ESP8266获取心知天气代码
时间: 2023-05-18 18:03:55 浏览: 113
以下是获取心知天气代码的示例代码:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
void setup() {
Serial.begin(115200);
WiFi.begin("your_SSID", "your_PASSWORD");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("https://api.seniverse.com/v3/weather/now.json?key=your_API_key&location=your_location&language=zh-Hans&unit=c");
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println(payload);
}
http.end();
}
delay(60000);
}
请将 "your_SSID" 和 "your_PASSWORD" 替换为您的 WiFi SSID 和密码,将 "your_API_key" 替换为您的心知天气 API 密钥,将 "your_location" 替换为您的城市名称或城市 ID。
阅读全文