reynish
4/10/2017 - 12:04 PM

Hat tip to [http://harald.studiokubota.com/](http://harald.studiokubota.com/wordpress/index.php/2017/03/20/puck-js-and-bluetooth-le/)

// Have a service to show temperature and battery level
// This is only visible when you are connecting to the Puck

var currentTemperature=E.getTemperature().toFixed(2)*100;

console.log("Temp: "+currentTemperature);

NRF.setServices({
 "12411007-877b-4b6e-1d8a036a956a" : { // Health Thermometer
  "7e3defd9-1426-068f-d744-fa70603d83ac": { // Temperature
   readable: true,
   notify: true,
   value : [ currentTemperature % 256, currentTemperature / 256 ]
  }
 },
 0x180f : { // Battery Level
  0x2a19 : { // Percentage
   readable : true,
   notify: true,
   value: [ Puck.getBatteryPercentage() ],
  }
 }
});

// Updating the temperature
setWatch(function() {
 currentTemperature += 1; // For debugging: increase temp by 0.01 degree per update
 console.log(currentTemperature);
 NRF.updateServices({
  "12411007-877b-4b6e-1d8a036a956a" : {
   "7e3defd9-1426-068f-d744-fa70603d83ac" : {
    value : [ currentTemperature % 256, currentTemperature / 256 ],
    notify: true
   }
  }
 });
}, BTN, {edge:"rising", debounce:50, repeat:true});