Detecting and Sending Bluetooth LE Beacon
Detecting beacon via hcitool
In order to scan BLE beacons, you need to first make sure the bluetooth is on. To turn on bluetooth service, you can do
sudo rfkill unblock bluetooth
Vice versa, you can turn off bluetooth by typing
sudo rfkill block bluetooth
Once the service is on, you can start to scan the beacon by running
sudo hcitool lescan --duplicate
Noted that the command only ask the system to start collecting beacons BUT it DOESN’T parse the beacons. Instead, it simply dumps the received messages to a message queue in OS and we need to call another program to retrieve those message, which is
sudo btmon -T
Sending beacon via hcitool
We need to set up raw bytes for a beacon when using hcitool
to transmit/advertise a BLE beacon. Here is an example from a tutorial
sudo hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 92 77 83 0A B2 EB 49 0F A1 DD 7F E3 8C 49 2E DE 00 00 00 00 C5 00
For more details, please check this tutorial: here
AWK
practice
Task:
- Print out RSSI only from a certain device using
awk
. - Advanced: only use one awk, not several awk thru pipelines.
- Advacned II: Print out
json
formatted address and RSSI using awk.
In case you are using VM that cannot capture BLE beacon, here is a sample file you can practice awk
.