NRF.on('connect', function(addr) not called ?

Posted on
  • The following program logs "connect" and "disconnect" BLE events, while writing a dummy message in a loop.
    This is tested with a Bangle2 and an Android phone ("BLE Scanner" and also "nRF Connect").

    The "disconnect" event is properly detected, but not the "connect" one. However, the connection seems to be effective because "BLE Scanner" is able to read strings from the Bangle2.

    Also, when connected, the writing loop is not called. Why, please ?

    var counter = 0;
    
    // No display when connected. Pending lines are logged after disconnection.
    setInterval(
      function()
      {
        console.log("counter=", counter);
        counter++;
      },
      1000);
    
    // Just logs "-> Bluetooth". The custom message is not visible.
    NRF.on('connect', function(addr) {
      // Not called.
      console.log("Connection. addr=", addr); // Not displayed/
    });
    
    // Also logs "<- Bluetooth", as expected.
    NRF.on('disconnect', function(reason) {
      // This displays: "reason=19" which looks fine.
      console.log("reason=", reason);
    });
    
  • Can you try showing the message some other way? Maybe draw it to the LCD?

    It's entirely likely that the connection message ends up being ignored because the text is received before the 'console' has swapped over to bluetooth

  • Yes, many thanks, well done:

    This program displays a red square when Bluetooth connects, and a blue square on disconnection. This works as expected, good.

    NRF.on('connect', function(addr) {
      // Red square.
      g.setColor(255,0,0);
      g.fillRect(0,0,20,20);
    });
    
    NRF.on('disconnect', function(reason) {
      // Blue square.
      g.setColor(0,0,255);
      g.fillRect(20,0,40,20);
    });
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

NRF.on('connect', function(addr) not called ?

Posted by Avatar for rchateauneu @rchateauneu

Actions