Forum Xamarin.Forms

BLE device disconnect and auto re-bonding known devices

I have been going around in circles for the last few days on BLE device connectivity, I have been following the examples and structure for using BLE within Xamarin (using the command structure below). The question is how to manage re-bonding devices automatically to a mobile app and the best way to structure the code and functionality. I have the following questions on a suitable strategy

  1. When a phone is bonded to our mobile app, should we keep checking it's present and bonded via a period timer pinging the device for data or check the connected device inside the BLE adapter (Device is present)
  2. Once a device is switched off, goes out of range etc we should detect it's not present via the above periodic timer method (Device is not-present and open up discover mode)
  3. Setup a regular timer to check to see if the device can be re-bonded and can be re-connected (Device is present and re-connect)

Is it possible to setup a state change on a device present/not-present, to help auto-connect pre-bond devices?

Or should BLE do it all in the background and just missing something on the setup process

BT Device bonding process

[IBluetoothLE].StateChanged => To know the Bluetooth status, like its off/on (Check BT is switch on)
[IAdapter].DeviceDiscovered => This will trigger when any device is discovered (Search for suitable device)
[IAdapter].ConnectToDeviceAsync => For connecting with a device (Bond to a device)

BT Data transfer Tx/Rx while device is connected

BT Device is disconnected

How to auto-rebond the device back to the mobile app?
1) Period timer to scan for known devices and re-connect?
2) State change on the device?
3) A method to trigger a re-connection?

Sign In or Register to comment.