0

I'm having an issue with Blynk.begin(auth, ssid, pass); The problem is, when it fails to connect to the wifi, the rest of the program does not continue.

I'm using a Wemos D1 and it is also controlling some relays based on a temperature sensor. But when there was a power outage and power comes back on, the programs should continue whether the wifi is working or not, so that relays can still be controlled by the temperature sensor reading.

What happens now is if there is a wifi issue when Wemos D1 is starting up again, the program simply stops in the void setup() at Blynk.begin(auth, ssid, pass); and the rest of the program cannot be executed.

Anyone knows how to avoid this?

Kind regards, Peter

4
  • This has been a weakness with Blynk right along. The connect functions block and nothing else can execute until they return. In addition, some of the transmit-data functions block if your internet connection goes down or is carrying too much traffic for Blynk's traffic to complete in a timely way (how long is 'timely'?). I don't know a way around it other than possibly to make your own watchdog timer (one that can have a much longer timeout than 8 sec), and code your system to run without Blynk if it was restarted because of Blynk.
    – JRobert
    Apr 27, 2021 at 20:25
  • @JRobert, thank you for your comment! At first I thought perhaps just moving the Blynk code completely out of the void setup() into the main loop, at the very end, but even then I'll get stuck if wifi fails for some reason. I'm sure I'm missing something - not being very well experienced with anything more than the basic Blynk. Hard to imagine this is not a major issue when it comes to programs that need to execute important tasks regardless whether wifi is working or not...
    – Petrus
    Apr 27, 2021 at 20:41
  • this may help gist.github.com/mercdev/…
    – jsotola
    Apr 27, 2021 at 23:54
  • docs.blynk.cc/#blynk-firmware-configuration-blynkconfig and the ESP8266_Standalone_Manual_IP example for Blynk library
    – Juraj
    Apr 28, 2021 at 6:56

1 Answer 1

0

You can try my Blynk_WM or Blynk_Async_WM library with their Blynk.begin() functions are not blocking.


Check Why using this Blynk_WiFiManager with MultiWiFi-MultiBlynk features

Why using this Blynk_WiFiManager with MultiWiFi-MultiBlynk features

You can see that the system automatically detects and connects to the best or avaiable WiFi APs and/or Blynk Servers, whenever interruption happens. This feature is very useful for systems requiring high degree of reliability.

Moreover, this Blynk.begin() is not a blocking call, so you can use it for critical functions requiring in loop().

Anyway, this is better for projects using Blynk just for GUI (graphical user interface).

In operation, if WiFi or Blynk connection is lost, Blynk.run() will try reconnecting automatically. Therefore, Blynk.run() must be called in the loop() function. Don't use:

void loop()
{
  if (Blynk.connected())
     Blynk.run();
     
  ...
}

just

void loop()
{
  Blynk.run();
  ...
}

It's also beneficial to search in Blynk Forum for more information and examples

3
  • Khoi, stack exchange policy requires to disclose that these are your libraries
    – Juraj
    Apr 28, 2021 at 7:03
  • Thanks Juraj, already update.
    – khoih-prog
    Apr 28, 2021 at 8:46
  • Yes, Blynk_WiFiManager is great. I have modified DHT11ESP8266.ino to suit my needs and works.
    – Petrus
    May 5, 2021 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.