Blynk and Library ICMPPing.h - Connection Loss

I’ve been a Blynk user for some time but my mistake might be something easy for the more experienced.

I have a Blynk application working perfectly. I recently decided to put my Arduino Uno to give a PING on a certain IP of the network, the PING happens, but at the moment of PING the Blynk on my Smartphone gets disconnected and connecting. I put the PING every 30 seconds, every time the PING is counted it disconnects and reconnects, even the PING lasts only 2ms.

I already put it inside the SimpleTimer function, but it stays the same.

is there a way to increase the time the blink and arduino application stays in soncrony?

The only PING time is only 2ms, and it already appears disconnected in my BLYNK application.

Hello. Could you please show the code with ping?

The code is great, I put only the part of the PING and the button of the Application that serves to enable PING. Without PING enable, operate without disconnecting, from the moment PING starts, it starts to connect and disconnect. Both on the serial monitor and in the application.

If the problem is the time Arduino gets busy with PING, I wonder if there is any way to increase this timeout.

All of my app displays and widgets are set to read more than 5 seconds. So I do not think that’s it.

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <EEPROM.h>
#include <ICMPPing.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

#define rele 3
#define saida1 4
#define saida2 5
#define saida3 6
#define saida4 7

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEB};
IPAddress ip(192, 168, 2, 115);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dnServer(8, 8, 8, 8);
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";

IPAddress pingAddr1(192,168,2,120); SOCKET pingSocket1 = 0; ICMPPing ping1(pingSocket1, (uint16_t)random(0, 255));
int habilita_ping1 = 0; int conta_ping1 = 0;

BLYNK_WRITE(V25) { int buttonState = param.asInt(); 
if (buttonState == 1) {habilita_ping1 = 1;}  if (buttonState == 0) {habilita_ping1 = 0;} Serial.println(habilita_ping1); }

SimpleTimer timer;

void pingar()
if (habilita_ping1 == 1){ICMPEchoReply echoReply = ping1(pingAddr1, 4); 
	if (echoReply.status == SUCCESS){conta_ping1=0;Serial.println("Ping");} 
	else{conta_ping1++; Serial.print("Nao Pingou "); Serial.println(conta_ping1);} 
		if(conta_ping1 > 5){ Serial.println("reset");  digitalWrite(saida1,HIGH); delay(5000); conta_ping1=0; digitalWrite(saida1,LOW);}}

void setup()
  analogReference(DEFAULT); Serial.begin(9600); 
Blynk.begin(auth, "", 8442, ip, dnServer, gateway, subnet, mac);
  timer.setInterval(10000L, pingar);

void loop()

I’ve already looked inside the BlynkConfig.h file and did not see an option to look like something about increasing the communication time between the Arduino and the Blynk server.

Or maybe it’s something else. is what is the fact that the code pinging a local IP does this make the Arduino disconnect from the Blynk server?

Unfortunately you missed looking into the Welcome Topic… Can you do so, then edit your post with properly formatted code,

Then spend some time reading the Documentation and Help Center files to see why using a 7 second delay is a bad thing to do (even more use of differing timers can eliminate such need). There could be more issues as well, but I gave up reading through the unformatted code :wink:

Thank You.

The 7 seconds is a reset time. This only happens when PING can not complete a few times. No problem it exists.

The problem is that even with normal PING at 2ms it continues to lose connection.

Any delay or loop that exceeds Blynk’s heartbeat timeout will cause disconnection. You can try to code around it with checks and reconnection code, but it basically comes down to proper time management.

Is not that a way to increase Blynk’s time a little?

Thanks for the links, I had already visited all of them, but I did not get answers.

As for good time management, the rest of my code uses the recommended timers to do the sensor readings, on average it sends the information to the APP every 10 seconds. Not overloading the same way.

Only the ping that varies between 2ms to 4ms, this has no way of decreasing the time.

I wanted to know if there is any way to increase the time that () connects to the server, so it does not see those small millisecond delays.

Not on Cloud Server. Look at a installing a Local Server if you want all the tweeking rights. Be aware it is a more advanced operation.

The library is open source, so you can play around with it all you want, but there is no real documentation for such.

your disconnections for sure not caused by those 2 or 4 millisecond delays. the blynk system can easily handle even several 100 millisecond delays, up to 500 or so.

i feel the problem is somehow related to the ethernet library or some other protocol… probably somehow when you init the ping, it gets disconnected from the blynk server.

i would try the following experiments:

  • even if the ping is only 4 ms, but maybe the WHOLE PINGING PROCEDURE takes much more time, and this causes the disconnections. for example, if i do a ping on my pc from a terminal, i can have 4 ms ping, but the time to execute the whole command takes some seconds. to measure the actual time, put a serial.println(millis()) before and after the pinging function, and see what it gets. if that is more than 500 ms, than there is the cause.

  • try the same code (with the neccessary modifications of course) on a esp8266 board (with the 2.4.0-rc2 esp core). and see if the disconnection occures. if not, than probably the cause is related to the ethernet library internal protocols

Thank you for the tip. I did the test, look at the result:

void pingar()
if (habilita_ping1 == 1){ICMPEchoReply echoReply = ping1(pingAddr1, 4);
		if (echoReply.status == SUCCESS){conta_ping1=0;} 

	if(conta_ping1 >= 2){conta_ping1=0; digitalWrite(saida1,HIGH); delay(5000); digitalWrite(saida1,LOW);}}



Before: 26402
After: 26404

Before: 46387
After: 46389

Before: 66378
After: 66380

Before: 326361
After: 326363

Before: 346409
After: 346412

Before: 366389
After: 366391

Before: 386368
After: 386370

Before: 406942
After: 406945

Before: 426427
After: 426430

Before: 446406
After: 446409

Shows intervals between 2ms and 4ms. So I guess it’s not a matter of time. It must be internal ethernet library protocols. Which should be much harder to solve. :disappointed_relieved:

It seems that someone else has had issues with ICMPing causing disconnects, in this case from their MQTT server:

Nobody responded to that issue, but they can be like that over on the Arduino forum :grinning:
You might be better looking for a different solution, or raising the issue with the author of the ICMPing library.


i see. that is strange…

if you have an esp at hand, you can also

and, by the way, which blynk lib are you using?

Use with the Library 0.5.0

@Gunner when you set heartbeat setting in the sketch or config file, it is automatically adjusted on our public cloud as well!

1 Like

Ah, good to know… what are the ranges that are allowed?

In the BlynkConfig.h file in the “\ libraries \ Blynk \ src \ Blynk” folder, you have the following options.

#ifndef BlynkConfig_h
#define BlynkConfig_h

#include <Blynk/BlynkDetectDevice.h>

 * Change these settings to match your need

#define BLYNK_DEFAULT_PORT       8442

 * Professional settings
// Library version.
#define BLYNK_VERSION        "0.5.0"

// Heartbeat period in seconds.
#define BLYNK_HEARTBEAT      10

// Network timeout in milliseconds.
#define BLYNK_TIMEOUT_MS     2000UL

// Limit the amount of outgoing commands per second.
#define BLYNK_MSG_LIMIT      15

// Limit the incoming command length.

// Limit the outgoing command length.

// Uncomment to disable built-in analog and digital operations.

// Uncomment to disable providing info about device to the server.
//#define BLYNK_NO_INFO

// Uncomment to enable debug prints.
//#define BLYNK_DEBUG

// Uncomment to force-enable 128 virtual pins
//#define BLYNK_USE_128_VPINS

// Uncomment to disable fancy logo

// Uncomment to enable 3D fancy logo

// Uncomment to enable experimental functions.

// Uncomment to disable all float/double usage
//#define BLYNK_NO_FLOAT

// Uncomment to switch to direct-connect mode

// Uncomment to append command body to header (uses more RAM)

// Split whole command into chunks (in bytes)
//#define BLYNK_SEND_CHUNK 64

// Wait after sending each chunk (in milliseconds)


can changing one of them help anything?

I don’t think so. Basically that’s some conflict of the Ping library which apparently kills existing connections, including Blynk connection to the cloud.

I guess I didn’t pay enough attention… here I was thinking of what I call a PING sensor, AKA ultrasonic sensor… not a library for pinging network connections :blush:

Yes, such a thing would override any other network connections while running… otherwise it would not be getting accurate readings… kinda like determining how loud a fan is… in a hurricane :stuck_out_tongue: Which does raise the feasibility of using IoT software for testing Network conditions, due to the contradictory networking needs of each.

@chacalgbi It might be doable, but you would first need to run something like Blynk.disconnect() run your Network PING scan, store the results, restart Blynk’s connection with Blynk.connect() then send those results through to the App for display.


Buddy, your idea of using Blynk.disconnect () and Blynk.connect () worked, the application continues to connect and disconnect, but it is very fast.

Thank you very much!! I’m going to ping and connect and disconnect on the Blynk server once a minute. Is that a problem? Can the Blynk server permanently disconnect me for this?

follow the code below:

void pingar(){ // once per minute
if (habilita_ping1 == 1)
ICMPEchoReply echoReply = ping1(pingAddr1, 4); 
 if (echoReply.status == SUCCESS){conta_ping1=0;} 
  if(conta_ping1 >= 2)
  digitalWrite(saida1,HIGH); ultimo_tempo = millis();