Work as Beacon
by hci
- open hardware
sudo hciconfig hci0 up
- change its operating mode to “Low Energy Advertising“
sudo hciconfig hci0 leadv 3
- set the Pi’s Bluetooth to broadcast the iBeacon payload data.
sudo hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 06 1A FF 4C 00 02 15 C7 C1 A1 BF BB 00 4C AD 87 04 9F 2D 29 17 DE D2 00 00 00 00 C8 00
id | Byte Value | Description |
---|---|---|
0x08 | Defines the OGF as the Bluetooth Command Group 0x08 | |
0x0008 | Defines the OCF so that we set the bluetooth advertising data | |
1F | Defines the data length of our entire payload | |
02 | Data length of the next section, 2 bytes | |
01 | Data Type, defines that this section is flag data | |
06 | Defines the flag needed for Low Energy Advertising mode | |
1A | Data length of the final section of the payload, 26 bytes | |
FF | Data Type, defines that this section is manufacturer specific data | |
4C | Defines the manufacturer ID, in this case apple (0x4c00) | |
00 | Second part of the manufacturer ID | |
02 | Defines the sub type, which in our case is an iBeacon | |
16 | Defines that the following data is “service data” for eddystone | |
15 | Data length of the subtype payload, which should be 21 bytes | |
C7 | Proximity UUID, 1st Byte | |
C1 | Proximity UUID, 2nd Byte | |
A1 | Proximity UUID, 3rd Byte | |
BF | Proximity UUID, 4th Byte | |
BB | Proximity UUID, 5th Byte | |
00 | Proximity UUID, 6th Byte | |
4C | Proximity UUID, 7th Byte | |
AD | Proximity UUID, 8th Byte | |
87 | Proximity UUID, 9th Byte | |
04 | Proximity UUID, 10th Byte | |
9F | Proximity UUID, 11th Byte | |
2D | Proximity UUID, 12th Byte | |
29 | Proximity UUID, 13th Byte | |
17 | Proximity UUID, 14th Byte | |
DE | Proximity UUID, 15th Byte | |
D2 | Proximity UUID, 16th Byte | |
00 | Major 1st byte – Distinguishes devices using same UUID | |
00 | Major 2nd byte – Distinguishes devices using same UUID | |
00 | Minor 1st byte – Distinguishes devices using same UUID | |
00 | Major 2nd byte – Distinguishes devices using same UUID | |
C8 | Signal Power – Used to optimize distance calculations. |
by BlueZ
- Enable Experimental Flag for BlueZ
sudo nano /lib/systemd/system/bluetooth.service
Find a line starting with “ExecStart” and add “–experimental” at the end of the line
ExecStart=/usr/libexec/bluetooth/bluetoothd --experimental
- Download Example Code
wget www.kernel.org/pub/linux/bluetooth/bluez-5.43.tar.xz
tar xvf bluez-5.43.tar.xz
ls -l bluez-5.43/test/example-advertisement
Method 1
sudo bluetoothctl
help
Method 2
hciconfig
//list devices
hcitool scan
//scan