Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple ping requests to several hosts in parallel #8

Open
Hermarcel opened this issue May 8, 2020 · 1 comment
Open

Multiple ping requests to several hosts in parallel #8

Hermarcel opened this issue May 8, 2020 · 1 comment

Comments

@Hermarcel
Copy link

Hermarcel commented May 8, 2020

I need to ping several hosts in parallel from an event callback function. I cannot figure out how to do this. I created an array:

Pinger pinger[5]; // as global, [0] is unused

And tried to issue the pings in a loop within an event callback:

IPAddress IPtoPing(172,16,172,0);
for(i = 1; i <= 4; i++) {`
    IPtoPing[3] = i;
    pinger[i].OnEnd([](const PingerResponse& response)
    {
        Serial.printf("IP address: %s\n",  response.DestIPAddress.toString().c_str());
        return(true);
    });
    
    if(pinger[i].Ping(IPtoPing) == false) {
        // Error
    }
}

I would expect a ping being issued to ip's 192.168.0.1 thru 192.168.0.4, each leading to it's own callback and it's ip address being printed upon Serial. I do see the ARP and ICMP frames correctly in Wireshark. The OnEnd callback, however, is called only once, only for the last ip in the loop.

Am I doing something wrong? Am I missing something?

@Hermarcel
Copy link
Author

To answer my own question: Give the frames of each ping-request their own id by calling "SetPacketsId()"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant