心知天气网站的数据获取
笔者来简单提一下获取天气网站的一些数据(网站提供了API接口)
一、测试
笔者使用的是心知天气,提供了免费的API,直接在浏览器输入网址:(key+localtion+language)
https://api.seniverse.com/v3/weather/now.json?key=your_private_key&location=beijing&language=zh-Hans&unit=c
则可以获取数据:
{"results":[{"location":{"id":"WX4FBXXFKE4F","name":"北京","country":"CN","path":"北京,北京,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"},"now":{"text":"晴","code":"0","temperature":"23"},"last_update":"2022-05-01T19:00:00+08:00"}]}
二、嵌入式设备访问
当然这只是测试,更多的场景是在嵌入式设备中获取数据来进行显示。笔者使用的是ESP8266,相当于WIFI模块,可以用来连接网络获取数据,首先需要连接wifi,这都不多说,接下来建立网络连接:
- 使用AT指令建立TCP链接,
"AT+CIPSTART=\"TCP\",\"api.seniverse.com\",80\x0d\x0a"
当然可以先通过串口直接连接8266进行测试:
- 使用API进行访问,笔者之前就想着C语言怎么发送get 或者post的请求,也没有参数指定,后来经过借鉴,发现直接在url 之前加入 get 就可以:
GET https://api.seniverse.com/v3/weather/now.json?key=your_private_key&location=beijing&language=zh-Hans&unit=c
- 通过ESP8266直接发送,就可以返回数据,同样串口直接测试:
- 可以通过OLED进行显示。
串口AT指令测试:
三、参考
文章目录
关闭
一位WordPress评论者
嗨,这是一条评论。
要开始审核、编辑及删除评论,请访问仪表盘的“评论”页面。
评论者头像来自Gravatar。
张一西@一位WordPress评论者
123
3
Help
Hello.
Your site is completely empty and not attractive to visitors.
Perhaps you need help?
Here you can choose an attractive template for your website – https://bit.ly/allforwp4
Various useful plugins can be found here – https://bit.ly/pluginsforsite
You can find logos, fonts and other web elements here – https://bit.ly/graphicforsite
If you need unique photos for the site, you can find them here – https://bit.ly/photoforsite
If you need help setting up WordPress, help with SEO or some other help, you can contact here – https://fvrr.co/3mJkc9P
I hope you will succeed and you will not abandon your site.
ZhangYixi@Help
yeah,you are right,but i dont know that how to do well for it,太难过了