Turning your Raspberry Pi (3 or Zero W) into a Bluetooth beacon

The idea behind a Bluetooth beacon is that things around you are allowed to interact with you in a certain way.  For example, they can give you the address of a website or provide information by using a special app that you have installed for that particular purpose.

In this article, I want to focus on the possibility of broadcasting the URL of a website, since this is a very easy and universal way to provide location based information to someone. My aim for using a Bluetooth beacon at my home was to broadcast the URL of the Weather Underground page of my weather station, using the Eddystone URL format by Google, so that others around can easily access these information with the help of their Android smartphones.

Although, Bluetooth beacons may not be very poplar in daily life up to now, the idea behind it is very fascinating and since it is very easy to create one with a Rasberry Pi (3 or Zero W), it is well worth doing.

There is already a very good description over here, of how to use a Raspberry Pi 3 as an Eddystone URL beacon.  All in all, there are just three easy steps necessary:

1. Enableing the Bluetooth device

2. Setting the Bluetooth device to “advertise and not-connectable”

3. Entering the Beacon Advertising Data

The third step includes encoding the URL which is the most difficult part, but luckily, there is already an Eddystone URL command calculator online available who does the encoding for you.

It is to mention that the lenght of the URL within the broadcast frame is limited, which means that, if you want to broadcast a longer URL, you have to use a service that shortens the URL for you. I am using https://goo.gl for that. Actually, I recommend to do that, even if the URL you want to broadcast fits into the Eddystone broadcast message, because you will be able to see the number of clicks within the statistics of the Google URL Shortener service, which is really nice. The commands for all three steps together are shown below (using some example URL).

sudo hciconfig hci0 up
sudo hciconfig hci0 leadv 3
sudo hcitool -i hci0 cmd 0x08 0x0008 17 02 01 06 03 03 aa fe 0f 16 aa fe 10 00 03 77 65 62 67 61 7a 65 72 08 00 00 00 00 00 00 00 00

This is already enough to turn your Raspberry Pi into a bluetooth beacon. After executing the commands, you should see a notification on your Android Smartphone, if Bluetooth is turned on. Normally, the notifications for Nearby are turned on by default. If you don’t see a notification, you should go to the Google settings and check the Nearby configuration.

Nearby

Even if your Bluetooth beacon is alredy working and broadcasting the URL correctely now, there is one more additional thing that you should do. The Eddystone format also transmits the TX power (the value between 10 and 03), so that a receiver can use that information to determine the distance to the beacon. For making that work correctely, you have to make a calibration, which simply means that you have to adjust the value for TX power within the Eddystone message. I have done that with the help of the APP Beacon Scanner. The rule for calibration is that you measure The TX power of the beacon at a distance of 1m (using Beacon Scanner), add 41 dBm and then use the result as the value for TX power. For me, that gave a good starting point for the calibration, but I had to play around a bit more with the value for TX power, so that the real distance to the beacon and the one shown by Beacon Scanner were a good match.

scanner

If you want to start the beacon automatically when you power up your Raspberry Pi, you can easily create a script with the three command lines and put it in the crontab with @reboot. But you have to take in account that Bluetooth may not available when the script is executed, so a delay (sleep command) at the beginning of the script  is necessary to make the beacon work. I use a delay of ten seconds for that, which works just fine.

With the help of your new Raspberry Pi Bluetooth beacon, you can now just tell your visitors to check the notifications of their Android Smartphone and to follow the link (bad luck for iPhone users 😉 ), if they are curious about the current weather condition details at your home location.