You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • This seems to work for me:

    function scanFunc(dev) {
      if (!dev.name || dev.name.substr(0,4)!="Puck") return; 
     // you probably want to check ID, not name
      print(dev.manufacturerData[0]);
      // do something when this changes
    }
    NRF.setScan(scanFunc)
    

    You could increase the advertising interval for setAdvertising which would help a lot:

    NRF.setAdvertising({},{interval:50, ...
    // you'd have to experiment with values. Due to the way BLE advertising works it'll probably only pick up every third advertisement
    

    In terms of fast connection, try something like this:

    var lightAddr = "98:7b:f3:61:1c:22";
    var characteristic;
    
    function setLight(isOn) {
      var gatt;
    // if we have the characteristic, connect, write, disconnect
      if (characteristic) {
        return NRF.connect(lightAddr).then(function(g) {
          gatt = g;
          return characteristic.writeValue(isOn ? 1 : 0);
        }).then(function() {
          gatt.disconnect();
          console.log("Done!");
        });
      }
      // otherwise we have to search for it first
      NRF.connect(lightAddr).then(function(g) {
        gatt = g;
        return gatt.getPrimaryService("33160fb9-5b27-4e­70-b0f8-ff411e3ae078");
      }).then(function(service) {
        return service.getCharacteristic("217887f8-0af2­-4002-9c05-24c9ecf71600");
      }).then(function(c) {
        characteristic = c;
        return characteristic.writeValue(isOn ? 1 : 0);
      }).then(function() {
        gatt.disconnect();
        console.log("Done!");
      });
    }
    
About

Avatar for Gordon @Gordon started