• Hi! Your issue is that the advertising data is set at the time you make the call. It isn't continually updated.

    To update it, all you need to do is make the call repeatedly, so use some code like this:

    setInterval(function() {
      NRF.setAdvertising({
        0x180F : Puck.getBatteryPercentage()
      },{name: "puckName", interval: 1000});
    }, 30*1000); // 30 seconds
    

    Puck.js will then go to sleep (apart from advertising), but every 30 seconds it'll wake up and change the advertising. You can lengthen the interval, but at some point there are diminishing returns for the power usage.

    For NRF.setServices, a similar thing applies - except you don't want to redefine the services each time so you need to use NRF.updateServices:

    NRF.setServices({
      0x180F : { // Battery Service
        0x2A19: {  // Battery Level
          readable: true,
          notify: true,
          value : [Puck.getBatteryPercentage()]
    }}},{
      advertise: [ '180F' ]
    });
    setInterval(function() {
      NRF.updateServices({
        0x180F : { // Battery Service
          0x2A19: {  // Battery Level
            value : [Puck.getBatteryPercentage()]
      }}});
    }, 30*1000); // 30 seconds
    

    You should get battery data this way, but only when you connect and view the characteristic. In the advertising data that is sent out without a connection you will see just the 180F service.

About

Avatar for Gordon @Gordon started