Registers a function to be executed when the server requests a restart
Device
Name | Type | Description |
---|---|---|
callback | Function |
A function with one parameter that will be executed when a restart is requested
|
Nothing
This method registers a callback function that will be executed whenever the server wants the device to restart. This gives the device the opportunity to perform any necessary housekeeping tasks before manually triggering the restart, which it does by calling server.restart(). The registered shutdown handler may even delay the restart until a less disruptive time.
The callback function is passed one parameter, reason, which holds an integer indicating why the server has requested the restart. The value will be one of the following constants:
Constant | Value | Description |
---|---|---|
SHUTDOWN_NEWSQUIRREL | 1 | New Squirrel is available |
SHUTDOWN_NEWFIRMWARE | 2 | New impOS firmware is available |
SHUTDOWN_OTHER | 3 | A restart is requested for some other reason |
The values assigned to the constants may change in a future impOS™ release.
If no callback is registered using server.onshutdown(), or if the method has been used to register a null
function, then server-requested restarts will take effect immediately.
If the device undergoes a cold power-cycle, you trigger a device restart via impCentral™ (Build and Force Restart) or the impCentral API, or the device is re-assigned to a different Device Group, then any pending impOS update and/or updated Squirrel will be applied immediately and the server.onshutdown()-registered callback will not be executed.
This example demonstrates how to save important data before devices restart.