• So it's literally just with this code:

    function setLight(isOn) {
      var gatt;
      NRF.connect("98:7b:f3:61:1c:22").then(fu­nction(g) {
        //         ^^^^^^^^^^^^^^^^^  your light's address here
        gatt = g;
        return gatt.getPrimaryService("33160fb9-5b27-4e­70-b0f8-ff411e3ae078");
      }).then(function(service) {
        return service.getCharacteristic("217887f8-0af2­-4002-9c05-24c9ecf71600");
      }).then(function(characteristic) {
        characteristic.writeValue(isOn ? 1 : 0);
      }).then(function() {
        gatt.disconnect();
        console.log("Done!");
      });
    }
    
    var on = false;
    setWatch(function() {
      on = !on;
      setLight(on);
    }, BTN, { repeat:true, edge:"rising", debounce:50 });
    

    that you're having problems? Is it anything particular that you do that causes the error?

    To catch a promise rejection, just do:

    ....then(function() {
      // .....
    }).catch(function(error) {
       // here
    });
    

    you can't catch them with a try...catch block because the function will have already finished executing by the time the error occurs.

    The majority of errors will probably be because you're pressing the button quickly enough that the Puck won't have finished the last connection before the latest request to connect comes in?

About

Avatar for Gordon @Gordon started