You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Thanks - I get what you mean. I just tried this and I get the same issues.

    It looks like a bug in Espruino to me. The act of connecting does require scanning, and it looks like the Bluetooth stack just shuts down scanning afterwards rather than leaving it going.

    I'll file an issue for it, but all I can suggest for now is to cancel scanning and the restart it when you're done connecting:

    NRF.setScan(function scanFn(d) {
        if (d.id === "xxxx") { 
              //do some stuff here
              NRF.setScan();
              setState([0xCC, 0x24, 0x33], function() { NRF.setScan(scanFn); }); }
    }
    
    function setState(arg, callback) {
        var gatt;  
        NRF.connect(addr).then(function(g) {
          gatt = g;
          return gatt.getPrimaryService("0000ffe5-0000-10­00-8000-00805f9b34fb");
        }).then(function(service) {
          return service.getCharacteristic("0000ffe9-0000­-1000-8000-00805f9b34fb");
        }).then(function(c) {
          characteristic = c;
          return characteristic.writeValue(arg);
        }).then(function() {
          gatt.disconnect();
          callback();
        }); // probably also want a .catch in here to catch errors and also call 'callback()'
      }
    
About

Avatar for Gordon @Gordon started