Hello there!
I am trying to create a home weather station using the NodeMCU ESP8266 board. I am somewhat of a beginner, so I have had some trouble along the way. All the problems which I have encountered have been relatively easy to fix, until now.
Below is my code, where I establish a connection with the wifi, then make an HTTP.GET request on a weather API, then print the results. (I have changed my wifi info and API key)
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
HTTPClient http;
WiFiClient client;
const char* ssid = "ssid";
const char* password = "password";
void setup () {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print("Connecting..");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
http.begin(client, "https://api.thingspeak.com/apps/thinghttp/send_request?api_key=21apikey"); //Specify request destination
int httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
Serial.println(payload); //Print the response payload
}
http.end(); //Close connection
}
delay(30000); //Send a request every 30 seconds
}
When I run the program, I receive a rather confusing error message:
C:\Users\Serkan\OneDrive\Documents\Arduino\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp: In member function 'bool HTTPClient::begin(WiFiClient&, const String&)':
C:\Users\Serkan\OneDrive\Documents\Arduino\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp:88:22: **error: 'class WiFiClient' has no member named 'clone'**
** 88 | _client = client.clone();**
** | ^~~~~**
C:\Users\Serkan\OneDrive\Documents\Arduino\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp: In member function 'bool HTTPClient::begin(WiFiClient&, const String&, uint16_t, const String&, bool)':
C:\Users\Serkan\OneDrive\Documents\Arduino\libraries\ESP8266HTTPClient\src\ESP8266HTTPClient.cpp:105:22: **error: 'class WiFiClient' has no member named 'clone'**
** 105 | _client = client.clone();**
** | ^~~~~**
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
This definitely has something to do with the library 'ESP8266HTTPClient.h'. I had previously had some trouble with importing it to the sketch, but now there appears to be something wrong with the actual library. I need to figure out if its something wrong with my code, or if I need to find a new library.
Any help would be greatly appreciated, thanks!