Recently I noticed that when the WiFi router is on (WiFi is available) but the internet connection is lost from ISP the program stops. Even if I hard reboot the ESP board it will start and then stop here. “CONNECTING_NET => CONNECTING_CLOUD”
In order to eliminate all variables I used the example Edgent program, I made no changes other than adding Template ID and name, adding a timer, set the interval to 3 seconds to print some to the serial monitor so I monitor function in the serial monitor.
This is the output from the serial monitor
[389]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
///_, /////_
/__/ v1.1.0 on ESP8266
[675] INIT => CONNECTING_NET
[677] Connecting to WiFi: SenseIQ 2.4G
[6436] Using Dynamic IP: 10.0.0.4
[6436] CONNECTING_NET => CONNECTING_CLOUD
It does not move past this point when the router is on (no internet). In order to get past this point I switch off the router, and reboot the ESP then it will search for wifi, but not get it and my program continues to the point Edgent reboot the ESP (when it reaches the “WIFI_CLOUD_MAX_RETRIES”) and we start over (which is fine).
What can be done so that my code can run ‘offline’? I have customers where devices are not working due to this.
That’s the way that the Blynk Edgent example sketch is designed to work.
Blynk is an IoT system, and the Edgent example is designed to go through a process of attempting to connect to WiFi and the Blynk cloud server until it succeeds. Without these connections Blynk can’t operate.
If you want to change the behaviour of the Edgent example then it’s a fairly major re-write of that sketch.
An alternative is to switch to using an ESP32 board, and make use of the dual core features of that processor. You’d need to run the Blynk Edgent code in one core and your offline code (which presumably allows control via physical buttons) in the other core. You’d need to remove the calls to restartMCU() in the Edgent code, as this would reboot the entire board, not just core that’s running the Blynk code.
It’s still a fairly substantial rewrite, but there are a few topic on the subject in the forum if you do some searching.
I am using FreeRTOS with ESP projects, and it works great.
I want to focus on resolving the first issue where the program halt/hang and never recover unless a hard reboot to the D1 mini is introduced.
Problem: When the WiFi router loses internet (ISP problem etc) the program will reboot when an error is detected and will start up, connecting to WiFi, allocating dynamic IP, then only to get stuck trying to connect CONNECTING_NET => CONNECTING_CLOUD.
As I already mentioned, I used a blank Edgent example to eliminate any code mistakes I may have on my side. Trying to get to the root cause we switched off the router (simulating internet loss) the program then work as it should (detect error and reboot, repeat until the issue is resolved). So all is fine IF the router is not present. The moment the router is on (WiFi is on but ISP cable unplugged) and there is no internet the program gets stuck at CONNECTING_NET => CONNECTING_CLOUD and never recovers.
Question:
Is there from your experience anything that can be done here? I have many devices in the field that is failing due to this.
Just a note, we made a few changes to the code adding ‘Serial.print’ to understand where the code hangs, during the “enterConnectCloud” call, it hangs when the program call “Blynk.run();”
We ran the code you provided on a Lolin32 board and it’s very similar to what we use in our larger products where we utilize the FreeRTOS (similar).
The problem is not with the ESP32, it’s how Edgent execute while WiFi is available but not internet!
What exactly happens when “enterConnectCloud” call Blynk.run();?
The program halts here when the above scenario is true. If I can find a place to add a ‘timeout’ (reboot) then we will be ok if there is no internet but WiFi is present.