Hello every body,
I hope you are all doing well.
Could you help me on solving a problem?
I am testing Blynk on a ESP32-S3 connected to 8 Temperature sensors (DS18B20) to measure 8 aquariums. Five are linked to Blink for software test (v1-v5), and I am prone to install more devices with many sensors as soon as I get the sketch running well with Blynk.
Temperatures are collected every second and the average of 60 seconds are send to Blink, i. e., Blink receives five values every minute. The sketch works perfect locally, showing data on screen and logging in a SD card. Nevertheless, Blynk is very important for remote monitoring.
==> The connection with Blynk occurs perfectly at the start and I can follow values on App or Console, but after a while…minutes or even hours… the device becomes offline, although it continues to collect, show and log data. It also “tries” to send data to Blynk. The reset of the uC solves the issue, but graphs on Blynk app miss the data.
Based on code found in this community I set up a function to monitor the connection and reestablish in case of (Blynk. connected() == false). I use a Blynktimer to check every 20 seconds. ==> NO SUCCESS.
I also change the Heartbeat to 20 seconds. NO SUCCESS
So, I put
#define BLYNK_DEBUG_ALL
… to follow the communication between Device<->Blynk and share here to help on diagnosis.
I hope to find a solution. Thanks in advance!
Traits of the project:
I use FreeRTOS. Blynk.run() and timer.run() are placed within a task pinned to Core1 as follows:
void BlynkLoop (void * pvParameters) {
(void) pvParameters;
Serial.println("Blynk-Loop Task Started");
for(;;) {
if (Blynk.connected()) Blynk.run();
timer.run();
vTaskDelay(1); //feed the watchdog
}
}
There is a function that sends data to Blynk after 60 measuremens:
void SendDataToBlynk(){
debugln("\n -> Start Sending Data to Blynk "); //Serial.println
uint64_t TimeStamp = ((uint64_t)now.unixtime()+10800)*1000; //Time Stamp (milliseconds + 3hours)
Blynk.beginGroup(TimeStamp);
Blynk.virtualWrite(V1, (double)(TempAverage[0]));
Blynk.virtualWrite(V2, (double)(TempAverage[1]));
Blynk.virtualWrite(V3, (double)(TempAverage[2]));
Blynk.virtualWrite(V4, (double)(TempAverage[3]));
Blynk.virtualWrite(V5, (double)(TempAverage[4]));
Blynk.endGroup();
debugln(" -| End Sending Data to Blynk \n");
}
To monitor the connections a Blynk timer was initiated at setup():
connection_timer_ID = timer.setInterval(20000L, Blynk_CheckConnection);
Which calls the the Function void Blynk_CheckConnection () as follows:
void Blynk_CheckConnection(){
if (!(Blynk.connected())) {
if(WiFi.status() != WL_CONNECTED) {
debugln(" WiFi connection was lost!");
WiFi_Disconnect();
WiFi_ConnectAsClient();
Blynk.connect();
} else {
debugln(" Blynk server connection was lost");
Blynk.connect();
}
}
Here is the Serial.print output when connection is ok. One can see the one second value followed 60 second average. I cut part of the printout for simplicity. It is possible to see the device pinging to server, which stops when it appears offline. Blynk.connected() is always true, even when the device is offline.
[3767] Connected to WiFi
[3767] IP: 192.168.1.34
[3767]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.3.2 on ESP32-S3
#StandWithUkraine https://bit.ly/swua
[3768] Connecting to blynk.cloud:80
[4037] <[1D|00|01|00|20]**********
[4182] >[00|00|01|00|C8]
[4183] Ready (ping: 144ms).
[4183] Free RAM: 280608
[4183] Waiting:50
[4234] <[11|00|02|00]}mcu[00]0.0.0[00]fw-type[00]TMPL20ZbxYhJ7[00]build[00]May[20|20]7[20]2024[20]21:40:06[00]blynk[00]1.3.2[00]h-beat[00]20[00]buff-in[00]1024[00]dev[00]ESP32-S3[00]tmpl[00]TMPL20ZbxYhJ7
Blynk Connected!
Blynk Loop Task Started
[6403] >[00|00|02|00|C8]
01 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
02 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
03 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
04 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
05 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
06 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
07 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
...
17 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
18 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
[24239] <[06|00|03|00|00]
[24414] >[00|00|03|00|C8]
19 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
20 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
Blink connected
21 - 29.81 29.69 29.62 30.00 29.50 29.62 29.38 29.69
...
58 - 29.81 29.69 29.62 30.00 29.56 29.69 29.38 29.69
[64246] <[06|00|05|00|00]
[64455] >[00|00|05|00|C8]
59 - 29.81 29.69 29.62 30.00 29.50 29.69 29.38 29.69
60 - 29.81 29.69 29.62 30.00 29.50 29.69 29.38 29.69
Avg 29.81 29.69 29.62 30.00 29.51 29.64 29.37 29.69 (°C) 2024-05-08T12:29:19
-> Start Sending Data to Blynk
[66058] <[15|00|06|00|0F]t[00]1715182159000
[66060] <[14|00|07|00|0F]vw[00]1[00]29.8125000
[66062] Waiting:49
[66112] <[14|00|08|00|0F]vw[00]2[00]29.6875000
[66113] Waiting:50
[66164] <[14|00|09|00|0F]vw[00]3[00]29.6250000
[66165] Waiting:50
[66216] <[14|00|0A|00|0F]vw[00]4[00]30.0000000
[66217] Waiting:50
[66268] <[14|00|0B|00|0F]vw[00]5[00]29.5062504
[66269] <[15|00|0C|00|01]e
-| End Sending Data to Blynk
Blink connected
01 - 29.81 29.69 29.62 30.00 29.50 29.69 29.38 29.69
...
Here is the Serial.print output when devide is offline.
57 - 29.75 29.62 29.56 29.94 29.44 29.56 29.31 29.62
58 - 29.75 29.62 29.56 29.94 29.44 29.56 29.31 29.62
59 - 29.75 29.62 29.56 29.94 29.44 29.56 29.31 29.62
60 - 29.75 29.62 29.56 29.94 29.44 29.56 29.31 29.62
Avg 29.74 29.62 29.54 29.94 29.44 29.56 29.31 29.62 (°C) 2024-05-08T12:20:54
->Start Sending Data to Blynk
[12903088] Cmd skipped:20
[12903088] Cmd skipped:20
[12903088] Cmd skipped:20
[12903088] Cmd skipped:20
[12903089] Cmd skipped:20
-| End Sending Data to Blynk
01 - 29.75 29.62 29.56 29.94 29.44 29.56 29.31 29.62
02 - 29.75 29.62 29.56 29.94 29.44 29.56 29.31 29.62
03 - 29.75 29.62 29.56 29.94 29.44 29.56 29.31 29.62
Blink connected <=== SHOWS CONNECTED BESIDES DEVICE OFFLINE
04 - 29.75 29.62 29.56 29.94 29.50 29.5