BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk and Library ICMPPing.h - Connection Loss


#1

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.


#2

Hello. Could you please show the code with ping?


#3

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, "blynk-cloud.com", 8442, ip, dnServer, gateway, subnet, mac);
  
  timer.setInterval(10000L, pingar);
}

void loop()
{ 
Blynk.run();
timer.run();
}

#4

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?


#5

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.


#6

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.


#7

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.

http://docs.blynk.cc/#blynk-firmware-connection-management

http://docs.blynk.cc/#troubleshooting

http://docs.blynk.cc/#blynk-firmware-debugging


#8

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 blynk.run () connects to the server, so it does not see those small millisecond delays.


#9

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.


#10

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


#11

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

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

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

Serial.println(millis());

}

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:


#12

It seems that someone else has had issues with ICMPing causing disconnects, in this case from their MQTT server:
http://forum.arduino.cc/index.php?topic=327701.0

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.

Pete.


#13

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?


#14

Use with the Library 0.5.0


#15

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


#16

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


#17

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_DOMAIN     "blynk-cloud.com"
#define BLYNK_DEFAULT_PORT       8442
#define BLYNK_DEFAULT_PORT_SSL   8441

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

// Heartbeat period in seconds.
#ifndef BLYNK_HEARTBEAT
#define BLYNK_HEARTBEAT      10
#endif

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

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

// Limit the incoming command length.
#ifndef BLYNK_MAX_READBYTES
#define BLYNK_MAX_READBYTES  256
#endif

// Limit the outgoing command length.
#ifndef BLYNK_MAX_SENDBYTES
#define BLYNK_MAX_SENDBYTES  128
#endif

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

// 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
//#define BLYNK_NO_FANCY_LOGO

// Uncomment to enable 3D fancy logo
//#define BLYNK_FANCY_LOGO_3D

// Uncomment to enable experimental functions.
//#define BLYNK_EXPERIMENTAL

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

// Uncomment to switch to direct-connect mode
//#define BLYNK_USE_DIRECT_CONNECT


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

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

// Wait after sending each chunk (in milliseconds)
//#define BLYNK_SEND_THROTTLE 10

#endif

can changing one of them help anything?


#18

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.


#19

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.


GPS and BLYNK not working together. Help..!
#20

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)
{
Blynk.disconnect();
ICMPEchoReply echoReply = ping1(pingAddr1, 4); 
 if (echoReply.status == SUCCESS){conta_ping1=0;} 
 else{conta_ping1++;} 
  if(conta_ping1 >= 2)
  {
  digitalWrite(saida1,HIGH); ultimo_tempo = millis();
  }
Blynk.connect();
}
}