• So you're running the code from this example? https://www.espruino.com/Interfacing#node-js-javascript

    It seems that maybe it's trying to connect to the device twice, so you could try changing the code right at the top to:

    var foundDevice = false;
    noble.on('discover', function(dev) {
      if (foundDevice) return;
      console.log("Found device: ",dev.address);
      if (dev.address != ADDRESS) return;
      noble.stopScanning();
      foundDevice = true;
      connect(dev, function() {
        // Connected!
        write(COMMAND, function() {
          btDevice.disconnect();
        });
      });
    });
    

    Does the code make the Puck's light flash?

    How does one press a button on the device to trigger the HTTP request on the raspberry pi? Then after that poll the puck for the temperature?

    The best bet there is to use https://www.espruino.com/BLE+Advertising

    So on the Puck:

    var presses = 0;
    
    function updateAdvertising() {
    NRF.setAdvertising({},{manufacturer: 0x0590, manufacturerData:[presses,E.getTemperature()]});
    }
    
    setWatch(function() {                                                          
      presses++;                                                                   
      updateAdvertising();
    }, BTN, {edge:"rising", repeat:1, debounce:20});
    // update advertising with new temperature once a minute
    setInterval(updateAdvertising, 60000); 
    // update advertising right now
    updateAdvertising();
    

    And then use the code from https://www.espruino.com/BLE+Advertising#node-js - either JS or Python. The first byte you get will be the button press count - so when it changes you can do your HTTP request - and the second byte is the temperature, so there's no need to request it - you just always have it available.

About

Avatar for Gordon @Gordon started