-
• #2
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 useNRF.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.
-
• #3
Hi!
Thank you very much!!!
It works!
Hi all,
I am using puck.js in advertising mode with the firmware version 2v01 an I am pretty new in using puck.js. I started with the code:
I used a constant voltage generator to simulate the drop of the battery level. After I had changed the voltage from 2,9 V to 2,7 V, I waited days along but the puck.js didn't refresh the battery level (it stays 100%). On the other side, if I connect to Espruino Web IDE and upload the code, than the battery level is refreshed immediately, showing some 80% for 2,7 V.
How can I get the puck.js to update the battery level during advertising? Is it possible to configure the interval, like once per day.
I have also tried the solution suggested in this Forum:
In this case I get the empty service data (i.e. any battery level shown)
Thank you in advance!