Last active
December 19, 2015 00:49
-
-
Save electricimp/5871844 to your computer and use it in GitHub Desktop.
Code snippet showing typical switch statement for hardware.wakereason(). In this example we're just logging the reason to the debug window, but we *could* be performing various tasks based on how the imp was woken up.
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 logDeviceOnline() | |
{ | |
local reasonString = "Unknown" | |
switch(hardware.wakereason()) | |
{ | |
case WAKEREASON_POWER_ON: | |
reasonString = "The power was turned on" | |
break | |
case WAKEREASON_SW_RESET: | |
reasonString = "A software reset took place" | |
break | |
case WAKEREASON_TIMER: | |
reasonString = "An event timer fired" | |
break | |
case WAKEREASON_PIN1: | |
reasonString = "Pulse detected on Wakeup Pin" | |
break | |
case WAKEREASON_NEW_SQUIRREL: | |
reasonString = "New Squirrel code downloaded" | |
break | |
case WAKEREASON_SQUIRREL_ERROR: | |
reasonString = "Squirrel runtime error" | |
break | |
case WAKEREASON_NEW_FIRMWARE: | |
reasonString = "impOS update" | |
break | |
case WAKEREASON_SNOOZE: | |
reasonString = "A snooze-and-retry event" | |
break | |
case WAKEREASON_HW_RESET: | |
// imp003 only | |
reasonString = "Hardware reset" | |
} | |
server.log("Reason for waking/reboot: " + reasonString) | |
} | |
logDeviceOnline() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment