obnizOS is equipped with a sleep function that stops the CPU operation to minimize power consumption.
This feature is ideal for operating devices with batteries or solar panels in environments where a constant power supply is unavailable, such as outdoors.
Sleep Types and Behavior
obnizOS supports the following types of sleep modes:
| Type | Compatible OS Version | Behavior |
|---|---|---|
| Deep Sleep + External Modem Sleep | 7.0.0 or later | System shuts down completely and reboots after waking up. The external modem also enters sleep mode. |
| Deep Sleep (Without External Modem Sleep) | 7.0.0 or later | System shuts down completely and reboots after waking up. The external modem remains active. |
| Light Sleep + External Modem Sleep | 7.0.0 or later | System pauses temporarily without rebooting. The external modem also enters sleep mode. |
| Light Sleep (Without External Modem Sleep) | 7.0.0 or later | System pauses temporarily without rebooting. The external modem remains active. |
| obniz Board 1Y Sleep | 2.0.0 or later | Specifically for obniz Board 1Y. Minimizes power by cutting off the 3.3V power line using an external power module. |
- obniz Board 1Y Sleep is the most power-efficient mode but is hardware-dependent.
- Other sleep modes are standard functions of the ESP32 (on which obnizOS runs) and can be used on any obnizOS-compatible ESP32 device.
- External Modem refers to an LTE modem connected externally. For the Intelligent Edge series, the internal nRF91 modem will enter sleep mode when this option is selected.
Wake-up Triggers
When initiating sleep, you must specify one of the following triggers to wake the device:
| Trigger Type | Compatible OS Version | Behavior |
|---|---|---|
| Timer | 2.0.0 or later | Wakes up after a specified duration. |
| IO0 State Change (High/Low) | 2.0.0 or later | Exclusive to obniz Board 1Y. Wakes up when the pin state changes. |
- Note on Accuracy: The timer relies on the internal ESP32 clock or the power module's clock. Please be aware that it may not be perfectly accurate and can be affected by ambient temperature.
- Connection Latency: The device does not become "Online" immediately after waking up. For example, if you set a 60-second sleep, the internet reconnection process starts after those 60 seconds have passed. Therefore, it will take additional time before the device is accessible via the cloud.
Using Sleep via Javascript SDK (Cloud)
When controlling obniz via JavaScript or the Cloud, only the following two modes are available:
- Deep Sleep + External Modem Sleep
- obniz Board 1Y Sleep (Automatically selected when using an obniz Board 1Y)
// Javascript Example
obniz.sleepSeconds(60); // Sleep for 60 seconds (1 minute)
Since you can trigger sleep at any timing from the cloud, it is particularly useful for periodic monitoring:
- Sleep the device after data is successfully uploaded until the next required interval.
- Adjust sleep duration dynamically based on battery voltage (e.g., sleep for 5-minute intervals).
Using Sleep via Lua Plugin
The Lua Plugin installed on the device allows for more granular control, including both Light and Deep sleep modes.
The duration is specified in milliseconds.
-- Lua Example
os.sleep(5 * 1000, 0); -- Deep sleep + External module sleep
os.sleep(5 * 1000, 1); -- Deep sleep + Without external module sleep
os.sleep(5 * 1000, 2); -- Light sleep + External module sleep
os.sleep(5 * 1000, 3); -- Light sleep + Without external module sleep
Edge Computing Advantage:
Using the Lua Plugin allows the device to make decisions and enter sleep mode before connecting to the internet. This is highly effective for minimizing battery consumption—for example, checking a sensor value and only connecting to the internet if data transmission is necessary.
The following script demonstrates how to connect to the internet only when the voltage on IO1 exceeds 2.0V:
io.retain(1, true);
if ad.get(1) < 2.0 then
-- If voltage is low, sleep for 1 minute and check again without connecting to the cloud
os.sleep(60 * 1000, 0);
end
Caution: When using sleep before an internet connection is established, there is a risk that the device may never connect to the internet if the conditions are not met. Please use this feature with care for remote maintenance.
Power Consumption during Sleep
Power consumption during sleep varies depending on the hardware. For specific values, please refer to the hardware reference manual for your specific product.