Last active
March 18, 2021 14:50
-
-
Save ElectricImpSampleCode/4c644050e872b23d0657 to your computer and use it in GitHub Desktop.
A simple function which uses hardware.wakereason() to reveal why an imp restarted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment