Connection loss Wemos D1 mini: flood error?

Dear all,

I’ve a problem with my Wemos D1 mini that still loss connection with Blynk server (sometimes in few minutes and sometimes in 3-4 hours).
The project uses a STH30 probe to measure temperature and humidity and a ACS712 to measure the power of the boiler. Data is send every 1 second. Also time, date and a check on pin D1 (to check if it is actually activated) are send to server every 1 second.
Is possible that is a flood error? As for the code I used only SimpleTimer for send data and no code has been edited in loop () section.
I’ve read the DOC section but I didn’t found “how many” measures for a time is possible to send.
This is the complete code, could you please help me? The project is very simple, but required me a lot of time to set up.
Thank you


/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <WidgetRTC.h>
#include <WEMOS_SHT3X.h>

char auth[] = "XXXXXXXX";
char ssid[] = "XXXXX";
char pass[] = "XXXXXX";

#define pinout_d5 D5
#define pin_potenza A0

WidgetRTC rtc;
BlynkTimer timer;
WidgetLED led_boiler(V3);
SHT3X sht30(0x45);

void setup()
{
 
 pinMode(pinout_d5, OUTPUT);
 pinMode(pin_potenza, INPUT);
  
  // Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  rtc.begin();

  timer.setInterval(1000L, clockDisplay); //invia orario
  timer.setInterval(1000L, statoBoiler); //invia se acceso o spento
  timer.setInterval(1000L, inviaMisuraPotenza); //invia misura assorbimento e potenza
  timer.setInterval(1000L, inviaMisuraTempHum); //invia misura temperatura e umidità
}

// recupera tutti i valori dal server nel caso in cui WeMas si spenga o resetti
BLYNK_CONNECTED() {
Blynk.syncAll();
}

BLYNK_WRITE(V1) // Button Widget writes to Virtual Pin V1 
{
  boolean valore = param.asInt();
  if(valore == 1) {    
  digitalWrite(pinout_d5, HIGH);
  }
  else {    
  digitalWrite(pinout_d5, LOW);
  }
}

BLYNK_WRITE(V2) // Widget timer writes to Virtual Pin V2 
{
  boolean valore = param.asInt();
  if(valore == 1) {    
  digitalWrite(pinout_d5, HIGH);
  }
  else {    
  digitalWrite(pinout_d5, LOW);
  }
}

// Digital clock display of the time
void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute(); // + ":" + second();
  // String currentDate = String(day()) + " " + month(); // + " " + year();
  Blynk.virtualWrite(V50, currentTime);
  // Blynk.virtualWrite(V51, currentDate);
}

void statoBoiler() //leggo lo stato fisico del pin D1
{
  int state = digitalRead(D5);
  if(state == 1) {
  Blynk.setProperty(V3, "color", "#64C800");
  led_boiler.on();
  }
  else {    
  Blynk.setProperty(V3, "color", "#FF0000");
  led_boiler.on();
}
}

 void inviaMisuraPotenza()  
{  

 // misuro la potenza in ingresso =================
  // int lettura_analog = 0;
  float ampere = 0;
  for (byte i = 0; i < 5; i++) { //Esegue l'istruzione successiva 5 volte
  ampere += ((0.0322 * analogRead(pin_potenza) - 23.7) );
  // lettura_analog += analogRead(pin_potenza);    
  }
  ampere /= 5; //Calcola la media dei valori letti
  // Serial.println(ampere);
  // lettura_analog /= 5;
  // Serial.println(lettura_analog);
  // ===================================================

  float potenza = ampere*220;
  Blynk.virtualWrite(6, potenza);
  Blynk.virtualWrite(7, potenza);
  Blynk.virtualWrite(5, ampere); // invia al pin virtuale 5 il valore della potenza  
  }

   void inviaMisuraTempHum()  
{ 
    if(sht30.get()==0){
   //  Serial.print("Temperature in Celsius : ");
   //  Serial.println(sht30.cTemp);
    Blynk.virtualWrite(10, sht30.cTemp);
    // Serial.print("Temperature in Fahrenheit : ");
    // Serial.println(sht30.fTemp);
    // Serial.print("Relative Humidity : ");
    // Serial.println(sht30.humidity);
    Blynk.virtualWrite(12, sht30.humidity);
    // Serial.println();
  }
  else
  {
    // Serial.println("Error!");
  }
}

void loop()
{
  Blynk.run();
  timer.run(); // esegue timer 
}

You’re trying to do 4 things every second.
This includes updating a time display in the app that currently only shows hours and minutes.

It’s possible that while your Wemos is missing the Blynk heartbeat while these processes are being executed and therefore the connection is being dropped.

Have a think about how often you really need to run these routines then adjust the timers accordingly. Try to avoid having all if the timers set to the same value, to avoid all of the processes coinciding.

There are a number of other threads about disconnection issues, which most people thing are probably caused by the version of the ESP8266 core that’s being used and the iwIP settings that are being chosen.
If my suggestions don’t help then take a look at those other threads.

Pete.

2 Likes

Thank you so much @PeteKnight I’m going to modify the code according to your suggests. I’ll back to update.

The problem has been solved changing interval times. No more loss connection occurred :slight_smile:
Thanks!

1 Like

You’re welcome.
I’ve changed the status to Solved.

Pete.

1 Like