• Hey all, I'm a little lost here. My Bangle is running a watchface that is listening on a specific UUID for short strings to act as notifications (not BLE notifications, just messages). The Bangle code works fine, and I can access it from both a Web Bluetooth page and a DroidScript app. However, I can't get my puck to send the message properly. Here is the Bangle (peripheral) code snippet:

    var BLEMessage = "";
    NRF.setServices({
      "feb10001-f00d-ea75-7192-abbadabadebb": {
        "feb10002-f00d-ea75-7192-abbadabadebb": {
          value : [0],
          maxLen : 20,
          writable : true,
          onWrite : function(evt) {
            let str = stringFromArray(evt.data);
            if(str === "__EOM__") {
              if(BLEMessage) {
                showMsg('Message',BLEMessage);
              } else {
                reload();
                scheduleAlarms();
                showMsg('', 'Reloading...');
              }
              BLEMessage = '';
            } else {
              BLEMessage += str;
            }
          }
        }
      }
    }, { });
    

    The showMsg() function is defined and works fine (just draws a dialog box and writes the string to screen).

    Here is the Puck code (mostly thanks to Gordon's BLE example):

    const primaryServiceUuid = 'feb10001-f00d-ea75-7192-abbadabadebb';
    const sendCharUuid = 'feb10002-f00d-ea75-7192-abbadabadebb';
    
    let device, sendCharacteristic;
    
    
    const split20 = (msg) => {
      let chunks = [];
      while(msg.length > 20) {
        chunks.push(msg.substr(0, 20));
        msg = msg.substr(20);
      }
      if(msg.length) chunks.push(msg);
      return chunks;
    };
    
    var msgToSend = "FOO!";
    var logMsg = '';
    
    function logD() {
      require("Storage").write('logMsg.txt', logMsg);
    }
    
    function sendMsg() {
      var gatt;
       NRF.requestDevice({  filters: [{ namePrefix: 'Bangle' }]  })
      .then(function(device) {
        logMsg += "Found\n";
        digitalPulse(LED2,1,10);
        return device.gatt.connect();
      }).then(function(g) {
        logMsg += "Connected\n";
        digitalPulse(LED3,1,10);
        gatt = g;
        return g.getPrimaryService(primaryServiceUuid);­
      }).then(function(service) {
        logMsg += "got PS\n";
        return service.getCharacteristic(sendCharUuid);­
      }).then(function(characteristic) {
        logMsg += "Got char\n";
        sendCharacteristic = characteristic;
        return sendCharacteristic.writeValue(toArrBuf(m­yMessage));
      }).then(function() {
        logMsg += "Sending: " + JSON.stringify(toArrBuf(myMessage));
        return sendCharacteristic.writeValue( toArrBuf('__EOM__'));
      }).then(function() {
        digitalPulse(LED2,1,[10,200,10,200,10]);­
        gatt.disconnect();
        logMsg += "Done!\n";
        logD();
        busy=false;
      }).catch(function(e) {
        digitalPulse(LED1,1,10);
        logMsg += e.toString()+"\n";
        busy=false;
        logD();
      });
    }
    
    
    setWatch(sendMsg, BTN, {edge:"rising", debounce:50, repeat:true});
    

    Which works fine in an HTML page using "let NRF = navigator.bluetooth;"
    I'm writing my log to a file since console is disabled when I run this, and the file reads:

    Found
    Connected
    BLE error 0x11 (BUSY)
    
    

    As i said, I know the Bangle code works, been using it for weeks. The Puck code runs in a browser just fine. Which device is "BUSY"?? Any help appreciated!

  • Which device is "BUSY"??

    I guess it is bluetoooth stack on Puck that is BUSY - the return g.getPrimaryService(primaryServiceUuid);­ fail for some reason. Could it be that this code is running multiple times or there is something else BLE related running on Puck at the same time?

  • Hi! I'm pretty sure you've his exactly this issue that was reported a few days ago: http://forum.espruino.com/conversations/­363920/#comment15998892

    I have no idea why this has happened yet but I will look into it very soon. For the moment you can almost certainly fix it by changing:

        return device.gatt.connect();
      }).then(function(g) {
        logMsg += "Connected\n";
        digitalPulse(LED3,1,10);
        gatt = g;
        return g.getPrimaryService(primaryServiceUuid);­
      }).then(function(service) {
    

    to:

        return device.gatt.connect();
      }).then(function(g) {
        logMsg += "Connected\n";
        digitalPulse(LED3,1,10);
        gatt = g;
        return new Promise(r => setTimeout(r,500)); //< ---------- added this delay
      }).then(function() {
        return gatt.getPrimaryService(primaryServiceUui­d);
      }).then(function(service) {
    ...
    
  • Thank you @Gordon!! That was it! And thanks for forwarding the other issue, I did a search on the forums for BLE Error 11 and I get no hits (not even this post).

    And @fanoush... thank you too! You have inspired me to order both an F07 and a DK08 to flash into Espruinos. I'm trying to work up the courage to make a build for PineTime. It's been a LONG time since i've worked at device level (hence my preference for JS on MCUs) but you've done considerable heavy lifting already. I've learned a lot from you both!

  • Just to add I tried to reproduce this with recent firmware, but can't. I wonder whether there's something about the Bangle.js's configuration that's non-standard (like having bonding enabled somehow?).

  • Ok, I figured it out (I think). This is due to negotiation of a higher MTU since this was added in Espruino 2v09.

    I think if you're connecting to a device with an older firmware you can connect just fine. It's when you connect between two devices with 2v09+ firmware that you have the issue. Follow this on the GitHub issue.

  • I did a search on the forums for BLE Error 11 and I get no hits (not even this post).

    you need to turn off Title matched search terms filter which is preselected

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

Getting a BLE error trying to get Puck to talk to Bangle

Posted by Avatar for yngv126399 @yngv126399

Actions