Communication between 2 ESP's... Dealing with disconnects? (widget opportunity)

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)
test = param.asInt();
if (test == 1) {
Blynk.virtualWrite(V1, 0);
} 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.

1 Like

ESP.reset(). of course it’s that easy :smiley:

Thanks @Costas I’ll give this a try… How often do you do your !(Blynk.connected()) check?

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.

I deal with the issue by not using bridge!


So where do you put these ESP.reset in sketch?

@speed57 it depends why you are doing the reset in your particular project.

For us we have a function that checks every 20s to see if the hardware is connected to Blynk. If it is not then we do the reset.

@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.

So how do you do this?

Your problem sounds like bad coding that isn’t fixed by using the reset facility.

1 Like

SimpleTimer set at 20s intervals to call the check connection function.
Let me know if you require the precise details.

Yes please, it would be great :pray:

@speed57 ok the elements you need to include:

#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()) {
      ESP.reset();  // maybe a reset is the best way to ensure the ESP is ready to run.

void loop(){
  if (Blynk.connected()) { // to ensure that function is only called if we are still connected to the server;
1 Like

@Costas thank you very much, really appreciate that, very explanatory :slight_smile:

I would like to do this with an arduino Mega. Can I ask if there is a reset for arduinos as well ??? @Costas



Why dredge up a really old topic when a simple Google search would have answered that question?