esp8266 esp-12 connects to wifi but I cannot ping IP address

I have written some code that successfully connects to the wifi and prints out the ip address for the device. However, when I try to go there in browser it just loads forever and when I try to ping it in cmd prompt, it does not ping. Also, during this time, it is saying connected in the serial.println. Any idea what is wrong here? BTW this works on my arduino mkr wifi 1010 just fine.

if (client.connect(localServer, 80) == 1) {
    Serial.println("Connected!");

    client.print("GET /write_data.php?");
    client.println(" HTTP/1.1");
    client.println("Host: www.myurl.com");
    client.println("Connection: close");
    client.println();
    client.println();
    client.stop();

}

The code is much more complex but this shows it is clearly connected and running this in loop() every 5 seconds.

I guess the ESP8266 doesn't respond nicely to ICMP requests.
Are you attempting to see if your ESP8266 is alive from another device on the network ?
This may help: ESP8266-ping - Arduino Reference

I've never had a problem pinging an ESP8266 once it's connected to my WiFi. Time to make an MRE. Cut out everything from your code but connecting to the WiFi. Get rid of all the Server / Client stuff, user I/O, everything but connecting to the WiFi and reporting the IP address. After that do nothing. Then ping the IP from a PC on your network. If it doesn't work, post the full code for this attempt.

I am still trying to debug what is happening but I found the issue. I am getting "400 bad request" but I cannot figure out why. Here is my client communication. Can you see anything wrong here?

const char* hostGet = "www.myUrlHere.com"; 


void postData() {

   WiFiClient clientGet;
   const int httpGetPort = 80;

   //the path and file to send the data to:
   String urlGet = "write_data.php";

 
  // We now create and add parameters:
  String src = "000123";
  String typ = "esp";
  String nam = "92";

  urlGet += "?uniqueID=" + src + "&user=" + typ + "&value=" + nam;
   
      Serial.print(">>> Connecting to host: ");
      Serial.println(hostGet);
      Serial.println(urlGet);
      
       if (!clientGet.connect(hostGet, httpGetPort)) {
        Serial.print("Connection failed: ");
        Serial.print(hostGet);
      } else {
          clientGet.println("GET " + urlGet + " HTTP/1.1");
          clientGet.print("Host: ");
          clientGet.println(hostGet);
          clientGet.println("User-Agent: ESP8266/1.0");
          clientGet.println("Connection: close\r\n\r\n");
          
          unsigned long timeoutP = millis();
          while (clientGet.available() == 0) {
            
            if (millis() - timeoutP > 10000) {
              Serial.print(">>> Client Timeout: ");
              Serial.println(hostGet);
              clientGet.stop();
              return;
            }
          }

          //just checks the 1st line of the server response. Could be expanded if needed.
          while(clientGet.available()){
            
            String retLine = clientGet.readStringUntil('\r');
            Serial.println(retLine);
            break; 
          }

      } //end client connection if else
                        
      Serial.print(">>> Closing host: ");
      Serial.println(hostGet);
          
      clientGet.stop();

}

OMG I found my issue... missing a "/" before the php file and after the url. So silly. Glad I found it though.

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