http.GET()

Hi,

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");
  }

sed003:
I would like to know where those http.GET is defined.

Since you didn't bother to tell us which libraries you're using, you must not want to know very badly. I'll go ahead and take a guess:

sed003:
I searched in the ESP8266wifi-master.h and .cpp

Why would search there? The only repository of that name I know of is certainly not being used with the code you posted.

Oops. Sorry. It is not that I didn't bother. I just wanted to get to the point :slight_smile:

#include "ESP8266WiFi.h"
#include <ESP8266HTTPClient.h>

sed003:
#include "ESP8266WiFi.h"

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.

sed003:
#include <ESP8266HTTPClient.h>

That confirms my guess was correct.

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.

sed003:
nothing comes out. That line is blank.

If your code is running:

sed003:

      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));

You should not be getting nothing no matter what. It should be either:

payload: ...
http code: 0

or:

No response
http code: {some non-zero code}

You're right. I gotta stop posting after midnight :slight_smile:

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:

#define HTTPC_ERROR_CONNECTION_LOST     (-5)