I went looking for where the includes might be coming from to collect revisions of as many libraries as I could and found it in WiFi101. So I was guessing which libraries so John93 could verify which revs he was operating under.
What I did discover from your example is that Edgent runs in a state machine (in ConfigMode.h) and calls app_loop() from most of the states, which is where the users code would be run from. I was trying to run it from the main loop() routine. So if you run your code in app_loop, which you did, it calls your code even if it has stuff to do.
There are two timeouts, WIFI_CLOUD_CONNECT_TIMEOUT and WIFI_NET_CONNECT_TIMEOUT, in Settings.h that are set for 30 seconds. If it cannot connect with wifi(NET) or Blynk(CLOUD), within these timeouts, it resets the cpu. I could increase these but it would just reset less often.
- When something goes wrong, the state machine sets BlynkState to MODE_ERROR, which in turn causes enterError() to be called which resets the CPU
// Edgent state machine:
void run() {
app_loop();
switch (BlynkState::get()) {
case MODE_WAIT_CONFIG:
case MODE_CONFIGURING: enterConfigMode(); break;
case MODE_CONNECTING_NET: enterConnectNet(); break;
case MODE_CONNECTING_CLOUD: enterConnectCloud(); break;
case MODE_RUNNING: runBlynkWithChecks(); break;
case MODE_OTA_UPGRADE: enterOTA(); break;
case MODE_SWITCH_TO_STA: enterSwitchToSTA(); break;
case MODE_RESET_CONFIG: enterResetConfig(); break;
default: enterError(); break;
}
}
The enter Error routine restarts the CPU:
void enterError() {
BlynkState::set(MODE_ERROR);unsigned long timeoutMs = millis() + 10000;
while (timeoutMs > millis() || g_buttonPressed)
{
delay(10);
app_loop();
if (!BlynkState::is(MODE_ERROR)) {
return;
}
}
DEBUG_PRINT(“Restarting after error.”);
delay(10);restartMCU();
}
So maybe I can re-write this so instead of resetting the CPU, I just restarts the state machine. I was hoping somewhere was an example (template) for us folks that want to run code without the status of the provisioning, wifi or Blynk connection to reset our products.