Wemos D1, random disconnection

• Hardware model + WEMOS D1
• Blynk local server
• Blynk Library version = latest

I made a simple thermometer with the DS18B20 sensor but I have a disconnection problem that happens every 5-8 minutes and that is also reported on the app. Reconnection is virtually instantaneous. The sketch works perfectly but has this flaw. These disconnections do not damage the functionality of the project but I would like to make it more stable. Can you tell me if there’s something wrong? Sorry for my “limping” English


void setup(){
  Serial.begin(9600);
  sensors.begin(); //Avvia la libreria
  pinMode(wifiok, OUTPUT);  //uscita led avvenuta connessione
  digitalWrite(wifiok, off);
  WiFi.config(staticIP, gateway, subnet);
  #ifdef RA
    Blynk.begin(AUTH, SSID, PASSW, IPAddress(192,168,1,44), 8080);  //RETI CASA - SERVER BLYNK locale(Raspi)
  #endif
  #ifdef CL
	 Blynk.begin(AUTH, SSID, PASSW, SERVER, PORT); //RETE LAVORO - SERVER BLYNK CLOUD
  #endif
  Blynk_timer.setInterval(5000L, lettura);  //chiama al funzione 'void lettura()' ogni 5000ms

}

void loop(){
  Blynk.run();
  Blynk_timer.run();  //avvia il timer Blynk
  if(Blynk.connected()){
    digitalWrite(wifiok, on); //accende il led a bordo per avvenuta connessione WIFI   
  }else{
    digitalWrite(wifiok, off);  //spegne il led a bordo per avvenuta disconnessione WIFI
    Blynk.connect();
  }
  sensors.requestTemperatures(); //Invia comando per rilevare temperatura a tutti i dispositivi sul bus
  Temp = sensors.getTempCByIndex(0);
}

/*-----( Dichiara funzioni scritte da utente )-----*/

BLYNK_CONNECTED(){  //necessario per aggiornamento stati (Arduino >>> App)
  Blynk.syncAll();
}

void lettura(){
  // Non più di 10 letture a secondo!
  Blynk.virtualWrite(V0,Temp);  //usare in app il settaggio PUSH
}

You are trying to read your sensors hundreds/thousands of times a second in your void loop()… use a timed function instead.

There is no reason to read a temperature reading more then every few minutes for most cases anyhow.

Wow, I did not think about it …
could it be better this way?


void loop(){
  Blynk.run();
  Blynk_timer.run();  //avvia il timer Blynk
  if(Blynk.connected()){
    digitalWrite(wifiok, on); //accende il led a bordo per avvenuta connessione WIFI   
  }else{
    digitalWrite(wifiok, off);  //spegne il led a bordo per avvenuta disconnessione WIFI
    Blynk.connect();
  }
}

/*-----( Dichiara funzioni scritte da utente )-----*/

BLYNK_CONNECTED(){  //necessario per aggiornamento stati (Arduino >>> App)
  Blynk.syncAll();
}

void lettura(){
  // Non più di 10 letture a secondo!
  sensors.requestTemperatures(); //Invia comando per rilevare temperatura a tutti i dispositivi sul bus
  Temp = sensors.getTempCByIndex(0);
  Blynk.virtualWrite(V0,Temp);  //usare in app il settaggio PUSH
}


Better… but outside of testing, even 5 seconds is unnecessarily too fast. I typically run mine every 2-10 minutes

1 Like

yes, it’s true but in this case I need to visualize quite rapid temperature variations. I will test and I hope there are no more disconnections.

As long as that sensor can handle that speed, then fine I guess. I have never bothered to check it’s frequency stats.

BTW, why run Blynk.syncAll()? You are not really running many virtual pins that I can see.

Better to just sync specifically needed pins, as a syncAll() calls any and all Blynk functions at the exact same time… that in itself can sometimes cause disconnections right after connecting.

Ok, thanks for the further information.
Blynk.syncAll () … I did not know that this call could potentially create problems. For now I do not really need it so I will delete it and I will study in depth the use of Blynk.syncAll () and possible variants with individual virtual pins