Last active
June 30, 2016 15:11
-
-
Save embedded-creations/9c8b5c17b5de6e629c319433bd872e7a to your computer and use it in GitHub Desktop.
Test to see how long it can take for the functions in system_sleep() to run - for Electron with Particle Build
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
STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY)); | |
const int delayAfterPublishMilliseconds = 5000; | |
const uint32_t magicWordComparison = 0xDEADBEEF; | |
retained uint32_t maxNetworkSuspendTimeSeconds = 0; | |
retained uint32_t maxNetworkDisconnectTime = 0; | |
retained uint32_t maxNetworkOffTime = 0; | |
retained uint32_t maxNetworkFunctionTime = 0; | |
retained uint32_t sequenceNumber = 0x00000000; | |
retained uint32_t magicWord = magicWordComparison; | |
void setup() { | |
time_t timestamp; | |
uint32_t networkDisconnectTimeSeconds; | |
uint32_t networkOffTimeSeconds; | |
uint32_t networkSuspendTimeSeconds; | |
// simple check for valid retained memory | |
if(magicWord != magicWordComparison) { | |
magicWord = magicWordComparison; | |
maxNetworkSuspendTimeSeconds = 0; | |
maxNetworkDisconnectTime = 0; | |
maxNetworkOffTime = 0; | |
maxNetworkFunctionTime = 0; | |
sequenceNumber = 0x00000000; | |
} | |
sequenceNumber++; | |
// disable this to test disconnect without Particle.publish | |
#if 1 | |
Serial.println("publish"); | |
Particle.publish("test", "teststring", 10, PRIVATE); | |
delay(delayAfterPublishMilliseconds/2); | |
Particle.process(); | |
delay(delayAfterPublishMilliseconds/2); | |
Particle.process(); | |
#endif | |
Serial.println("startup"); | |
Serial.printf("sequenceNumber: %08X\r\n", sequenceNumber); | |
Serial.print("max suspend time = "); | |
Serial.println(maxNetworkSuspendTimeSeconds); | |
Serial.print("max disconnect time = "); | |
Serial.println(maxNetworkDisconnectTime); | |
Serial.print("max off time = "); | |
Serial.println(maxNetworkOffTime); | |
Serial.print("max total time = "); | |
Serial.println(maxNetworkFunctionTime); | |
timestamp = Time.now(); | |
// enable this to test forcing a disconnect before calling System.sleep(SLEEP_MODE_DEEP, seconds) | |
#if 0 | |
Serial.println("network disconnect + off before suspend"); | |
network_disconnect(0, 0, NULL); | |
network_off(0, 0, 0, NULL); | |
#endif | |
System.sleep(SLEEP_MODE_WLAN, 60); | |
networkSuspendTimeSeconds = Time.now() - timestamp; | |
timestamp = Time.now(); | |
network_disconnect(0, 0, NULL); | |
networkDisconnectTimeSeconds = Time.now() - timestamp; | |
timestamp = Time.now(); | |
network_off(0, 0, 0, NULL); | |
networkOffTimeSeconds = Time.now() - timestamp; | |
Serial.print("current suspend time = "); | |
Serial.println(networkSuspendTimeSeconds); | |
Serial.print("current disconnect time = "); | |
Serial.println(networkDisconnectTimeSeconds); | |
Serial.print("current off time = "); | |
Serial.println(networkOffTimeSeconds); | |
if(networkSuspendTimeSeconds > maxNetworkSuspendTimeSeconds) { | |
maxNetworkSuspendTimeSeconds = networkSuspendTimeSeconds; | |
Serial.println("**** new max suspend time ****"); | |
} | |
if(networkDisconnectTimeSeconds > maxNetworkDisconnectTime) { | |
maxNetworkDisconnectTime = networkDisconnectTimeSeconds; | |
Serial.println("**** new max disconnect time ****"); | |
} | |
if(networkOffTimeSeconds > maxNetworkOffTime) { | |
maxNetworkOffTime = networkOffTimeSeconds; | |
Serial.println("**** new max off time ****"); | |
} | |
if((networkSuspendTimeSeconds + networkDisconnectTimeSeconds + networkOffTimeSeconds) > maxNetworkFunctionTime) { | |
maxNetworkFunctionTime = networkSuspendTimeSeconds + networkDisconnectTimeSeconds + networkOffTimeSeconds; | |
Serial.println("**** new max total time ****"); | |
} | |
delay(1000); | |
System.sleep(SLEEP_MODE_DEEP, 30); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment