HyLoPi is a FOSS bundle for the Raspberry Pi which creates a hyper-localized webserver using a Raspberry Pi device as the server. A hyper-localized webserver delivers content to users based on the user's location. In particular, when configured properly, a hyper-localized webserver allows itself to be accessed by only those in close physical proximity. For example, consider a listening party during which a musician may want to make certain content available - but only for those actually in attendance. The more generic example of this situation is allowing anybody in a venue to access content via a webserver. To this end, one of the main uses of hyper-localization is for the distribution of promotional material. This could, for example, be setup to notify customers at a store of an upcoming sale.
HyLoPi utilizes 2 checks to ensure that only authorized users, according to their location, are able to access the content. 1) Users connect to a fully customizable local WiFi network. 2) A content restriction system implementing an extra layer of location-based security, created with PHP and the HTML5 Geolocation API to access GPS data, is available for easy moderation of web content. Note that this also allows for increased precision - while connecting to the local WiFi network might be possible from a couple blocks away, the range of allowed locations can be tweaked to only allow visitors within that particular venue, for example.
We accomplish 1) with the use of any USB WiFi adapter with AP (access point) mode - if your Pi included the built in WiFi module that will work fine, and 2) a PHP content restriction system using the HTML5 Geolocation API. This can optionally use a GPS receiver module. The Raspberry Pi supports many USB GPS receivers such as this one: VK-162 USB GPS Dongle or if you feel like doing some hardware hacking, there is also Adafruit's Ultimate GPS Hat which works for just about any version of the Raspberry Pi.
The first step in setting up a hyper-localized webserver is to allow users to connect to a wifi network of your creation. This can be accomplished on the Raspberry Pi by using the nmcli tool. It is actually quite simple to setup a wifi network. The command below assumes you want to use wlan0 - if you wish to use a different wifi adapter, simply specify it below (you can list your network interfaces with ifconfig). Make sure to replace HotspotName and HotspotPassword.
sudo nmcli device wifi hotspot ssid HotspotName password HotspotPassword ifname wlan0
After creating the network, your wifi hotspot should automatically become active and you should see it when listing available wifi networks as shown below.
As explained above, the second way that we restrict content to hyper-local devices is through the use of GPS. There are many options for this on the Pi, such as an external USB device or a hardware hat. The hardware hats willl typically use /dev/ttyAMA0 while USB devices use /dev/ttyACM0. This guide will assume your GPS device can be accessed via /dev/ttyACM0, though the process should be otherwise the same.
After plugging in a GPS / GNSS receiver through the USB port, your GPS should be automatically configured. To verify that your GPS receiver has been successfully bound to /dev/ttyACM0, you can use the following command.
sudo cat /dev/ttyACM0
You should see at least 1 (but most likely several) NMEA sentence(s) that are of the form:sudo apt install gpsd gpsd-clients
Once installation completes, start gpsd with the following command.
gpsd /dev/ttyACM0 -n
You can then run the cgps client, which conveniently translates NMEA data to GPS coordinates.
cgps -s
which produces output like the following. Notice the latitude and longitude circled.
This section will describe how to create a web environment for restricting content by GPS-based location, using the HTML5 Geolocation API. For convenience, we will assume that you already have Apache (or some other httpd) w/ PHP installed and running. If you need help with this step, see my guide at RAMP-Pi.com. Note that for a user to connect to your webserver at all, they will HAVE to be already connected to your local wireless network. In this sense, the use of the HTML5 Geolocation API is a 2nd check to ensure that your content is only served to physically proximate users. By adjusting the allowed location radius, one can potentially even further restrict which users are able to access the content (e.g., while it might be possible to connect to your wireless network from 70m away, you might only want to serve users within a 30m radius).
Initial restriction will be via the client using the HTML Geolocation API. Note that your client *must* access your webserver in this method only, otherwise there could be a security risk. What we will essentially do is use javascript to force a redirect once we get the client's location. The client's location will then be sent to our webserver running on our Raspberry Pi, where we will check if the client's location is within allowed distance. This can all be 3 done by 3 files, as below, which will need to be modified for your own use. Use these as a guide only.
inc_hylopi.php
hylopi_access_control_example.php
client.js
Note that client.js will need to be integrated with an HTML page.