4

I am trying to automatically reconnect to a BLE device, a Taidoc Thermometer in this case. I have scanned for the device, then issued a 'pair' command which succeeds and then a 'trust' command which also succeeds.

If I do 'info' on the device it is reported as paired and trusted:

Name: TAIDOC TD1241
Alias: TAIDOC TD1241
Appearance: 0x0300
Paired: yes
Trusted: yes
Blocked: no
Connected: no
LegacyPairing: no
UUID: Vendor specific           (00001523-1212-efde-1523-785feabcd123)
UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Health Thermometer        (00001809-0000-1000-8000-00805f9b34fb)
UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Battery Service           (0000180f-0000-1000-8000-00805f9b34fb)

However, it never automatically reconnects to the device when the device starts advertising. I also tried manually starting a scan but that also doesn't make a difference.

My understanding was that 'trusting' it would make the device reconnect automatically? The Bluez documentation doesn't really say much about what 'trust' does...

Any tips on how to make automatically reconnecting using 'trust' work?

  • I have also deep problems with BlueZ and automatically reconnecting to devices. There should be an "auto connect" feature on BlueZ somehow but it's of bad documented and never got it working. I think you should post the use case and question to the BlueZ mailing list. – Emil Jun 09 '20 at 18:56
  • I am writing a 'wrapper' library now for Bluez and have implemented an 'autoConnect' function but it basically just continuously scans until the device is found. Not a very effective nor elegant way....but I guess it is the only way for now. See my work in progress here: https://github.com/weliem/blessed-bluez ...I might try the Bluez mailinglist indeed... – Martijn van Welie Jun 10 '20 at 20:24

1 Answers1

2

Trusting a device does not mean automatically reconnecting to it when it is available. Trusting a device means you are bonding with it (i.e. pairing with the device and saving the bonding keys in your bonding database). When you bond to a device, there are a few benefits including:-

  • The connection can become encrypted.
  • Your device would be able to see the actual address of the remote device (if the other device is using LE Privacy where its Bluetooth address is continuously changing).

You can find more information about pairing/bonding below:-

So to answer your original question, if you want your device to automatically pair to the thermometer, you have to write a script/daemon on your BlueZ machine to continuously scan & connect to the device if found. You can even have that daemon as part of your startup scripts so that it is launched as soon as your Linux machine boots up. You can do the scanning/connection every few minutes so that you don't needlessly waste battery and processing power.

I hope this helps.

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72
  • Thanks for your answer. However, in my understanding the 'pair' command already does the bonding. I have been using that with quite some devices. So I am puzzled about what the 'trust' command then does... – Martijn van Welie Jun 09 '20 at 15:08
  • I just ran another test with a Nonin 3230 which is a pulse oximeter that requires bonding. When I connect for the first time it pairs and asks for confirmation since it uses JustWorks pairing. The second time, it just connects fine because the bonding keys have been saved, no confirmation asked. However, if I do 'info' on the device, it shows 'Trusted: no". My conclusion is that trusting is not needed for bonding BLE devices. Issuing a 'pair' command is enough and the keys are definitely stored by Bluez. So I still don't have a clue what 'trust' is for... – Martijn van Welie Jun 10 '20 at 20:17
  • You are right, I had a search through the BlueZ source code and it looks like bonding and trusting are different. However trusting still doesn't seem to mean that you can automatically connect to your device. I'll do more reading and delete or modify my answer accordingly. – Youssif Saeed Jun 15 '20 at 06:22
  • Ok good! I understand 'trust' may not be for 'reconnecting'.....but now I am even more puzzled what it is for! – Martijn van Welie Jun 16 '20 at 07:11