ESP32Ping
ESP32Ping copied to clipboard
Last ping shouldn't wait 1s
ping_start() forces to wait 1s after each ping. I suggest to don't wait in last cycle and return immediately.
I find it like a good proposal, but I think it should be tested before. Also an enhancement could be to add the time interval as an option to PingClass::ping (I see that this https://github.com/marian-craciunescu/ESP32Ping/blob/e42412bfe42367b0c5ce8e2fc045dc6bd6341b77/ESP32Ping.cpp#L39 is useless )
I updated my local sources like below and it works perfectly for me.
--- ping.old.cpp 2020-06-05 09:46:00.000000000 +0200
+++ ping.cpp 2021-01-07 18:26:01.457435408 +0100
@@ -322,7 +322,9 @@
if (ping_send(s, &ping_target, size) == ERR_OK) {
ping_recv(s);
}
- delay( interval*1000L);
+ if(ping_seq_num < count){
+ delay( interval*1000L);
+ }
}
closesocket(s);
please raise a pull request
Only if you have some other way to wait. If you don't wait, you might not get the answer and declare it bad.
It's not true. Current behavior is wait 1s between pings and wait 1s after last ping too. For example: If i only want to check, if host is alive and have code like this:
bool hostAlive = false;
for(int i=0;i<5;i++){
if(ping(host,1)){
hostAlive = true;
break;
} else {
delay(1000);
}
}
With current code, each ping() takes at least 1s due to wait after last ping, which is not needed. With my simple change, last wait is removed and ping returns immediately after succes or failure. Success check than takes few ms instead of 1s.