Turn Your Raspberry Pi into a Bluetooth Beacon & Broadcast an URL

Published  July 10, 2019   0
Setup Raspberry Pi to Broadcast an URL using Eddystone BLE Beacon

Bluetooth is one of the revolutionary technology to wirelessly transfer the data, control other devices, build home automation systems etc. But have you ever wondered that the Bluetooth can also be used for broadcasting any information to nearby devices to display important information, advertisements, easy checkout etc. There is a protocol developed by the Google to perform the task of advertisement which can be easily deployed in Raspberry Pi to make it Bluetooth Beacon broadcaster.

 

In this tutorial we will get to know about BLE (Bluetooth Low Energy) and Bluetooth beacon and install the Eddystone Bluetooth Beacon in Raspberry Pi to broadcast a URL. Its very easy to convert Raspberry Pi into a Bluetooth Beacon as it has inbuilt Bluetooth.

 

What is BLE and Bluetooth Beacon?

The Bluetooth Low Energy, as the name indicates consumes less power than classic Bluetooth. It is achieved by sending data when needed with pre-defined periodic updates. But unlike classic Bluetooth it is not used to transfer Files or Music. A BLE device works with Bluetooth V4.0 and can operate with low power as a server or as a client which makes BLE an ideal choice for beacons, smart watches, fitness bands etc. Classic Bluetooth on the other hand is just the simple plain old Bluetooth protocol that we use to transfer files and other data. Almost all BLE devices have Classic Bluetooth functionality associated with it. We previously explained BLE in detail with ESP32.

Bluetooth

 

Bluetooth Beacons:

Beacons are the hardware devices which broadcast some messages to nearby electronics devices and behave as a Broadcaster. This technology enables the portable devices to perform some actions when they are in close proximity to beacon device. Now, beacons can be implemented using BLE and classic Bluetooth. Since, most smartphones and other electronic devices are compatible with BLE and can be used as Beacon receiver so implementing BLE beacon is more efficient as compare to classic Bluetooth beacon to reduce power consumption.

On an average, a Bluetooth Low Energy beacon can transmit BLE signals to 80 meters.

 

How does BLE Technology works and used with Beacons?

BLE is low power consumption technology which is designed for short-range communication and it is preferred where battery life is more important factor than high data rate. The data transfer in this communication is one-way only. BLE beacon transmits small data packets at regular intervals of time. These data packets are received and decoded by beacon scanner app installed in smartphones. This received data triggers actions like promoting a product or pushing a message.

In Bluetooth beacon an ID number is transmitted 10 times every second by the it via BLE channels. Then this ID number is received by the Bluetooth enabled device and recognized by the beacon scanner app, it links it to an action, such as download an app or piece of content stored on the cloud, and displays it on the smartphone.

 

What is Eddystone Beacon?

Eddystone is a protocol which is developed by Google that allows to broadcast one way messages to BLE devices. The Eddystone-URL frame forms the backbone of the Physical Web, which helps in discovery of web content in the surrounding. Beacon can broadcast four types of data using Eddystone protocol. They are as follows:

  1. Eddystone-URL for broadcasting URL addresses
  2. Eddystone-UID for broadcasting beacons IDs
  3. Eddystone-TLM for broadcasting beacon telemetry like device temperature, battery strength, etc.
  4. Eddystone-EID for security.

There are also other types of beacons like iBeacon which is for iOS supported devices, but Eddystone is only for Android devices. Also note that Google has discontinued Nearby Notifications, now user will have to install specialized beacon scanner app that will show the broadcasted content.

In this tutorial, we will use Raspberry Pi as Eddystone Beacon and focus on broadcasting URL address using Eddystone URL so that anybody can easily access the broadcasted information with the help of their Android devices.

 

Requirements

Here only Raspberry Pi is needed to build this Bluetooth Beacon. It should be Raspberry Pi 2 or newer with Raspbian Jessie or a newer OD installed in it.

Here, we will use SSH to access Raspberry Pi on the laptop. You can use VNC or Remote Desktop connection on the laptop, or can connect your Raspberry pi with a monitor. Learn more about setting up Raspberry Pi headlessly here without a monitor. 

 

Setup Raspberry Pi for Eddystone Beacon

It is very easy to setup the Eddystone broadcaster on Raspberry Pi. It involves only 3 commands.

This can be done by configuring the HCI (Host controller Interface) which can be access using hciconfig commad. To check what can be done using this command, enter the below command in terminal.

hciconfig -h

 

1. First, we have to Enable the Bluetooth device on our Raspberry Pi using below command.

sudo hciconfig hci0 up

 

2. Now, we have to Set the Bluetooth to “advertise and not-connectable” device using below command.

sudo hciconfig hci0 leadv 3

 

3. Above commands make the device to run broadcasting service, now just enter beacon data in next command which contains different frames information and URL in hexadecimal format. Run the below command to start beacon broadcasting.

sudo hcitool -i hci0 cmd 0x08 0x0008 1c 02 01 06 03 03 aa fe 14 16 aa fe 10 00 02 63 69 72 63 75 69 74 64 69 67 65 73 74 07 00 00 00

 

This command will broadcast the URL http://circuitdigest.com.

To check the broadcasted message on your smart phone, download the Physical Web App or Beacon scanner on your Android smartphone and start the scanning. You will see the broadcasted link in the app as shown below. Click on the link to visit and open the website in browser.

Setup Raspberry Pi for Eddystone Beacon

 

Now lets understand the hexadecimal coding of the message. In below table we have given explanation of each and every value present in the code:

Value

Description

0x08

#OGF = Operation Group Field = Bluetooth Command Group = 0x08

0x0008

#OCF = Operation Command Field = HCI_LE_Set_Advertising_Data = 0x0008

1c

Length. The hexadecimal 1c converts to 23 decimal which is the number of bytes that follow.

02

Length

01

Flags data type value

06

Flags data

03

Length

03

Complete list of 16-bit Service UUIDs data type value

aa

16-bit Eddystone UUID

fe

16-bit Eddystone UUID

14

Length. The hexadecimal 14 converts to 15 decimal which is the number of bytes that follow

16

Service Data data type value

aa

16-bit Eddystone UUID

fe

16-bit Eddystone UUID

10

Frame Type = URL

00

TX Power (this should be calibrated)

02

URL Scheme (http:// = 0x02)

63

‘c’ in hexadecimal

69

‘i’ in hexadecimal

72

‘r’ in hexadecimal

63

‘c’ in hexadecimal

75

‘u’ in hexadecimal

69

‘i’ in hexadecimal

74

‘t’ in hexadecimal

64

‘d’ in hexadecimal

69

‘i’ in hexadecimal

67

 ‘g’ in hexadecimal

65

 ‘e’ in hexadecimal

73

 ‘s’ in hexadecimal

74

 ‘t’ in hexadecimal

07

 .com (.com = 0x07)

00

 

00

 

00

 

 

To broadcast any custom URL using Raspberry Pi Bluetooth Beacon, just convert the URL characters into hexadecimal using any online tool and put it in the above command. Maximum characters that can be transmitted are 16, if the URL is too long then shorten it using any URL shortners services like bitly.com and then fit the data in above table.

It is very cumbersome and time consuming to convert each character into Hexadecimal equivalent. So to do your job easy there is an Eddystone URL command calculator where you just need to enter URL which you want to be broadcasted and you will get your command ready like this.

Eddystone URL Command Calculator

 

Bluetooth beacon is now broadcasting the URL and working fine but there is one more thing to be calibrated that is Tx power which is one of the value in above command to get the accurate distance from the Bluetooth beacon. 

 

Optimize the Transmitting Signal Power by Calibrating Tx Power

In Eddystone frame there are few components which are transmitted and Tx power is one of them which tells the strength of the signal. By decoding the strength of the signal, receiver finds the distance from the Beacon broadcaster. The value of Tx power can be ranges from -12 to 10. We have to find the value by hit and trial method to get the accurate distance. For this, adjust the value of Tx power in the Eddystone message command and put your smartphone at a distance of 1 m with Beacon scanner app opened. Now start putting the values of Tx power in the command from 0 to negative values. Remember to convert the decimal values in hexa decimal format, for this use the online value converter tools for easy decoding and take the last two digits of the converted value. In my case the hexa value is f4. Check the distance in the scanner app, adjust the values until it shows approx 1m and after that you are to use Eddystone URL broadcaster with accurate distance.

 

Applications of Eddystone Bluetooth Beacon

Here are some of the use cases for BLE beacon:  

  1. BLE enabled retailing: This technology can be used to attract customers in the vicinity of the stores by advertising the exciting offers and sales.
  2. BLE beacon enabled events:  It can be used to easy registrations at the events and in stadiums with easy payment checkouts.
  3. BLE beacons in Real Estate: You can get the all the details of properties available near you and can book in one touch.

There are many other applications you can think of and implement according to the requirements.

So this how the Raspberry Pi can be used to broadcast any message or URL by converting it into a Bluetooth Beacon using Eddystone. Check the demonstration Video below.

Video

Have any question realated to this Article?

Ask Our Community Members