Can't connect and ping to other devices in local network

Hi,
I'm stuck on a problem.
I tried to connect to the websocket server set up on my laptop, the code used to connect came straight from the documentation. The Arduino gets the IP address but cannot connect. I started checking and pinging my ESP32. The server is working, the connection from the PieSocket Tester is correctly established.
The Ip address of the esp32 is 192.168.1.7. The address of the computer on the same network is 192.168.1.4. From the computer I can ping the esp address with no problem, but the address of the computer with the esp does not work. When changing the network to HotSpot from the phone it is the same. what could be wrong?

#include <WiFi.h>
#include <ESP32Ping.h>

const char *ssid = "xxxx";
const char *password = "xx";

void setup()
{
  Serial.begin(9600);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.println("Connecting to WiFi...");
  }

  bool success = Ping.ping("192.168.1.4", 3);

  if (!success)
  {
    Serial.println(WiFi.localIP());
    Serial.println("Ping failed");
    return;
  }
  Serial.println(WiFi.localIP());
  Serial.println("Ping succesful.");
}

void loop() {}

You can't do this:

 bool success = Ping.ping("192.168.1.4", 3);

If you look at the library source, you have to choose between:

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

When using the second one, the "host" parameter should contain a host name, to be resolved using "hostByName" function, as you can see:

bool PingClass::ping(const char *host, byte count) {
    IPAddress remote_addr;

    if (WiFi.hostByName(host, remote_addr))
        return ping(remote_addr, count);

    return false;
}

So if you want to use the IP address I think you must use "IPAddress" class:

  IPAddress remote_ip(192, 168, 1, 4);
  bool success = Ping.ping(remote_ip, 3);
2 Likes

Thanks for you reply. Your solution produces the same result.
But, I have found what the problem is.
After changing the router settings, more specifically the ping blocker (I didn't know such a setting existed at all) the devices see each other normally.

Anyway, it's the "regular" way to call such function. :wink:

IDK, as far as I know routers ping blocker function is for ICMP coming from outside your network (disabled anyone else checking if your router is online), not for local clients.
BTW if that router (which one?) setting was the culprit, it's ok! :+1:

I had the same problem and the explanation & solution by docdoc worked perfectly. Cheers!

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