• It should be as simple as mashing the two examples above together...

    Just modify the second example to:

    var currentTemp = 0;
    function getTemp() {
      NRF.findDevices(function(devices) {
        var found = false;
        for (var i in devices) {
          if (devices[i].name!="Puck.js e782") continue;
          var d = E.toString(devices[i].data);
          // index of 0x1809 in advertised data
          var idx = d.indexOf(String.fromCharCode(0x09,0x18));
          if (idx>=0) {
            currentTemp = d.charCodeAt(idx+2);
            found = true;
          }
        }
        if (found) {
          NRF.setAdvertising({
            0x1809 : [currentTemp]   // <----  code added here
          });
          digitalPulse(LED2,1,50); // green = good
        }  else
          digitalPulse(LED1,1,50); // red = bad
      }, 2000 /* receive for 2000ms */);
    }
    // look once a minute for temperature
    setInterval(getTemp, 60000);
    
About

Avatar for Gordon @Gordon started