iOS + Bluetooth Low Energy Tests, 2019
myFirstPeripheral advertises one custom GATT service with two characteristics. One readable characteristic returns the utf8 bytes for "*** Hello, would you like some coffee?" for every read.
- GATT service UUID:
0000cafe-0000-1000-8000-00805f9b34fb
(16bit version*:0xcafe
).- Readable characteristic. UUID:
0000c0fe-0000-1000-8000-00805f9b34fb
(16bit version*:0xc0fe
). - Readable characteristic. UUID:
0000c0ff-0000-1000-8000-00805f9b34fb
(16bit version*:0xc0ff
).
- Readable characteristic. UUID:
-
Launch the BLE peripheral app on the iOS device.
-
Run
sudo bluetoothctl
. Within bluetoothctl: -
type
list
to see Bluetooth controllers. If you want to use a different controller, typeselect<tab>
and select a different Bluetooth Low Energy controller. -
Type
paired-devices
, and use theremove
command to remove the iOS device / "Health Thermometer" if already paired. -
power on
-
agent on
-
default-agent
-
scan on
-
Wait for the iOS Device or "myFirstPeripheral" to show up in the scan. If it's not showing up, make sure the iOS device is unlocked and the BLE peripheral app is running in the foreground.
-
connect<tab>
and connect to the device. -
Accept the pairing request if there is one.
-
menu gatt
-
select-attribute 0000c0ff-0000-1000-8000-00805f9b34fb
-
read
-
read
-
read
Sample output
[bluetooth]# connect 43:06:32:87:63:44
Attempting to connect to 43:06:32:87:63:44
[CHG] Device 43:06:32:87:63:44 Connected: yes
Connection successful
...
[NEW] Primary Service
/org/bluez/hci0/dev_43_06_32_87_63_44/service003e
0000cafe-0000-1000-8000-00805f9b34fb
Unknown
[NEW] Characteristic
/org/bluez/hci0/dev_43_06_32_87_63_44/service003e/char003f
0000c0fe-0000-1000-8000-00805f9b34fb
Unknown
[NEW] Characteristic
/org/bluez/hci0/dev_43_06_32_87_63_44/service003e/char0041
0000c0ff-0000-1000-8000-00805f9b34fb
Unknown
[myFirstPeripheral]# menu gatt
[myFirstPeripheral:/service003e/char0041]# read
Attempting to read /org/bluez/hci0/dev_43_06_32_87_63_44/service003e/char0041
[CHG] Attribute /org/bluez/hci0/dev_43_06_32_87_63_44/service003e/char0041 Value:
52 65 61 64 20 72 65 71 75 65 73 74 20 23 31 Read request #1
52 65 61 64 20 72 65 71 75 65 73 74 20 23 31 Read request #1
[myFirstPeripheral:/service003e/char0041]# read
Attempting to read /org/bluez/hci0/dev_43_06_32_87_63_44/service003e/char0041
[CHG] Attribute /org/bluez/hci0/dev_43_06_32_87_63_44/service003e/char0041 Value:
52 65 61 64 20 72 65 71 75 65 73 74 20 23 32 Read request #2
52 65 61 64 20 72 65 71 75 65 73 74 20 23 32 Read request #2
[myFirstPeripheral:/service003e/char0041]# read
Attempting to read /org/bluez/hci0/dev_43_06_32_87_63_44/service003e/char0041
[CHG] Device 8C:8E:F2:AB:73:76 RSSI: -60
[CHG] Attribute /org/bluez/hci0/dev_43_06_32_87_63_44/service003e/char0041 Value:
52 65 61 64 20 72 65 71 75 65 73 74 20 23 33 Read request #3
52 65 61 64 20 72 65 71 75 65 73 74 20 23 33 Read request #3
*Note: To make my code a little simpler and easier to follow, I cheated and used 16bit UUIDs without registering them with the Bluetooth SIG. See https://stackoverflow.com/questions/10243769/what-range-of-bluetooth-uuids-can-be-used-for-vendor-defined-profiles. For a real app I would use a UUID generator and 128bit UUID strings in my code.