You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Just tried with 1v92 and looks ok to me - just gives me Uncaught Error: Unhandled promise rejection: No Services found or Uncaught Error: Unhandled promise rejection: undefined at line 7 col 29

    The undefined rejection is a bit weird, but I've done it a bunch of times now and I don't get a disconnect.

    The error is because I have a bunch of Bluetooth LE devices here and your code is trying to connect to the first one that's found, which is probably never the correct one.

    I changed your code to the following so that it works the same but searches for the correct device, re-uploaded, and the red LED comes on on the Nordic_Blinky device as expected.

    var devices;
    NRF.findDevices(function(devices) {
      var idx = -1;
      for (var i=0;i<devices.length;i++) {
        if (devices[i].name == "Nordic_Blinky")
          idx = i;
      }
      if (idx < 0) throw new Error("Nothing found!");
      devices[idx].gatt.connect().then(function(g) {
        gatt = g;
        return gatt.getPrimaryService("00001523-1212-EFDE-1523-785FEABCD123");
      }).then(function(service) {
        return service.getCharacteristic("00001525-1212-EFDE-1523-785FEABCD123");
      }).then(function(characteristic) {
        characteristic.writeValue( [0xff] );
      }).then(function() {
        gatt.disconnect();
        console.log("Done!");
      });
    }, 4000);
    

    Are you really using all those other pins though? Is it actually a Puck.js with a whole bunch of wires attached, or some other device?

    So yeah, it works fine for me as long as it's connecting to the correct device. If you want to connect by name look at NRF.requestDevice where you can just specify a name rather than manually searching: http://www.espruino.com/Reference#l_NRF_requestDevice

About

Avatar for Gordon @Gordon started