Hardware:
Board: ESP32 Dev Module
Core Installation/update date: Mon Jan 7
Blynk library: 0.5.4
Blynk server: local
IDE name: Arduino IDE 1.8.6
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Mac OSX
Description:
Hello, I got the strange behaviour of the ESP32 millis() overflows and the blynk Heartbeat timeout
. For now ESP32 has only 4294967 milliseconds (about 71 minutes) from the start before millis() overflow happens. My app perfectly works during that 4294967 milliseconds. But exactly when owerflow happens, blynk shows the Heartbeat timeout
message. And sometimes after that it breaks the loop. The sketch bellow is the last version of my attempts to reach a stable work. And this last version gave me hours of stable work, but it still not predicable. Sketch can hang after 7 hours. I meant code in loop just stops to exicute. Even timer doesn’t runs enymore. But blynk app is working itself. Hadrware is online, and I can send requests to it and get responses. In loogs I see only ping responses right after the Heartbeat timeout
event happend.
I tried to use third party timers, but it didn’t help. I tried to create a three separate timers and divide sync load betwean them. It doesn’t help. So, without blynk library my code is very stable. For today it gave me 116 hours uptime. But with blynk it very hard to reach at last one day of stable work. The sketch below shows pretty much all that I’m doing.
Does someone else get this behaviour?
Sketch:
#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial
#define BLYNK_NO_BUILTIN // Disable built-in analog & digital pin operations
#define BLYNK_NO_FLOAT // Disable float operations
#define BLYNK_MSG_LIMIT 50
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
const char *SSID = "***";
const char *PSWD = "***";
char blynkAuth[] = "***";
char blynkDomain[] = "192.168.1.4";
const uint16_t blynkPort = 8080;
const unsigned long blynkConnectAttemptTime = 5L * 1000L; // try to connect to blynk server during only 5 seconds
BlynkTimer timer;
const unsigned long uptimePrintInterval = 1L * 1000L;
// blynk sync
void blynkSyncStrings() {
Blynk.virtualWrite(V1, "1");
Blynk.virtualWrite(V2, "2");
Blynk.virtualWrite(V3, "3");
Blynk.virtualWrite(V4, "4");
Blynk.virtualWrite(V5, "5");
Blynk.virtualWrite(V6, "6");
Blynk.virtualWrite(V7, "7");
Blynk.virtualWrite(V8, "8");
Blynk.virtualWrite(V9, "9");
}
void blynkSyncNumbers1() {
Blynk.virtualWrite(V10, 1);
Blynk.virtualWrite(V11, 1);
Blynk.virtualWrite(V12, 1);
Blynk.virtualWrite(V13, 1);
Blynk.virtualWrite(V14, 1);
Blynk.virtualWrite(V15, 1);
Blynk.virtualWrite(V16, 1);
Blynk.virtualWrite(V17, 1);
Blynk.virtualWrite(V18, 1);
}
void blynkSyncNumbers2() {
Blynk.virtualWrite(V19, 1);
Blynk.virtualWrite(V20, 1);
Blynk.virtualWrite(V21, 1);
Blynk.virtualWrite(V22, 1);
Blynk.virtualWrite(V23, 1);
Blynk.virtualWrite(V24, 1);
Blynk.virtualWrite(V25, 1);
Blynk.virtualWrite(V26, 1);
}
//
void blynkConnect() {
if (WiFi.isConnected() && !Blynk.connected()) {
unsigned long startConnecting = millis();
while (!Blynk.connected()) {
Blynk.connect();
if (millis() > startConnecting + blynkConnectAttemptTime) {
Serial.println("Unable to connect to Blynk server.\n");
break;
}
}
}
}
void setup() {
Serial.begin(115200);
while (!Serial) { ;
}
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PSWD);
for (int loops = 10; loops > 0; loops--) {
if (WiFi.isConnected()) {
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
break;
} else {
Serial.println(loops);
delay(1000);
}
}
if (!WiFi.isConnected()) {
Serial.println("WiFi connect failed");
}
Blynk.config(blynkAuth, blynkDomain, blynkPort);
blynkConnect();
timer.setInterval(30L * 1000L, blynkConnect);
timer.setInterval(3000L, blynkSyncStrings);
timer.setInterval(4300L, blynkSyncNumbers1);
timer.setInterval(5400L, blynkSyncNumbers2);
}
void loop() {
if (Blynk.connected()) {
Blynk.run();
}
timer.run();
uint32_t now = millis();
static uint32_t lastUpdate = 0;
static uint32_t overFlowCounter = 0;
if (now < lastUpdate) { // overflow
overFlowCounter++;
lastUpdate = now;
}
if (now - lastUpdate > uptimePrintInterval){
lastUpdate = now;
Serial.print("uptime = ");
Serial.println((overFlowCounter * 4294968) + now);
}
}
Logs:
...
uptime = 8587666
uptime = 8588667
[4293745] <[06]p[0F|00|00]
[4293769] >[00]p[0F|00|C8]
[4293895] <[14]p[10|00|06]vw[00]1[00]1
[4293919] <[14]p[11|00|06]vw[00]2[00]2
[4293941] <[14]p[12|00|06]vw[00]3[00]3
[4293962] <[14]p[13|00|06]vw[00]4[00]4
[4293984] <[14]p[14|00|06]vw[00]5[00]5
[4294006] <[14]p[15|00|06]vw[00]6[00]6
[4294028] <[14]p[16|00|06]vw[00]7[00]7
[4294050] <[14]p[17|00|06]vw[00]8[00]8
[4294072] <[14]p[18|00|06]vw[00]9[00]9
[4294495] <[14]p[19|00|07]vw[00]19[00]1
[4294519] <[14]p[1A|00|07]vw[00]20[00]1
[4294541] <[14]p[1B|00|07]vw[00]21[00]1
[4294564] <[14]p[1C|00|07]vw[00]22[00]1
[4294586] <[14]p[1D|00|07]vw[00]23[00]1
[4294608] <[14]p[1E|00|07]vw[00]24[00]1
[4294630] <[14]p[1F|00|07]vw[00]25[00]1
[4294652] <[14]p [00|07]vw[00]26[00]1
uptime = 8589668
[0] Heartbeat timeout: 0, 4293769, 4293745
[3] Connecting to 192.168.1.4:8080
[8] <[02|00|01|00] 4c31987252054e4f83f538cb483decd3
[24] >[00|00|01|00|C8]
[24] Ready (ping: 11ms).
[45] <[11|00|02|00]Fver[00]0.5.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]ESP32[00]build[00]Jan 15 2019 18:23:28[00]
[49] >[00|00|02|00|C8]
[10068] <[06|00|04|00|00]
[10083] >[00|00|04|00|C8]
[20072] <[06|00|05|00|00]
[20082] >[00|00|05|00|C8]
[30076] <[06|00|06|00|00]
[30096] >[00|00|06|00|C8]
[40080] <[06|00|07|00|00]
[40089] >[00|00|07|00|C8]
[50084] <[06|00|08|00|00]
[50091] >[00|00|08|00|C8]
...