硬件平台:stm32f429、esp8266串口wifi模块.
天气数据来源:丫丫天气 [ http://www.yytianqi.com ].(其他天气都要手机号注册,这个不用,就用它了)
stm32f429通过串口6和esp8266连接,esp8266连接丫丫天气的服务器API接口 api.yytianqi.com,通过GET请求获取数据。
从官网介绍可以看到,有8个不同类型的请求接口,免费用户能用的是前面2个,我们用forecast7d测试下,例如
因为是免费用户,只能获取2天的天气。从获取到的信息可以看到,数据是json格式,而且没有gbk编码,要正常显示到LCD的话,要用cjson把我们需要的字段取出,并转换成gbk,
先格式化下网络调试助手接收的数据
{
"code": 1,
"msg": "Sucess",
"counts": 29,
"data": {
"cityId": "CH280601",
"cityName": "深圳",
"sj": "2018-11-05 19:00:00",
"list": [{
"tq2": "多云",
"tq1": "多云",
"numtq1": "01",
"numtq2": "01",
"qw1": "27",
"qw2": "22",
"fl1": "微风",
"fl2": "微风",
"numfl1": 0,
"numfl2": "0",
"fx1": "东北风",
"fx2": "无持续风向",
"numfx1": "1",
"numfx2": "0",
"date": "2018-11-05"
}, {
"tq2": "多云",
"tq1": "多云",
"numtq1": "01",
"numtq2": "01",
"qw1": "29",
"qw2": "22",
"fl1": "3-4级",
"fl2": "微风",
"numfl1": "1",
"numfl2": "0",
"fx1": "东风",
"fx2": "无持续风向",
"numfx1": "2",
"numfx2": "0",
"date": "2018-11-06"
}]
}
}
格式化后数据就很容易看懂了,从这里取出我们要显示的字段,搞定。
本帖最后由 流年u7 于 2018-11-6 10:23 编辑