Using the WiFiping example, pinging an offline device seems to delay the loop() from running beyond the specified coded delay.
Is there a way to force the ping result to error out quicker?
You can easily test this by opening the WiFiping example and entering in a bad host (external, internal or IP address in byte format as IPAddress). Also test it against a working host. All yield the same result for me.
Note: I also see the same result with the example for WiFiWebClient when either attaching to an offline host.
Stock example which responds properly with a good host and unusually long with a bad (offline) host.
void loop() {
Serial.print("Pinging ");
Serial.print(hostName);
Serial.print(": ");
pingResult = WiFi.ping(hostName);
if (pingResult >= 0) {
Serial.print("SUCCESS! RTT = ");
Serial.print(pingResult);
Serial.println(" ms");
} else {
Serial.print("FAILED! Error code: ");
Serial.println(pingResult);
}
delay(5000); //<---- Change this to 2000 for a better example
}
Another example of a simplified full sketch that experiences the same result.
#include <SPI.h>
#include <WiFiNINA.h>
char ssid[] = "MyParanoidNeighborsHouse";
char pass[] = "password";
int status = WL_IDLE_STATUS;
unsigned long startTime = millis ();
IPAddress server(192, 168, 252, 22);
void setup() {
Serial.begin(9600);
while (status != WL_CONNECTED) {
status = WiFi.begin(ssid, pass);
delay(2000);
}
}
void loop() {
if (millis() - startTime > 2000) {
Serial.println(WiFi.ping(server));
startTime = millis();
}
}