Automatically reconnecting a trusted BLE device

Viewed 560

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?

1 Answers

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.

Related