Check for active BLE connection

Posted on
  • Hi everybody,

    I'm wondering if there is a callback of some sort if/when the espruino device loses connection to a BLE sensor, when subscribed to it's notifications?

    Otherwise I would reset a timer upon reception of every notification, and check say every 15 seconds if the timer was reset (meaning notifications were still received), and disconnect if not.

    What do you think?

    Thanks, Joost

  • connection.on('close', function() { ... }); doesn't do the trick?

  • I think you might want gattserverdisconnected : https://www.espruino.com/Reference#l_BluetoothDevice_gattserverdisconnected

    It's an odd name, but for some reason it's what they chose for the Web Bluetooth spec.

  • Thank you both,

    this works great it seems:

    gatt.device.on('gattserverdisconnected', function(reason) {console.log("gattserverdisconnected, Grund: "+ reason+" Zeit: " + (getTime() -t) + " sec"); disconnect(reason);} ); 
    

    with variable t being set earlier upon successful connect.

    with reason 8 triggered when the BLE server (my sensor) goes out of reach (loss of reception) and reason (int) 19 gets triggered when the sensor shuts down due to inactivity.

    Thanks again,

    Joost

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Check for active BLE connection

Posted by Avatar for Joost @Joost

Actions