Skip to main content


Causes the imp to halt code execution for a specified period


Device + Agent


Name Type Description
sleepTime float The delay duration in seconds




This method causes the device to pause executing code for a period of time expressed in seconds and with a resolution of 1μs (0.000001 seconds). The method will block for this period, and no other Squirrel code (eg. timers and event handlers) will run.

The imp remains connected to WiFi while paused, but does not process messages from the server. Very short sleep periods — under 20ms — are established using busy-waiting; longer periods by the use of system timers.

This is the most precise way to do nothing: imp.wakeup() has centisecond resolution and server.sleepfor() only deals with whole seconds.

The method may also be used in agent code to suspend processing for the specified period, typically to introduce a delay of a fixed duration. When the agent is paused, it does not process messages from the device. No other Squirrel code, such as timers or event handlers, will run.

  • For a way to doze while letting event-handlers and message processing continue, refer to imp.wakeup().

Example Code

The following code oscillates the output of an imp pin every 50ms, using imp.sleep() to introduce a suitable pause before switching the pin’s state.