Update
It appears possible to pair and communicate with the module without using a pin, but so far only using gatttool
. I am still learning about BLE, and it is unclear to me whether this is a normal feature (e.g. a low-security default mode), or whether the modules I am using (JDY-08 / BT05 / HM-10 style BLE serial) might be non-compliant and simply not using the pin as set.
Via the default connection tool in Ubuntu Mate
I am running Ubuntu Mate on a Lenovo P50. I am exploring a BT05 BLE module, but I cannot connect to the device due to what I think might be a bug in Ubuntu. The steps I am taking to connect the device are:
- From the bluetooth menu, I select "Setup new device".
- I select the device from the list
- and then proceed, selecting "pair device"
- A screen saying "Pairing in progress..." appears.
- After some minutes, the message changes to "Failed to add device".
- At no point in time am I prompted to enter the 6-digit pin code needed for pairing.
The pin is customized and cannot be inferred by the operating system (short of forcing 10^6 possibilities), so I need to be able to enter it when connecting to the device. This issue might be related. The commands found here are a possible solution, but to this date there remains no method of communicating with bluetooth devices through the graphical user interface.
Via bluetoothctl
bluetoothctl
claims to connect (without using the custom pin). (this question is helpful for understanding what bluetoothctl
is doing). However, it does not seem possible to read/write characteristics once the device is paired?
φ bluetoothctl
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
[NEW] Device [address] [name]
[bluetooth]# scan off
[bluetooth]# pair [address]
Attempting to pair with [address]
[CHG] Device [address] Paired: yes
Pairing successful
[name]# info [address]
Device [address]
Name: [name]
Alias: [name]
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Generic Access Profile ([ID1])
UUID: Generic Attribute Profile ([ID2])
UUID: Device Information ([ID3])
UUID: Unknown ([ID4])
Modalias: bluetooth:[number]
[name]# list-attributes
[no attributes]
Based on, for example, this tutorial, I would expect Characteristics and Attributes to become available after pairing.
Via hcitool
and gatttool
I am able to connect to the modules and access the relevant properties using the commands hcitool
and gatttool
. This is also without a pin.
φ sudo hcitool -i hci0 lescan --duplicates | grep 'earlybird'
[ADDRESS] [NAME]
φ gatttool -i hci0 -b [ADDRESS] -I
[ADDRESS][LE]> connect
Attempting to connect to [ADDRESS]
Connection successful
[ADDRESS][LE]> primary
attr handle: 0x0001, end grp handle: 0x000b uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x000c, end grp handle: 0x000f uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x0010, end grp handle: 0x0022 uuid: 0000180a-0000-1000-8000-00805f9b34fb
attr handle: 0x0023, end grp handle: 0xffff uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
[ADDRESS][LE]> included
No included services found for this range
[ADDRESS][LE]> characteristics
handle: 0x0002, char properties: 0x02, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
...
handle: 0x0024, char properties: 0x1e, char value handle: 0x0025, uuid: 0000ffe1-0000-1000-8000-00805f9b34fb
gatttool
via the Python bindings. Connections were unstable, and I had to tweak how things behaved to avoid kernel panics. I ended up using a solution where both the BLE module and the computer polled at regular intervals, to try to synchronize their states. I also did some funny things to reboot the BLE chip and reset the connection from the computer periodically, since the pairing would be lost at random. But it in the end, it more or less worked. – MRule Sep 07 '19 at 19:31