You can use NRF.on('connect', ... and NRF.on('disconnect', ... events to turn on and off the sensor / sampling / updating.
For example these two lines, turn on the magnetometer when connected, and turns it off when disconnected. The magnetometer event calls NRF.updateServices. So no magnetometer power consumption and updating of service data if nothing is connected:
// on connect / disconnect blink the green / red LED turn on / off the magnetometer
NRF.on('connect', function() {Puck.magOn(magRate); digitalPulse(LED2, 1, 100)})
NRF.on('disconnect', function() {Puck.magOff(); digitalPulse(LED1, 1, 100)})
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
You can use
NRF.on('connect', ...
andNRF.on('disconnect', ...
events to turn on and off the sensor / sampling / updating.For example these two lines, turn on the magnetometer when connected, and turns it off when disconnected. The magnetometer event calls
NRF.updateServices
. So no magnetometer power consumption and updating of service data if nothing is connected:Full code at https://github.com/AkosLukacs/PuckStreamĀing