NRF Disconnect reason help

Posted on
  • Hey i'm trying to to do different things depending on what reason the ble disconnect says. Hard to view this live and debug.

    Got a MDBT42Q module hooked up the bangle. I wish to differentiate the gatt.device.disconnect() (user terminated disconnection) event and the event when range is reason to disconnect. Is this possible ? and what events might those be ? and how do i check them.

    Currently i do this with no luck, it seems that the same event is fired for both types of disconnection.

      NRF.on('disconnect', function (reason) {
        connected = false;

    Standard buzz never happends.

  • What you're doing there looks ok, but BLE_HCI_REMOTE_USER_TERMINATED_CONNECTIO­N isn't defined, so you'd have to define it as a number somewhere.

    To make debugging this easier, I'd suggest adding a USB-TTL converter if you have one handy:­onsole (and then do Serial1.setConsole(1) for force the console on serial even when Bluetooth is connected).

    You can then interact with the REPL at the same time as trying out Bluetooth stuff, which should help no end!

  • Thanks, that's great ! What do you mean by defining it as a number ? the reason has to not match that specific number right.
    Isn't that constant already defined ?
    define BLE_HCI_REMOTE_USER_TERMINATED_CONNECTIO­N 0x13 /**< Remote User Terminated Connection. */
    Do you mean that i should define it as 0x13 ?

  • I'm afraid those constants aren't defined in JS - they just come from the Nordic Softdevice.

    Doing var BLE_HCI_REMOTE_USER_TERMINATED_CONNECTIO­N = 0x13 as you suggest would really help I reckon.

    Of course I guess you could also do:

    var reasons = [];
     NRF.on('disconnect', function (reason) {

    And then check out what was in reasons when you reconnect?

  • Alright, then i misunderstood. Ah yeah that's great, thanks Gordon.

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

NRF Disconnect reason help

Posted by Avatar for Gustav @Gustav