I've added a few things to support async ping. It shouldn't change any existing functionality.
A third param disables the while-loop with the delay that waits for the _done flag to become true.
Then we can just check for the results with the Ping.hasResult() method and optionally clear the result flag using Ping.hasResult(true).
When the async flag is set to true, the return value of Ping.ping() indicates if the start of the pinging was successful or not. It will return false if theres another ping currently active.
void setup() {
// ...
bool ret = Ping.ping("www.google.com", 5, true); // async = true
if (ret) {
// ping started successfully
}
}
void loop() {
if (Ping.hasResult(true)) {
// ping is done, get the result
bool success = Ping.hasSuccess();
// do something with the result
}
// do other stuff here
delay(200);
}
Hey :-)
I've added a few things to support async ping. It shouldn't change any existing functionality. A third param disables the
while
-loop with the delay that waits for the_done
flag to becometrue
. Then we can just check for the results with thePing.hasResult()
method and optionally clear the result flag usingPing.hasResult(true)
.When the
async
flag is set totrue
, the return value ofPing.ping()
indicates if the start of the pinging was successful or not. It will returnfalse
if theres another ping currently active.