sleep

For information regarding sleep behavior, please refer to the OS Sleep page.

There are two types of sleep modes available. You can choose between Light Sleep and Deep Sleep depending on your specific use case.

Sleep Mode Usage & Characteristics
Deep Sleep Offers the lowest power consumption. The system performs a full reboot upon waking up.
Light Sleep Temporarily pauses execution. The program resumes from where it left off after waking. Note that network connections (such as Wi-Fi) may be disconnected.

Additionally, for both modes, you can specify whether to put external communication modems into sleep mode—specifically the LTE modules used in the Intelligent Edge series.

Generally, for Deep Sleep, the modem is also put to sleep to save power. For Light Sleep, you may choose to keep the modem active to maintain a quicker recovery.

os.sleep(milliseconds, mode)

Transitions the device into a sleep state.

The following example demonstrates a 3-second Light Sleep immediately after startup, followed by a transition to Deep Sleep upon receiving a command from the cloud.

function on_event(event)
  if event == "power_on" then
    os.log(" - Light Sleep Start 3seconds. Tick="..os.getTick());
    -- Start Light Sleep for 3000ms (Mode 3)
    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");
  -- Start Deep Sleep for 1000ms (Mode 0)
  os.sleep(1 * 1000, 0);
end

-- Mode Reference:
-- 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