ESP8266 http Get query

Hi, thanks for reading my post :slight_smile:

I'm using a Wemos D1 Mini / ESP8266 board to perform an HTTP GET to mu local server.

My code works although I am getting a compilation warning.. I have changed the http.begin() call to include the WiFi client but then the code fails. Here is the warning message :

WiFi_test.ino:37:27: warning: 'bool HTTPClient::begin(String)' is deprecated (declared at C:\Users\user\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:174) [-Wdeprecated-declarations]
   if ( http.begin( Buffer ) )

I suspect I have the wrong combination of libraries ? - can anyone please advise of what the issue may be ? Here is the complete app.

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

#define BUTTON_PIN  0

void setup()
{
  Serial.begin( 38400 );
  pinMode( BUTTON_PIN, INPUT_PULLUP );
}

void loop()
{
  char       Buffer[64];
  WiFiClient Client;
  HTTPClient http;

  Serial.println("Starting...");

  WiFi.mode(WIFI_STA);
  WiFi.begin( "VM2293456", "******" );

  while ( WiFi.status() != WL_CONNECTED )
    delay( 50 );

  Serial.println("Ready...");

  while ( digitalRead( BUTTON_PIN ) == HIGH )
    delay( 50 );

  strcpy( Buffer, "http://192.168.0.47/writelog.php?" );
  strcat( Buffer, "Source=Arduino" );
  strcat( Buffer, "&LogType=1" );
  strcat( Buffer, "&LogText=Button%20Pressed" );

  if ( http.begin( Buffer ) )
  {
    int httpRetCode = http.GET();

    http.end();

    if ( httpRetCode == HTTP_CODE_OK )
    {
      Serial.println( "GET sent OK" );
    }
    else
    {
      Serial.print( "Bad Request. httpRetCode = " );
      Serial.println( httpRetCode );
    }
  }
  else
  {
    Serial.print( "http.begin() failed" );
  }
  delay(5000);
}

I press the button connect to the device and see that the GET works ( confirmed on server ), but I get an exception message some time later on the device.

Thanks

Solved !

It appears that the order in which the defines were listed is significant. Whilst this did not work ;

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

...this did;

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

Also. after discovering that the order was significant I found that my code had a memory overrun in the variable 'buffer[].

Note to self to check buffer lengths against requirements !

Hope this helps somebody

:slight_smile:

Mart1411