用platfromIO,做ESP32用HTTPClient库实现同步天气,但是在创建HTTPClient对象时总是出错,有谁知道为什么吗
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <ArduinoJson.h>
#include <HttpClient.h>
#define MAX_CONN 35
const char *ssid = "***";
const char *password = "**************************";
const String My_URL = "https://api.seniverse.com/v3/weather/now.json?key=***&location=qingdao&language=zh-Hans&unit=c";
int WiFi_CONN = 0;
bool WiFi_CONNECT = 1;
WiFiUDP ntpUDP; // 创建UDP实例
NTPClient timeClient(ntpUDP, "cn.pool.ntp.org", 3600 * 8, 60000);
void setup()
{
Serial.begin(115200); // 初始化串口
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
tft.print(".");
WiFi_CONN++;
if (WiFi_CONN == MAX_CONN)
{
WiFi_CONNECT = 0;
break;
}
}
if (WiFi_CONNECT == 0)
{
Serial.println("WIFi连接失败");
tft.println("WIFI is disconnect.");
}
else
{
Serial.println("WIFi连接成功");
tft.println("WIFI is connect.");
delay(1000);
}
delay(1000);
}
void loop()
{
HttpClient http; // 声明HTTPClient对象
http.begin(My_URL); // 准备启用连接
int httpcode = http.get(); // 发送get请求,并赋值用于判断状态
if (httpcode > 0) // 如果状态码>0证明无问题
{
if (httpcode == 200) // 请求被服务器正常相应
{String weather_info = http.getString();
Serial.print(weather_info);
}
else
{
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpcode).c_str());
}
http.end(); // 结束当前连接
delay(10000);
}
}
报错为:no matching function for call to 'HttpClient::HttpClient()'