• Some updates on the tests I have been doing during the week.

    In my attempt to analyze the Command Identifier byte which is different between the two Parameter Update messages, I simplified the app I am using on BangleJS.
    This is its code:

    const kb = require("ble_hid_keyboard");
    
    // Force Bluetooth to use the fastest poll interval available
    NRF.setConnectionInterval(7.5);
    // Enable BLE HID providing an HID report.
    NRF.setServices(undefined, { hid : kb.report });
    
    function drawApp() {
      g.clear();
      g.setFont("6x8",2);
      g.setFontAlign(0,0);
      g.drawString("HID test", 120, 120);
    }
    
    function logPrint(message) {
      const now = new Date();
      Terminal.println(now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + " - " + message);
    }
    
    NRF.on('connect', function(addr) { logPrint("Connected to " + addr); });
    NRF.on('disconnect', function(reason) { logPrint("Disconnected: " + reason); });
    
    // Start!
    drawApp();
    

    The app configures the minimum connection interval and sets the HID report, using the one provided by ble_hid_keyboard module. Then it does nothing else other than printing to terminal every connection and disconnection event. I also simplified the actions I do to reproduce the problem: now I always leave the BangleJS near my PC and control connections and disconnections to the device using the Blueman interface.

    Using this app I am still able to sniff the Bluetooth traffic with Wireshark and see the two Parameter Update messages sent by BangleJS, but I also noticed some other interesting details:

    1. The second Parameter Update message is not always sent by the device after a connection, but when it is present its timestamp is always 41 seconds after the first captured packet (i.e. the command triggered by my click on "Connect to device" on PC).
    2. The second Parameter Update message is not generated when the connection to BangleJS includes the device pairing procedure.
    3. After the connection is established, a momentary disconnection often (about 50% of my tests) occurs before 41 seconds have passed. The app prints on the BangleJS Terminal: Disconnected: 8, which should be the error code for Connection Timeout. After the reconnection has been completed no further traffic is reported by Wireshark, so no second Parameter Update message is present even in this case.

    The low power stuff is handled by the DYNAMIC_INTERVAL_ADJUSTMENT ifdefs, and it should get reset with the code here on disconnect https://github.com/espruino/Espruino/blo­b/master/targets/nrf5x/bluetooth.c#L1148­

    But... maybe something about the way it disconnects when out of range causes that code not to work?

    I, too, think than could be the root cause of the problem... The cases I described in this post tend to happen "alternately", for example: if in a Wireshark capture I see a spontaneous disconnection (case 3), I can almost be sure that in the next capture I will see two Parameter Update messages (case 1). It is as if something from the previous connection does not get correctly reset and keeps affecting the next connection.

About

Avatar for Franzo @Franzo started