how to implement beacon on raspberry pi?

790 Views Asked by At

If I want to implement the beacon and send message to Bluetooth devices, should I need

  1. a raspberry pi + beacon devices
  2. a raspberry pi

which one is right? I have found some people use raspberry pi and small beacon devices, others only use raspberry pi itself to send messages, both of them can send URL or data, and I want to know raspberry pi's character in this implementation.

thanks!!

1

There are 1 best solutions below

0
On

A Bluetooth BLE device can advertise its services and as part of the advertisement can contain up to 28 bytes of advertising data. There is no format for that data defined in the Bluetooth specification and so it is up to the manufacturer to define so that both ends of Bluetooth signal understand it. This is advertising data is how beacons have been created and companies have defined the structure used by them. Examples of this are the iBeacon and Eddystone formats.

This tweet gives a good summary of the structure of the data used by the popular/common formats: https://twitter.com/josryke/status/763006284052463617 enter image description here

On a Raspberry Pi the Bluetooth stack is BlueZ and it has API's that allow you to create the required advertisement from your favourite programming language: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/advertising-api.txt

There are also couple of command line tools that will allow you to create the beacons by hand.

Transcript of using bluetoothctl to create an Eddystone URL beacon:

(venv) pi@raspberrypi:~ $ bluetoothctl 
Agent registered
[bluetooth]# menu advertise 
[bluetooth]# uuids feaa
[bluetooth]# service 0xfeaa 0x10 0x00 0x00 0x62 0x6c 0x75 0x65 0x74 0x6f 0x6f 0x74 0x68 0x00
[bluetooth]# back
[bluetooth]# advertise on
[CHG] Controller B8:27:EB:22:57:E0 SupportedInstances: 0x04
[CHG] Controller B8:27:EB:22:57:E0 ActiveInstances: 0x01
Advertising object registered
UUID: (feaa)
UUID: Google(0xfeaa)
  10 00 00 62 6c 75 65 74 6f 6f 74 68 00           ...bluetooth.   
Tx Power: off
Name: off
Appearance: off
Discoverable: off
[bluetooth]# 

Or the same advertisement using the btmgmt tool:

pi@raspberrypi:~ $ sudo btmgmt add-adv -u feaa -d 1016aafe100001626c7565746f6f746800 -g 1

An example of iBeacon using the btmgmt tool:

sudo btmgmt add-adv -d 1AFF4C000215000102030405060708090A0B0C0D0E0F1234567800 -g 1