スリープ挙動についてはOSのスリープのページを参照してください。
2種類のスリープがあり用途によってライトスリープとディープスリープを使い分けることができます。
| スリープ | 活用方法 |
|---|---|
| ディープスリープ | 最も消費電力が少ない。終了後は再起動となる |
| ライトスリープ | 一時的に停止するのみで終了後はプログラムが継続動作される。Wi-Fiなどネットワークは切断されることがある |
また、それぞれにおいて外部の通信モデム、特にIntelligent Edge シリーズにおけるLTE通信モジュールまでスリープさせるかどうかを指定できます。
ディープスリープの場合は通常はモデムもスリープさせ、ライトスリープの場合は継続することも考えられます。
os.sleep(mode, milliseconds)
スリープ状態に移行します。
以下の例では起動後に3秒だけライトスリープし、クラウドからの指示に応じてディープスリープを開始します。
function on_event(event)
if event == "power_on" then
os.log(" - Light Sleep Start 3seconds. Tick="..os.getTick());
os.sleep(3 * 1000, 3);
os.log(" - Light Sleep Ended Tick="..os.getTick());
os.log(" - During light sleep, tick does not counted");
elseif event == "online" then
os.log(" - Lua Online.");
end
end
function on_command(command)
os.log("Going to deep sleep 1sec");
os.sleep(1 * 1000, 0);
end
-- 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