Ok, thanks for the link, I might need to restart the project. Just curious why the current solution is not working. I am not sure it’s the shield that is the problem (not saying it isn’t). I added debug and ran with two different values of heartbeat, 45 seconds (default) and 10 seconds. Device connects properly to server. Then it sends a heartbeat at the right time, gets the response in 100-150 ms. This is repeated twice, the third heartbeat signal is not answered by server and timeout will come in a few seconds defined by the blynk timeout set to 3 seconds. Regardless of heartbeat interval it is always the third heartbeat that is not answered. In theory, the third heartbeat signal could always disappear on the way to server but that’s extremely unlikely. Also, reconnection after timeout is always successful, meaning that server is alive and able to send data to device.
When adding a BlynkTimer and pushing data to server it gets even worse, reconnection is triggered after 50 seconds. It seems no heartbeat signals are sent in this situation, probably since the virtual writes are used instead. Before reconnection, this message shows up in debug:
20:23:50.092 → [54633] Sent 5/20
20:23:50.092 → [54656] Connecting to blynk.cloud:80
I don’t know what that is.
@vshymanskyy, do you have any idea what could be the problem?
NOTE: I use Blynk default sketches and quite basic scenarios. I did have my application working but then I think there might have been changes on server side.
Pasted logs below. After the logs, the code for the second case when data is pushed.
23:00:26.557 → BLYNK_HEARTBEAT is: 10
23:00:26.589 → BLYNK_TIMEOUT_MS is: 3000
23:00:26.624 → [1999] Getting IP…
23:00:28.250 → [3697] IP:192.168.0.24
23:00:28.285 → [3698]
23:00:28.285 → ___ __ __
23:00:28.320 → / _ )/ /_ _____ / /__
23:00:28.355 → / _ / / // / _ / '/
23:00:28.390 → ///_, /////_
23:00:28.390 → // v1.1.0 on Arduino Uno
23:00:28.426 →
23:00:28.426 → #StandWithUkraine https://bit.ly/swua
23:00:28.494 →
23:00:28.494 →
23:00:28.494 → [3863] Connecting to blynk.cloud:80
23:00:28.767 → [4210] <[1D|00|01|00]
23:00:28.800 → [4211] <n1FOQhcYoxKypVJdzpbC3G3nZoT_Mb-T
23:00:28.833 → [4259] >[00|00|01|00|C8]
23:00:28.867 → [4260] Ready (ping: 48ms).
23:00:28.901 → [4269] Free RAM: 924
23:00:28.936 → [4327] <[11|00|02|00|8B]
23:00:28.936 → [4327] <ver[00]1.1.0[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]W5100[00]fw-type[00]TMPLixABkY67[00]build[00]Jul 18 2022 23:00:12[00]
23:00:29.140 → [4504] <tmpl[00]TMPLixABkY67[00]
23:00:29.173 → [4579] >[00|00|02|00|C8]
23:00:39.119 → [14540] <[06|00|03|00|00] <<<<<< First heartbeat
23:00:39.256 → [14709] >[00|00|03|00|C8]
23:00:49.117 → [24541] <[06|00|04|00|00] <<<<<< Second heartbeat
23:00:49.254 → [24704] >[00|00|04|00|C8]
23:00:59.125 → [34543] <[06|00|05|00|00] <<<<<< Third heartbeat (no answer)
23:01:02.096 → [37544] <[06|00|06|00|00]
23:01:05.117 → [40545] <[06|00|07|00|00]
//-------------------------------------------------------------------------
23:01:48.676 → BLYNK_HEARTBEAT is: 45
23:01:48.676 → BLYNK_TIMEOUT_MS is: 3000
23:01:48.709 → [1999] Getting IP…
23:01:50.368 → [3697] IP:192.168.0.24
23:01:50.401 → [3698]
23:01:50.401 → ___ __ __
23:01:50.434 → / _ )/ / _____ / /_
23:01:50.434 → / _ / / // / _ / '/
23:01:50.470 → ///_, /////_
23:01:50.503 → /__/ v1.1.0 on Arduino Uno
23:01:50.537 →
23:01:50.537 → #StandWithUkraine https://bit.ly/swua
23:01:50.604 →
23:01:50.604 →
23:01:50.604 → [3863] Connecting to blynk.cloud:80
23:01:50.942 → [4262] <[1D|00|01|00]
23:01:50.942 → [4263] <n1FOQhcYoxKypVJdzpbC3G3nZoT_Mb-T
23:01:51.010 → [4312] >[00|00|01|00|C8]
23:01:51.010 → [4312] Ready (ping: 48ms).
23:01:51.043 → [4321] Free RAM: 924
23:01:51.077 → [4379] <[11|00|02|00|8B]
23:01:51.112 → [4380] <ver[00]1.1.0[00]h-beat[00]45[00]buff-in[00]256[00]dev[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]W5100[00]fw-type[00]TMPLixABkY67[00]build[00]Jul 18 2022 23:01:34[00]
23:01:51.281 → [4556] <tmpl[00]TMPLixABkY67[00]
23:01:51.314 → [4634] >[00|00|02|00|C8]
23:02:36.275 → [49592] <[06|00|03|00|00] <<<<<< First heartbeat
23:02:36.414 → [49755] >[00|00|03|00|C8]
23:03:21.277 → [94593] <[06|00|04|00|00] <<<<<< Second heartbeat
23:03:21.448 → [94772] >[00|00|04|00|C8]
23:04:06.259 → [139594] <[06|00|05|00|00] <<<<<< Third heartbeat
23:04:09.257 → [142595] <[06|00|06|00|00]
23:04:12.270 → [145596] <[06|00|07|00|00]
23:04:15.274 → [148597] <[06|00|08|00|00]
23:04:15.442 → [148774] Heartbeat timeout: 148774, 94773, 148597
23:04:20.288 → [153598] Connecting to blynk.cloud:80
23:04:20.388 → [153729] <[1D|00|01|00]
23:04:20.421 → [153730] <n1FOQhcYoxKypVJdzpbC3G3nZoT_Mb-T
23:04:20.488 → [153778] >[00|00|01|00|C8] <<<<<<< Reconnection successful
23:04:20.521 → [153779] Ready (ping: 45ms).
23:04:20.521 → [153795] Free RAM: 924
23:04:20.555 → [153846] <[11|00|02|00|8B]
23:04:20.590 → [153849] <ver[00]1.1.0[00]h-beat[00]45[00]buff-in[00]256[00]dev[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]W5100[00]fw-type[00]TMPLixABkY67[00]build[00]Jul 18 2022 23:01:34[00]
23:04:20.791 → [154037] <tmpl[00]TMPLixABkY67[00]
23:04:20.826 → [154121] >[00|00|02|00|C8]
23:05:05.751 → [199075] <[06|00|03|00|00]
23:05:05.818 → [199131] >[00|00|03|00|C8]
23:05:50.755 → [244077] <[06|00|04|00|00]
23:05:50.958 → [244260] >[00|00|04|00|C8]
23:06:35.769 → [289078] <[06|00|05|00|00]
23:06:38.763 → [292079] <[06|00|06|00|00]
23:06:41.781 → [295080] <[06|00|07|00|00]
23:06:44.774 → [298081] <[06|00|08|00|00]
23:06:44.941 → [298262] Heartbeat timeout: 298262, 244261, 298081
23:06:49.773 → [303082] Connecting to blynk.cloud:80
23:06:49.907 → [303211] <[1D|00|01|00]
23:06:49.940 → [303212] <n1FOQhcYoxKypVJdzpbC3G3nZoT_Mb-T
23:06:49.973 → [303264] >[00|00|01|00|C8]
23:06:50.007 → [303264] Ready (ping: 47ms).
23:06:50.042 → [303278] Free RAM: 924
23:06:50.042 → [303331] <[11|00|02|00|8B]
´´´
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how value can be pushed from Arduino to
the Blynk App.
NOTE:
BlynkTimer provides SimpleTimer functionality:
http://playground.arduino.cc/Code/SimpleTimer
App project setup:
Value Display widget attached to Virtual Pin V5
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID "TMPLixABkY67"
#define BLYNK_DEVICE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "n1FOQhcYoxKypVJdzpbC3G3nZoT_Mb-T"
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
BlynkTimer timer;
// Push temperatures to server
void myTimerEvent()
{
// Measure
Serial.println("Temperatures: ");
double t1 = calcTemperature(analogRead(0));
Serial.println(t1);
double t2 = calcTemperature(analogRead(1));
Serial.println(t2);
double t3 = calcTemperature(analogRead(2));
Serial.println(t3);
// Send temperatures to server
Blynk.virtualWrite(V1,t1);
Blynk.virtualWrite(V2,t2);
Blynk.virtualWrite(V3,t3);
}
// If V0 changed in app
BLYNK_WRITE(V0)
{
int currentLevel = param.asInt();
Serial.print("Received value and sent back to server: ");
Serial.println(currentLevel);
Blynk.virtualWrite(V4, currentLevel);
}
// Sync server value
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
}
void setup()
{
// Deselect SD card
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
// Debug console
Serial.begin(9600);
Ethernet.init(10);
delay(2000);
Blynk.begin(auth);
// Setup a function to be called every tenth second
timer.setInterval(10000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
// Value to temperature
double calcTemperature(int reading)
{
// Medelvärde
//int reading = (reading1+reading2+reading3)/3;
double Temp;
Temp = log(10000.0 * ((1024.0 / reading - 1)));
Temp = 1 /(0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp)) * Temp);
Temp = Temp - 273.15; // convert from Kelvin to Celsius
return Temp;
}
´´´
Log for above program
20:22:57.360 → [1999] Getting IP…
20:22:59.059 → [3689] IP:192.168.0.24
20:22:59.092 → [3690]
20:22:59.092 → ___ __ __
20:22:59.126 → / _ )/ /_ _____ / /__
20:22:59.160 → / _ / / // / _ / '/
20:22:59.195 → ///_, /////_
20:22:59.195 → /__/ v1.1.0 on Arduino Uno
20:22:59.228 →
20:22:59.262 → #StandWithUkraine https://bit.ly/swua
20:22:59.296 →
20:22:59.296 →
20:22:59.296 → [3855] Connecting to blynk.cloud:80
20:22:59.567 → [4199] <[1D|00|01|00]
20:22:59.601 → [4200] <n1FOQhcYoxKypVJdzpbC3G3nZoT_Mb-T
20:22:59.634 → [4251] >[00|00|01|00|C8]
20:22:59.668 → [4252] Ready (ping: 51ms).
20:22:59.702 → [4257] Free RAM: 896
20:22:59.735 → [4319] <[11|00|02|00|8B]
20:22:59.735 → [4320] <ver[00]1.1.0[00]h-beat[00]45[00]buff-in[00]256[00]dev[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]W5100[00]fw-type[00]TMPLixABkY67[00]build[00]Jul 19 2022 20:22:41[00]
20:22:59.938 → [4494] <tmpl[00]TMPLixABkY67[00]
20:22:59.971 → [4588] >[00|00|02|00|C8]
20:23:00.006 → [4595] <[10|00|03|00|04]
20:23:00.041 → [4595] <vr[00]0
20:23:00.041 → [4652] >[14|00|03|00|06]
20:23:00.075 → [4653] >vw[00]0[00]3
20:23:00.075 → Received value and sent back to server: 3
20:23:00.145 → [4720] <[14|00|03|00|06]
20:23:00.181 → [4722] <vw[00]4[00]3
20:23:09.964 → Temperatures:
20:23:09.999 → 25.80
20:23:09.999 → 24.91
20:23:09.999 → 26.07
20:23:09.999 → [14602] <[14|00|04|00|0F]
20:23:10.032 → [14603] <vw[00]1[00]25.8030700
20:23:10.065 → [14698] <[14|00|05|00|0F]
20:23:10.100 → [14698] <vw[00]2[00]24.9106450
20:23:10.133 → [14766] <[14|00|06|00|0F]
20:23:10.167 → [14766] <vw[00]3[00]26.0718080
…
…
20:23:49.991 → Temperatures:
20:23:49.991 → 25.80
20:23:49.991 → 24.91
20:23:50.024 → 26.07
20:23:50.024 → [54602] <[14|00|11|00|0F]
20:23:50.058 → [54603] <vw[00]1[00]25.8030700
20:23:50.092 → [54633] Sent 5/20 <<<<<<< What is this?
20:23:50.092 → [54656] Connecting to blynk.cloud:80
20:23:50.394 → [55003] <[1D|00|01|00]
20:23:50.394 → [55004] <n1FOQhcYoxKypVJdzpbC3G3nZoT_Mb-T
20:23:50.462 → [55057] >[00|00|01|00|C8]
20:23:50.495 → [55057] Ready (ping: 51ms).
20:23:50.495 → [55065] Free RAM: 896
20:23:50.528 → [55124] <[11|00|02|00|8B]
20:23:50.562 → [55126] <ver[00]1.1.0[00]h-beat[00]45[00]buff-in[00]256[00]dev[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]W5100[00]fw-type[00]TMPLixABkY67[00]build[00]Jul 19 2022 20:22:41[00]