Skip to main content

server.expectonlineat(hour, minute, second, dayOfWeek)

Informs the server that the device will be disconnecting and that it will reconnect at a specified time




Integer — 0 on success, or a Send Error Code on failure


Name Type Description
hour Integer The wake-up hour in 24-hour format (midnight = 0)
minute Integer The wake-up minute (0—60)
second Integer Optional, the wake-up second (0—60, default = 0)
dayOfWeek Constant Optional, the day of week on which to wake (0—6, default = any)


Note This method is now deprecated. However, removing it altogether would cause users’ existing code to stop working, so we currently have no plans to do so.

This method informs the server that the imp will now disconnect but will re-connect at a specified future time, expressed using UTC in 24-hour notation. Without this information, the server may end up assuming that the imp is offline, when in fact it is just asleep.

Optionally, the day of the week can also be given, which means this function can inform the server of absences lasting up to a week. The Electric Imp API provides numeric constants for SUNDAY through to SATURDAY, enumerated from 0 to 6. These values are consistent with Squirrel’s date() function, which returns a table where the wday field is the number of days since Sunday. This means that no normalizations have to be done in the Squirrel code.

dayOfWeek Constant Value

If no day of the week is given — only three parameters are passed — then the wake-up matches any day of the week, ie. the disconnection can last a maximum of one day.

This method should be called when using the imp.deepsleepuntil() call, or otherwise disconnecting the WiFi. The server.sleepuntil() call combines the effects of server.expectonlineat() and imp.deepsleepuntil(), but there are circumstances when the two calls should not be combined and instead run separately: for example, in order to perform operations before the imp is put into deep sleep.

Because this method is only useful for imps that are about to disconnect from the server, server.expectonlineat() includes an implicit server.disconnect() call after informing the server.

Example Code

This example collects data every second. Once a day (at midnight) it comes online and sends the data to the server.