I am using this piece of code to insert data using an ESP-12E. It is standard I copied it from somewhere with minor tweaks. It is placed inside a function.
I programmed my php page to send ">OK" or ">Error" if the insert was not successful. I am not sure how to get that feedback in the ESP12E. The code is always -5 regardless of the message.
I would like to know where those http.GET is defined. I searched in the ESP8266wifi-master.h and .cpp, but i don't see anything related.
Thanks
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection statu
HTTPClient http; //Declare an object of class HTTPClient
http.begin(GETCommand); //Specify request destination
int httpCode = http.GET(); //Send the request
Serial.print("Get command: ");
Serial.println(GETCommand);
if (httpCode > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
Serial.println("payload: " + payload); //Print the response payload
} else {
Serial.println("No response");
}
Serial.println("http code: " + String(httpCode));
http.end(); //Close connection
}
else
{
Serial.println("--> connection failed");
}
This is different from the ESP8266wifi library. ESP8266wifi is for when you are using an ESP8266 as a WiFi adapter module running the AT firmware, connected to a standard Arduino board via the serial port. ESP8266WiFi is a library bundled with the ESP8266 core for Arduino, which is used when you are directly programming the ESP8266. This was the cause of so much confusion that the author of the ESP8266wifi library renamed the source code files, but not the repository.
I am still not clear of what payload means. Is it the response sent back by the server? In my case the code says Serial.println(payload), but nothing comes out. That line is blank. I know my page sends some text back. I tested it from the browser.
I get no response. httpCode -5
I am not sure what -5 means, but when i turn off the wifi, i get -1. The question remains, how do I read the actual response sent by the page. I update a record and I want to see the result.
The library seems to define its own error codes with negative numbers, in addition to the standard HTTP status codes. They are defined in the header file: