The DeviceOff functionality allows turning device off by pressing a power button. It can be used to drastically reduce the battery consumption (to less than 1 µA) so that an unused device can be shipped to a customer and can be stored in stock for a long time with the battery inserted.
See also our documentation on Asset Tracking Tags, where we use this feature.
To turn use the power off functionality, the
powerButton needs to be configured in the
BoardConfiguration for the board. When the power button is pressed for over 1 second the device resets and enters a system off mode. If the device has LEDs, the power off will be signalled by blinking the red led 5 times.
The current time periods are the following (x-axis in seconds):
The only way to wake the device from system off mode is to press power button for over 1 second, to execute a pin reset or to replace the battery. If the power button is pressed for less than 1 second, while in off mode, device will start booting, but will immediately go to system off mode again. When waking up, FruityMesh will by default signal this by shortly flashing the green and blue LEDs (or the red one if it is the only one available).
During runtime, we detect the duration that the power button was pressed and only go to system off mode once it has been pressed for longer than one second. If the device is powered off, there is no possibility to detect the duration of a button press. The device will therefore wake up from system off as soon as it detects that the power button was pressed. After waking up, we postpone the boot process and instead observe how long the power button is being pressed. If it is pressed for less than one second, we go to system off again. This helps to prevent an accidential press on the button or other electrical hickups. If we detect that the button was pressed for more than one second, we continue to boot.
Once the device is running, it might have initialized functionality that consumes additional power, we therefore do a soft reset of the chip and on the next boot, we check the reason for the reboot. If the reason is
PREPARE_DEVICE_OFF, we then immediately go to system off mode before executing any other code.
|Switching off the device will not disable external sensors. We have not yet implemented callbacks to perform actions before the device is being powered off.|
By default, the node will boot into safe mode to recover from unexpected faults.
In cases where a reboot is on purpose, like a Watchdog reboot or after the
"reset" action, the reboot magic number has to be set. This is a
u32 variable that is stored inside a persisted RAM region next to the
ramRetainStruct, so it is available after a reboot.
The magic number must be set to the defined value of
REBOOT_MAGIC_NUMBER before a reboot. If not, the node will boot into safe mode.
Booting into safe mode is not generally bad, but the watchdog will trigger a reboot after 20s, replacing the original reboot reason with