Error: call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)
17,368
Solution 1
You need to also create a new instance of WiFiClient from WiFiClient.h, and pass that in to the begin:
#include <WiFiClient.h>
WiFiClient wifiClient;
void PiHoleClient::getPiHoleData(String server, int port) {
errorMessage = "";
String response = "";
String apiGetData = "http://" + server + ":" + String(port) + "/admin/api.php?summary";
Serial.println("Request: " + apiGetData);
HTTPClient http; //Object of class HTTPClient
http.begin(wifiClient, apiGetData);// get the result (**the error code**)
int httpCode = http.GET();
//Check the returning code
if (httpCode > 0) {
response = http.getString();
http.end(); //Close connection
if (httpCode != 200) {
// Bad Response Code
errorMessage = "Error response (" + String(httpCode) + "): " + response;
Serial.println(errorMessage);
return;
}
Solution 2
I saw this post and have checked this, I updated the esp8266 core to v3.0.0 earlier this week and also found that marquee scroller doesn’t compile and gives the identical errors, I have reinstalled v2.7.4 and it compiled first time.
https://www.gitmemory.com/issue/Qrome/marquee-scroller/186/846463005
Author by
Admin
Updated on June 05, 2022Comments
-
Admin almost 2 years
I tried to do a Clock News Weather Scrolling Marquee with the esp8266. But when I upload the code it's got an error. Can you help me? Here's a part of the code:( under the MIT License (Copyright 2018 David Payne))
void PiHoleClient::getPiHoleData(String server, int port) { errorMessage = ""; String response = ""; String apiGetData = "http://" + server + ":" + String(port) + "/admin/api.php?summary"; Serial.println("Sending: " + apiGetData); HTTPClient http; //Object of class HTTPClient http.begin(apiGetData);// get the result (**the error code**) int httpCode = http.GET(); //Check the returning code if (httpCode > 0) { response = http.getString(); http.end(); //Close connection if (httpCode != 200) { // Bad Response Code errorMessage = "Error response (" + String(httpCode) + "): " + response; Serial.println(errorMessage); return; }
error: exit status 1 call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)