The use of the ESP8266 in the world of IoT

User avatar
By rborrasca
#82418 Hi,

I'm trying to post some data into a website using ESP8266.
I've searched over the internet for some sketch that would do that, and found this one:

void post_data()
{
HTTPClient http; //Declare object of class HTTPClient

String data = "value=22";
http.begin(URL); //Specify request destination
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); //Specify content-type header

int httpCode = http.POST(data); //Send the request
String payload = http.getString(); //Get the response payload

Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload

http.end(); //Close connection

delay(5000); //Post Data at every 5 seconds
}


The problem is that I used this sketch, it didn't worked and I don't know why. httpCode is supposed to return 200 or 201 (I think so, not really sure) but it actually returns -1. And when I print payload, it doesn't print anything, only a blank space.

I can give any other specification you need about the code or even the website, just ask.