ESP8266获取网络天气数据

0
回复
108
查看
[ 复制链接 ]

38

主题

1

回帖

130

积分

管理员

积分
130
2025-7-1 11:23:48 显示全部楼层 阅读模式
ESP8266获取网络天气数据
快速实现:

安装库:

arduino
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
核心代码:

arduino
void getWeather() {
    WiFiClient client;
    if(client.connect("api.seniverse.com", 80)) {
        client.print("GET /v3/weather/now.json?key=YOUR_KEY&location=beijing");
        while(client.connected()) {
            String line = client.readStringUntil('\n');
            if(line.startsWith("\"temperature\":")) {
                Serial.println("当前温度:" + line.substring(14));
            }
        }
    }
}
调试技巧:

使用串口监视器查看原始JSON数据

用Postman先测试API接口
收藏
送赞
分享
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则