ESP8266 not working with port forwarded api

55 Views Asked by At

I am using ESP8266 to send data from my sensor to a server. For testing purposes I am hosting the api on localhost and port forwarding using localtunnel. When I test the api using Thunder Client it is working but when I start the esp8266 the serial monitor output is 404 error but the url from serial monitor output is working in Thunder Client. What is the isuue?

this is the code for sending the request

  String serverPath = serverName + "?value1=" + String(a.acceleration.x);
  Serial.println(serverPath);

  WiFiClient client;
  HTTPClient http;
  
  http.begin(client, serverPath.c_str());

  int httpResponseCode = http.GET();
      
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    String payload = http.getString();
    Serial.println(payload);
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
    Serial.println(serverPath);
  }
  http.end();
0

There are 0 best solutions below