Sleep management for battery-operated devices
This section describes the generic sleep management for gen2 battery-operated devices (for example, Shelly Plus H&T).
In order to conserve battery charge and ensure accurate sensor measurements, battery-operated devices spent most of their lifetime in a deepsleep state that deactivates WiFi connectivity. Unless in setup-mode, battery-operated devices only wake up and connect to WiFi to transmit new sensor data.
Once awake, battery-operated devices aim to go back to sleep as soon as possible. In order to do so, the device monitors a number of so called locks
, which track the communication progress on all outbound channels (cloud, MQTT, UDP) and ongoing services (OTA, webhooks). When all locks
are released, the device goes back to sleep.
In general, the behavior of battery-operated devices is as follows:
- When the device wakes up and connects to a WiFi network, it will proactively push its full status via NotifyFullStatus on all enabled outbound channels.
- The device will keep each channel open for incoming requests, and expects to receive an
EndOfQueue
command (Mqtt.EndOfQueue {}
,Udp.EndOfQueue {}
) within a reasonable timeout (2s for MQTT and UDP), meaning there are no more requests. Requests received after anEndOfQueue
command are not guaranteed to receive a response. - When all channels have received an
EndOfQueue
command or have timed out, the device will send asleep
event via theNotifyEvent
method, meaning it will shortly disconnect and go back to sleep.