I'm using an esp32 to ping a local responder which I can turn on and off.
I'm sending a single ping at 6 second intervals. An amber led is turned on when the ping is initiated, and off when its complete.
While the responder is up all works OK, with short flashes.
However when I turn the responder off, so there is no response to a ping, the amber light sooner or later appears to stay on. The serial monitor shows the program is still running
When the amber light "stays on" (actually its off for very short periods) the ping returns a success despite the responder being off.
Is this a fault in the ESP32 ping library?
in loop()
// do the pings if its time
if (WiFiUp) { //only if WiFi up!
timeNow = millis();
if (timeNow >= (timeWas + (timeInterval * 1000))) {
amb(1); //amber on - showing pinging in progress
// ***************** ping it
//pingOK = Ping.ping(remote_ip, pingNumber); //produces values for pingTime, expectedCount, success, errors
pingOK = Ping.ping("responder.local", pingNumber); //for testing
pingStats();
amb(0); //amber off ping complete
timeWas = timeNow;
buildStrings(); //in webData.ino
}
and the functions called
void pingStats() { //this is called from the loop() once every timeinterval seconds. (typically 6 sec)
if (pingOK) { //the line is UP so: OR //if (pingsLost == 0) { //the line is UP so
webIsUp();
Serial.println("web is up");
} else { // the web is DOWN:
webIsDown();
Serial.println("web is DOWN");
}
prepareStats();
}
void webIsUp() {
grn(1);
//timing the ups and downs
if (webUp == 0) { //its a new uptime, end of down phase
mtGoneUp = millis(); //*** record millis time that this uptime starts
//work out the down phase times
mtDowntimePrev += mtDnNew;
mtTimeDn = millis() - mtGoneDn;
mtTotDnThisH += mtDnNew;
webUp = 1;
}
//update live data for up times
mtUpNew = millis() - mtGoneUp; //duration of present up phase
mtUptimeTotal = mtUptimePrev + mtUpNew; //running value
lineDown = 0; //reset the linedown counter to 0 - this handles short outages less than threshold
pingMetrics(); //only relevant if theres a connection
//handle red led
if (webFail > 0) webFail--;
else red(0); //turn red off only after maxdown counts
}
void webIsDown() {
grn(0);
if (webUp == 1) { //its a new outage: end of up phase
mtGoneDn = millis(); // millis time the new outage started
//work out up phase times
mtUptimePrev += mtUpNew;
mtTimeUp = millis() - mtGoneUp;
mtTotUpThisH += mtUpNew;
// *** record dropouts
dropOuts++;
pDropOutsThisD++;
webUp = 0;
}
//update live data for downtime
mtDnNew = millis() - mtGoneDn;
mtDowntimeTotal = mtDowntimePrev + mtDnNew;
//handle red led
lineDown += 1;
if (lineDown >= threshold) { //we havent just missed a single ping so ..
lineDown = threshold; //dont let it keep counting
webFail = maxDown; //initially 60
red(1);
}
}
Serial monitor: the responder is OFF and stays OFF
01:22: web is DOWN
01:28: web is DOWN
pSaveStats lineDown, webFail 3 60
pSaveStats dropOuts, pDropOutsThisH, pDropOutsThisD 1, 0, 1
pSaveStats mtGoneUp, mtGoneDn, mtUptimePrev, mtDowntimePrev 22074, 40454, 238688 126000
01:34: web is DOWN
01:40: web is DOWN
web is DOWN
01:52: web is DOWN
01:58: web is DOWN
02:04: web is DOWN
web is DOWN
02:16: web is DOWN
02:28: web is up
pSaveStats lineDown, webFail 0 59
pSaveStats dropOuts, pDropOutsThisH, pDropOutsThisD 1, 0, 1
pSaveStats mtGoneUp, mtGoneDn, mtUptimePrev, mtDowntimePrev 148644, 40454, 238688 222000
02:35: web is up
02:43: web is up
02:50: web is up
02:57: web is up
03:04: web is up
03:11: web is up
03:18: web is up
03:26: web is up