Got problem with coding call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)

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

const char *ssid = "HUAWEI NOVA 5T";
const char *password = "0169437326";

String tempValue;
int analogValue;
int tempPin = A0;
float miliVolts;
float celcius;

String postData;
int httpCode;
String payload;

void setup(){
delay(1000);
Serial.begin(115200);
WiFi.begin(ssid,password);
Serial.println("");
Serial.println("Connecting");
while(WiFi.status()!= WL_CONNECTED){
delay(500);
Serial.println(".");
}
Serial.println("");
Serial.println("connected to");
Serial.println(ssid);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

}

void loop(){
delay(5000);
analogValue = analogRead(tempPin);
miliVolts = (analogValue/1024.0)*3000;
celcius = miliVolts/10;
tempValue = String(celcius);
Serial.println(tempValue);

HTTPClient http;
postData = "tempValue=" +tempValue;
http.begin("http://192.168.43.224/dbInsert.php");
http.addHeader("Content-Type","application/x-www-form-urlencoded");
httpCode =http.POST(postData);
payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
http.end();
}

(the status always appear even i change the coding can help me to define the problem)
pratceiot:47:11: error: call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)
47 | http.begin("http://192.168.43.224/dbInsert.php");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

You need a WiFiClient connected to the HTTP (Web) server to pass to the HTTPClient.begin() function. See the library examples in File -> Examples -> ESP8266HTTPClient. Particularly: File -> Examples -> ESP8266HTTPClient -> BasicHttpClient

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.