Returns a constant indicating the reason why the imp was woken
Device
Integer — a Wake-up Code
This method tells you what event caused the imp to wake up. The integer code it returns will be one of the following constants. You should note that not all of these constants are valid for a given type of imp.
Code Constant | Value | Description |
---|---|---|
WAKEREASON_POWER_ON | 0 | Powered on (cold boot) |
WAKEREASON_TIMER | 1 | Woken after sleep time expired |
WAKEREASON_SW_RESET | 2 | Restarted due to a software reset (eg. with imp.reset()) or an out-of-memory error occurred |
WAKEREASON_PIN | 3 | Woken by wakeup pin going high |
WAKEREASON_NEW_SQUIRREL | 4 | Restarted due to new Squirrel code being loaded |
WAKEREASON_SQUIRREL_ERROR | 5 | Restarted due to a Squirrel run-time error |
WAKEREASON_NEW_FIRMWARE | 6 | Restarted due to a firmware upgrade |
WAKEREASON_SNOOZE | 7 | Woken from a snooze-and-retry event |
WAKEREASON_HW_RESET | 8 | Restarted by RESET_L pin (imp003 and above only) |
WAKEREASON_BLINKUP | 9 | Restarted following a reconfiguration by BlinkUp |
WAKEREASON_SW_RESTART | 10 | Restarted by server.restart() |
WAKEREASON_POWER_RESTORED | 11 | VBAT powered during a cold start |
The values assigned to the constants may change in a future impOS release.
Power cellular radio brownouts at start-up are currently reported as reason 11.
A simple function which uses hardware.wakereason() to display the reason why an imp restarted.
function logWokenReason() { | |
local s = "Device restarted. Reason: "; | |
local c = hardware.wakereason(); | |
switch (c) { | |
case WAKEREASON_POWER_ON: // 0 | |
s += "Cold boot"; | |
break; | |
case WAKEREASON_TIMER: // 1 | |
s += "Timer woke the imp"; | |
break; | |
case WAKEREASON_SW_RESET: // 2 | |
s += "Software reset or out-of-memory error"; | |
break; | |
case WAKEREASON_PIN: // 3 | |
s += "Wakeup pin asserted"; | |
break; | |
case WAKEREASON_NEW_SQUIRREL: // 4 | |
s += "Application code updated"; | |
break; | |
case WAKEREASON_SQUIRREL_ERROR: // 5 | |
s += "Squirrel error during the last run"; | |
break; | |
case WAKEREASON_NEW_FIRMWARE: // 6 | |
s += "Device has a new impOS"; | |
break; | |
case WAKEREASON_SNOOZE: // 7 | |
s += "Woken from a snooze-and-retry event"; | |
break; | |
case WAKEREASON_HW_RESET: // 8 | |
// Requires imp003 or above | |
s += "RESET pin asserted"; | |
break; | |
case WAKEREASON_BLINKUP: // 9 | |
s += "Device's network settings have been re-configured"; | |
break; | |
case WAKEREASON_SW_RESTART: // 10 | |
s += "Device's application called server.restart()"; | |
break; | |
default: | |
s += "Other (code: " + c + ")"; | |
} | |
server.log(s); | |
} | |
logWokenReason(); |