NodeMCU v1.0
Hi, friends! I have something strange with working of my device.
It works 24 hours and then reboots every 5 seconds
My code:
void UpTime() {
Blynk.virtualWrite(V0, millis() / 60000); // Send UpTime seconds to App
Serial.print("UpTime: ");
Serial.println(millis() / 60000); // Send UpTime seconds to Serial
//digitalWrite(DeviceLED, !digitalRead(DeviceLED)); // Blink onboard LED
}
void loop()
{
timer.run();
if (Blynk.connected()) { // If connected run as normal
Blynk.run();
} else if (ReCnctFlag == 0) { // If NOT connected and not already trying to reconnect, set timer to try to reconnect in 30 seconds
ReCnctFlag = 1; // Set reconnection Flag
Serial.println("Connection is lost. Reconnect 30 secconds ...");
timer.setTimeout(30000L, []() { // Lambda Reconnection Timer Function
ReCnctFlag = 0; // Reset reconnection Flag
ReCnctCount++; // Increment reconnection Counter
Serial.print("Trying to reconnect #");
Serial.println(ReCnctCount);
Blynk.connect(); // Try to reconnect to the server
}); // END Timer Function
}
if (millis() - lastmillis > 20000){
lastmillis = millis ();
sendSensor_hum();
}
if ( digitalRead(TRIGGER_PIN) == 0 ) {
wifi_configer ();
}
}
Start with looking at what your ESP might be saying happened to cause the reboot… look at the Serial monitor message on reboot.
BTW, if you are using BlynkTimer anyhow, probably best to setup proper timed functions to run your sensor scans. Try to keep unnecessary code and logic out of the void loop()
That is not the whole code, and what is missing may or may not offer other potential hints.
You might want to look at your router setting, in particular DHCP lease times. If that’s set to 24 hours then that may be where the 24 hour thing is coming from.
Also, I’ try to clean-up your void loop, as this can cause Blynk timeouts and disconnections.