Getting ping statistics with ESP32

I have a NODE gathering ping statistics.
I now want to migrate to an ESP32 - but the ping library I'm using

doesnt work for the ESP32.

This library claims to work on the ESP32 but I haven't tested it as I need more detailed stats
(ie for a ping count of eg 4 average latency and packet loss count)

This is info from espressif

which says it provides the info I need eg
--- ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 176ms

However I dont find the example very helpful

Can anyone tell me how to get the simple ping metrics I need with the ESP32?


It takes a bit of work to translate ESP32 code written under the IDF to ESP32 code that will work under the Arduino IDE.

I've had mixed results with the lwip library under the Arduino IDE.

@anon57585045 [quote="Idahowalker, post:3, topic:939599"]

Because I had no idea the IDF existed, much less what programs for it looked like!

I've now had some success using the above library by modifying the .cpp adding member functions? for expected count, errors, success as follows:

float PingClass::averageTime() {
    return _avg_time;

byte PingClass::expectedCount(){
return _expected_count;

byte PingClass::errors(){
return _errors;

byte PingClass::success(){
return _success;

and adding to the ESP32Ping.h


    bool ping(IPAddress dest, byte count = 5);

    bool ping(const char *host, byte count = 5);

    float averageTime();

    byte expectedCount();
    byte errors();
    byte success();

as you can see my experience with OOP is "limited";

@Idahowalker : having "studied" the ping.cpp file I now understand your reference to the lwip library

#include "lwip/inet_chksum.h"
#include "lwip/ip.h"

I'm a bit concerned about this long delay in ping.cpp -


if (interval == 0) {
        interval = PING_DEFAULT_INTERVAL;

 unsigned long ping_started_time = millis();
    while ((ping_seq_num < count) && (!stopped)) {
        if (ping_send(s, &ping_target, size) == ERR_OK) {
        if(ping_seq_num < count){
            **delay( interval*1000L);**

but when I do a ping (target, 4) it takes less than 4 seconds so I dont see what is going on?

I do not use millis() and delay() with the ESP32 and I write all my ESP32 code using freeRTOS, which would make a significant difference in operations.

Having delved through the library code the issue is that the ping timeout is set to 1 second.
.. Which is a bit annoying as the library SEEMS to allow it to be specified in usec.

 // Setup socket
    struct timeval tout;
    tout.tv_sec = timeout;
    tout.tv_usec = 0;
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tout, sizeof(tout)) < 0) 

so the 1 second DELAY is to cater for the 1 second ping timeout.
and I cant see a way to change that.

marian-craciunescu/ESP32Ping: Ping library for ESP32 Arduino core (

thanks @Idahowalker - am I missing something obvious?

I could set the pingNumber to 1 - but I still cant find any way to change the timeout. And as its presently 1 second then I cant allow a repeat in less than 1 second.

void loop() {
  timeNow = millis();
  if (timeNow >= (timeWas + (timeInterval * 1000))) {
    timeWas = timeNow;
    Serial.print("Pinging ip  ");
    //ping it
    if (, pingNumber)) {  
   //produces values for pingTime, expectedCount, success, errors
      showDone = false;  //prepare to update display

I just thought that if there is a ESp32 ping library that can return ping time in milli seconds that it might be better to use instead of rolling your own.

Thanks @Idahowalker
to clarify I'm using the marian c library and I've modified it #4 to give me the stats I need.
Its working MUCH better than the 8266 giving sensible values for pings.
I'm just concerned about the blocking code as I now want to add more functions.

An ESP32 has the built in OS, freeRTOS. Blocking code can easily be avoided with an ESP32 by using the multi-tasking, multi-processing OS.

An ESP8266 is not a ESP32.

I'm learning that now! I really like the NODE but trying this is next on my todo list

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.