• 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(myMessage));
      }).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?

About

Avatar for yngv126399 @yngv126399 started