Anyone familiar with ESP8266Ping.h?

I wrote a program to ping various devices on my local network (192.168.1.x) . It works, but I can't ping the ESP (Wemos D1 Mini) that is running this sketch.

If I don't call ping(), then I can ping the ESP

Any workarounds would be appreciated.

The sketch:

#define SKETCH "pingTest"
#define VERSION "1.00"           // Four characters

/*
   This program is a test of the ping function
*/

//-------------------------
#include <ESP8266Ping.h>    //Includes ESP8266WiWi.h
#include <Kaywinnet.h>       // WiFi credentials

char pingIP[20];             // IP that we're going to ping.


//****************************** SERIAL **************************
void beginSerial() {
  Serial.begin(115200);
  delay(1000);
  Serial.println();
  Serial.println(SKETCH);
  Serial.println(VERSION);
  Serial.println();
}


//****************************** WiFi **************************
void setup_wifi() {
  Serial.println();
  Serial.println("Connecting to ");
  Serial.println(MY_SSID);

  //WiFi.hostname(SKETCH);
  WiFi.begin(MY_SSID, MY_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(WiFi.status());
    Serial.print(" ");
  }

  Serial.println("\nWiFi connected, ");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("Hostname: ");
  Serial.println(WiFi.hostname().c_str());
}


//****************************** PING **************************
void pingit() {
  Serial.print(pingIP);
  Serial.print(F(": "));
  if (Ping.ping(pingIP)) {                    // Ping
    Serial.println("OK");
  } else {
    Serial.println("Fail");
  }
}


//****************************** SETUP **************************
void setup() {
  beginSerial();
  setup_wifi();
}


//****************************** LOOP **************************
void loop() {
  strcpy(pingIP, "192.168.1.1");
  pingit();
  strcpy(pingIP, "192.168.1.57");
  pingit();
  strcpy(pingIP, "192.168.1.124");
  pingit();
  strcpy(pingIP, "192.168.1.183");
  pingit();
  strcpy(pingIP, "127.0.0.1");
  pingit();

  Serial.println(F("---------------"));
  delay(1000);
}

The sketch is not running a webserver or any function that would respond to a ping request. You would need to run something the ESPAsyncWebServer if you wanted to ping your ESP board. Basically, if ping is a phone call, you need something that will pick up and answer the call.

I know that it needs something to respond to an ICMP request, but if I never call ping(), I can ping the ESP just from connecting to the net.

Here is the same sketch with the ping library and ping functions removed. Run this and you can ping the ESP just fine.

#include <ESP8266WiFi.h>
#include <Kaywinnet.h>       // WiFi credentials

//****************************** SETUP **************************
void setup() {
  Serial.begin(115200);
  Serial.println();

  Serial.println();
  Serial.println("Connecting to ");
  Serial.println(MY_SSID);

  WiFi.begin(MY_SSID, MY_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(WiFi.status());
    Serial.print(" ");
  }

  Serial.println("\nWiFi connected, ");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("Hostname: ");
  Serial.println(WiFi.hostname().c_str());
}


//****************************** LOOP **************************
void loop() {
  delay(1000);    //No reason
}

You can call ping from the ESP but to ping the board itself from something else, the board will have to have some function to respond to said ping. You're not trying to ping the board from itself are you? Why would you do that?

First. a new observation. The observed problem seems to be in the Windows ping tool, not the ESP device. Pings from Ubuntu do get a response from the ESP while the ESP is calling ping(). Perhaps the timeout in the Windows ping is shorter than the TTL?

There's my question. When I just connect to the WiFi with

WiFi.begin(MY_SSID, MY_PASSWORD);

I can then ping the device from any computer on my local network.
After calling ping() on the ESP, the Windows PC times out with every ping.

So, problem solved- I don't have a problem. Windows does.

To answer your question, yes I was trying to have the ESP ping itself. I have a board that pings the router and the servers on my network. I wanted to ping self to differentiate from a board problem or a router problem. Since this didn't work I fixed that issue with a heartbeat. But it bugged me- why did calling ping() stop the pings from the PC from responding?

This feature is available, called the TCP / IP protocol stack, by default ping is not closed

PS (in ESP32)

PING 192.168.1.113 (192.168.1.113): 56 data bytes
64 bytes from 192.168.1.113: seq=0 ttl=255 time=103.807 ms
64 bytes from 192.168.1.113: seq=1 ttl=255 time=123.252 ms
64 bytes from 192.168.1.113: seq=2 ttl=255 time=146.051 ms
64 bytes from 192.168.1.113: seq=3 ttl=255 time=169.914 ms
64 bytes from 192.168.1.113: seq=4 ttl=255 time=193.285 ms

--- 192.168.1.113 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 103.807/147.261/193.285 ms

PPS - Actual for ESP8266

PING 192.168.1.240 (192.168.1.240): 56 data bytes
64 bytes from 192.168.1.240: seq=0 ttl=255 time=5.746 ms
64 bytes from 192.168.1.240: seq=1 ttl=255 time=4.566 ms
64 bytes from 192.168.1.240: seq=2 ttl=255 time=1.584 ms
64 bytes from 192.168.1.240: seq=3 ttl=255 time=1.575 ms
64 bytes from 192.168.1.240: seq=4 ttl=255 time=1.603 ms

--- 192.168.1.240 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 1.575/3.014/5.746 ms

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