I’m curious how others deal with this issue- I have two Wemos D1 minis. Wemos ‘A’ is connected to a sensor, reads the humidity, and sends a bridge.digitalWrite to Wemos ‘B’ to set pin D4 HIGH or LOW (controlling a relay board).
Every once in a while, I get a server disconnect at one or both mini’s- if Wemos A or B disconnects, and wemos B was previously set to the HIGH position via bridge, it will be stuck in that position as it’s not getting any new signals from A and doesn’t know if it should turn on or off, so i get an incredibly humid room, or a ridiculous dry room when i get to work the next day. In a climate control system, this no good.
The I think there are a few ways of solving this- varying in degrees of ‘hackiness’ that I’m going to state below, but how are others dealing with this issue?
Potential hacky solutions:
1: Re-connecting… I think my main issue is that my controllers are just not reconnecting. Do I need to add a snippet of code that runs every couple minutes and tests for connectivity/reconnects to blynk if false?
2: Connection test between two boards- I think there is a widget opportunity here, but would something like:
Board A:
(every minute)
bridge.virtualWrite( V1, 1);
Board B:
(every two minutes)
BLYNK_WRITE(V1)
test = param.asInt();
if (test == 1) {
Blynk.virtualWrite(V1, 0);
break;
} else {
turn off all the relays, send an email, reboot, reconnect to blynk etc etc
}
If you took this code and reversed it, you would essentially have a two-way connectivity test between two boards. Can this be widgetized with a clever name?? @Dmitriy
3: ESP reboot- is there a way to force the ESP to reboot if connection fails?
this will reboot the board and can be used with if(!Blynk.connected()) and SimpleTimer.
This procedure is not normally required as most hardware can be set to reconnect to Blynk but we recently started using it with some particularly problematic hardware. We could have probably spent time trying to figure out what the cause of the problem was but decided it wasn’t worth the effort and used this hack instead.
I believe officially it needs at least the delay(x) after the function call. I know it seems wrong as you would expect the delay(x) never to be triggered but it is. I always use a proceeding delay(x) too.
I have no idea what value x needs to be but it is quite high i.e. 4 figures.
The particular issue we had was that the hardware (quite a rare piece of kit) struggled to reconnect to Blynk if it hadn’t been reset before trying to make the connection so the time check was 20s. It obviously depends on your particular project as to what value to choose for the timer.
Our tests with this hardware involved powering off the router to see how it responded when WiFi / internet connection to a server failed and 20s was actually a bit too short as the hardware doesn’t really like being reset over and over again.
@Costas I am adding DHT11 sensor with 2 relays, problem is when I press HIGH/LOW in blynk app controlling 2 relays DHT11 sensor intersects (in my opinion DHT11 send a lot of value that makes to esp disconnect ) them, then in blynk app shows “your esp8266 is offline”. I can able to disable by overriding manually DHT11. I thought ESP.reset might be good solution.
#include <SimpleTimer.h>
SimpleTimer timer;
void setup(){
//........
timer.setInterval(20000, reconnectBlynk); // reconnect to Blynk every 20s if not already connected
}
void reconnectBlynk() { // check connection every 20s from timer in setup
if (!Blynk.connected()) {
delay(1000);
ESP.reset(); // maybe a reset is the best way to ensure the ESP is ready to run.
delay(1000);
}
}
void loop(){
if (Blynk.connected()) { // to ensure that Blynk.run() function is only called if we are still connected to the server
Blynk.run();
}
timer.run();
}