Multiple ESPs 1 auth code no bridge

Hello,
I am currently working on a home automation system using a local Blynk server. I have setup 3 Wemos D1 minis. 1 controls a relay and the other 2 each have a DHT sensor. All 3 are sharing the same auth code and they will all connect and report back to my project on the app but when I press 1 of the virtual buttons to activate the relay sometimes I will get a “Your WemosD1 mini was disconnected” message. Everything is being controlled with virtual pins so there shouldn’t be any issues as far as I can tell. The code is quite simple so I don’t understand why any of the boards would want to be disconnected.

Any ideas why this would happen? I will eventually have up to 5 Wemos boards connected to this 1 project with each one either controlling relays or gathering information from sensors. I don’t want to run into any issues with frequent disconnects so hopefully this is an easy fix.

Hello.

Wiring, power, code issue. Many possible reasons indeed. Posting code may help.

Board 1

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

bool isFirstConnect = true;
unsigned long lastReading = 1;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "myauth";

void setup() {
  Serial.begin(9600);
  
  Blynk.begin(auth, "myssid", "mypass", "myserver");
}

BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll();
    isFirstConnect = false;
  }
}

void loop() {
  Blynk.run();

  unsigned long now = millis();
  Blynk.run();
  if (now - lastReading >= 10000) {
    lastReading = now;
    int lightLvl = map(analogRead(A0),1024,0,0,100);
    Blynk.virtualWrite(V15, lightLvl);
    Serial.println(lightLvl);
  }
  //int lightLvl = map(analogRead(0),1024,0,0,100);

  int lightLvl = analogRead(0);
  Serial.println(lightLvl);
}

Board 2

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

bool mainRoom;
bool isFirstConnect = true;

WidgetLED mainRoomLED(V8);


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "myauth";

void setup() {
  Serial.begin(9600);

  Blynk.begin(auth, "myssid", "mypass", "myserver");
}

BLYNK_WRITE(V2)
{
  //BLYNK_LOG("Got a value: %i", param.asInt());
  mainRoom = param.asInt();

  Serial.println(mainRoom);
  if(mainRoom == 1)
  {
    digitalWrite(D1, HIGH);
    mainRoomLED.on();
  }
  else
  {
    digitalWrite(D1, LOW);
    mainRoomLED.off();
  }
}

BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll();
    isFirstConnect = false;
  }
}

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

Board 3

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

//Temp sensor
DHT_Unified dht(2, DHT22);

uint32_t delayMS;
bool isFirstConnect = true;
unsigned long lastReading = 1;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "myauth";

void setup() {
Serial.begin(9600);
  sensor_t sensor;
  sensors_event_t event;
  
  dht.begin();
  dht.temperature().getSensor(&sensor);

  Serial.println("------------------------------------");
  Serial.println("Temperature");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" *C");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" *C");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" *C");
  Serial.println("------------------------------------");

  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.println("Humidity");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println("%");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println("%");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println("%");
  Serial.println("------------------------------------");

  dht.temperature().getEvent(&event);
  Serial.print("Temperature Inside: ");
  Serial.println(event.temperature);

  dht.humidity().getEvent(&event);
  Serial.print("Humidity Inside: ");
  Serial.println(event.relative_humidity);

  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 3000;
  
  Blynk.begin(auth, "myssid", "mypass", "myserver");
}

BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll();
    isFirstConnect = false;
  }
}

float cToF(float c) {
  return c * 9 / 5 + 32; 
}

void dhtCheck() {
    sensors_event_t event;
    dht.temperature().getEvent(&event);
    Serial.print("Temperature Inside: ");
    float convertedTemp = cToF(event.temperature);
    Serial.println(convertedTemp);
    
    // Get humidity event and print its value.
    dht.humidity().getEvent(&event);
    Serial.print("Humidity Inside: ");
    Serial.println(event.relative_humidity);
    
    Blynk.virtualWrite(V3, convertedTemp);
    Blynk.virtualWrite(V4, event.relative_humidity);
}

void loop() {
  unsigned long now = millis();
  Blynk.run();
  if (now - lastReading >= 10000) {
    lastReading = now;
    dhtCheck();
  }
}

Eventually each one of these boards will have multiple sensors and relays added to them.

I’m using the wemos relay shield and wemos DHT22 shield on their respective boards for testing so there isn’t any wiring involved on those 2 and they are being powered directly from USB at the moment. The board with the light sensor is also being powered by USB but the sensor is wired to it. Only 3 wires and everything is correct.

My only thought is that since I am using a web address to my server instead of it’s IP address there may be some latency with having to go through the web instead of having a direct connection. That latency may be just enough to where the board appears offline after a command is sent to it.

I have watched the board communication through serial monitor and the board is not being reset which makes me think even more that latency could be the issue.

board 3 code is in a word “bizarre”

why are you doing the DHT stuff in setup?

All it does is give the details of the type of sensor that is being used. It’s just a one time thing that is printed to serial monitor for informational purposes. It doesn’t have to be there but it lets me know if the sensor isn’t working correctly.

Example of the output

Temperature
Sensor:       DHT22
Driver Ver:   1
Unique ID:    -1
Max Value:    125.00 *C
Min Value:    -40.00 *C
Resolution:   0.10 *C
------------------------------------
------------------------------------
Humidity
Sensor:       DHT22
Driver Ver:   1
Unique ID:    -1
Max Value:    100.00%
Min Value:    0.00%
Resolution:   0.10%
------------------------------------
Temperature Inside: 21.30
Humidity Inside: 1.00

i guess once could be enough… it just looks strange…