Connection to Blynk server does not work

Ok, that doesn’t sound promising. Actually, my Arduino application will be placed in a house in the countryside, controlled remotely via Blynk. Since I only have a mobile broadband router there I thought connecting Arduino via Ethernet with cable to the router would be the best alternative. But there is actually no reason why I cannot use Wifi instead. Do you think that would be better?

Thing is, I am worried that I have done some minor mistake with code or libraries. After you helped me to get Ethernet shield 2 to work I used it several days with no issues. Then, suddenly it stopped working. Strange. I wonder if problem is on my side, probably that is the case.

You think that someone from Blynk side can help?

//Björn

Yes.
But I’d also suggest switching to a hardware device that has native WiFi support, rather than trying to add WiFi support to the Uno via an ESP-01 device.
I’d go for a NodeMCU or ESP32 (but not one of the Arduino MKR devices), depending on how many useable pins you need.

I guess it is possible that your ISP is blocking port 80, or blocking the Blynk protocol. You could try switching to an SSL connection, but you’d be far better doing that with different hardware.

Pete.

Ok, Thames. Problem is nodeMCU seems to have only 1 ADC while I need 3 :slightly_frowning_face:.

So use an ESP32, which has 8 ADCs that can be used at the same time as WiFi.

Pete.

Ok, is it more complicated code-wise than programming Arduino? I see that it runs on 3.3V, my electronics are adapted to 5V. A bit unconvinient to redesign that. Just wish Blynk would work via Ethernet instead, but I guess I need to realize that it will not.

//Björn

No, it’s basically the same, and some things, such as WiFi connection are actually easier than an Uno plus ESP-01.

The ESP32 has an onboard 5v to 3.3v regulator, to allow it to be powered via USB.
The pins use 3.3v logic levels, but are 5v tolerant, and most sensors etc are 3.3-5v tolerant too.
If you do have an6 issues then you can use a logic level shifter, but i’ve only ever had one situation where I’ve had to do that.

This topic is about ESP8266 boards, but many of the points raised relate to ESP32s too…

As far as Ethernet boards not working consistently with Blynk, I think it’s more a case of Ethernet boards not working consistently - full stop!

Pete.

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]

Hi,
I did some investigation and I cannot see that it is the shield that is the problem, see answer below. I might be wrong but the scenarios below do not indicate communication problems. I tested the very basic scenarios using Blynk and communication between device and Blynk server is extremely unstable.

//Björn

Where?

Pete.

Oh, sorry, it is above this post. Br Björn

Do you think that is this we’re the case for everyone then Blynk would have any customers?

It may be an issue with your ISP, router, Ethernet cable, Ethernet shield or board, or power supply.

Pete.

Hi,
Of course it can be but it is not easy to say from the traces I get. But you’re right, on router connected to fixed IP it works. Does the ISP change my IP address? Yes, for mobile broadband it does and I might need to use DDNS, but it seems a bit strange that the ISP would change IP so often, it is probably something else causing this issue. Wouldn’t such a problem cause total failure?

My application is depending on usage of mobile broadband router.

Br Björn

I didn’t suggest that having a dynamic public IP address was part of the cause, and there is certainly no value in using a DDNS service, as only works in the reverse direction.

Pete.

I know you didn’t. As I understood it, Blynk will initiate communication from device to server, making double NAT problem not applicable. But there seems to be some other problem here. I know that my ISP uses double NAT and that has prevented me from using a web page to control my application.

Br Björn

Double NAT and DDNS are only an issue if you are hosting a server inside your network and trying to access it from outside your network.

The Blynk cloud server is outside your network and you are trying to access it from inside your network, so DDNS and double NAT don’t come into the equation.
You’re looking for problems where none exist, as I said…

Pete.

I know that, but I am trying to understand where the problem is.

And I’ve said that it I were in your situation I would use a device that had native WiFi connectivity, to eliminate some of these potential problem areas.
If the problem persists with a NodeMCU or ESP32 then you have a better idea of where the problem may lie.

However, you seem reluctant to want to do that, and instead you’re focusing on areas that won’t have anything to do with your ussue.

Pete.

Ok, fair enough.

//Björn

Now I ordered an ESP32: https://www.electrokit.com/produkt/sparkfun-esp32-thing/
I found a way to patch my other hardware without to much impact so that should be fine.

I will hook ESP32 up and use Arduino IDE to handle it, then try some example Blynk sketches and see what happens.

Br Björn

That’s pricey!

Pete.