Skip to main content


Registers a function to be executed when the imp next goes idle




Name Type Description
callback function The function to call when the imp goes idle




The registered callback function will be executed as soon as the imp becomes idle: in other words, when there are no pending interrupts or messages from the server to process, and Squirrel has come to the end of its sequence of instructions. The function is called with no parameters.

Only one idle callback may be active; setting a new one clears a previously registered callback. So an existing idle callback can be cancelled using:


An idle callback is only called once, even if the imp then remains awake but idle.

One use for imp.onidle() is in conjunction with the methods server.sleepfor() or server.sleepuntil(). These calls put the imp to sleep immediately, ie. even if there are messages from the server waiting to be dealt with and which might be important, such as ‘reload the Squirrel firmware’.

The example below shows how you can put the imp to sleep once all messages have been processed and no other important events are occurring.

Example Code

The following snippet shows the recommended code for triggering deep sleep: put the device to sleep only when it has become idle, ie. make the sleep call from within the onidle handler.