esp8266气象站

参考:

https://blog.csdn.net/xuw_xy/article/details/89407607

https://blog.csdn.net/oAlevel/article/details/86976348

http://www.yfrobot.com/thread-11877-1-1.html

//-----------------------------------------------------------------------

使用心知天气API

注册申请https://www.seniverse.com

获得免费开发密钥https://www.seniverse.com/products?iid=new

免费用户权限

免费用户可以调用哪些数据

国内 370 个主要城市

  1. 天气实况,包括天气现象文字、代码和气温 3 项数据
  2. 未来 3 天天气预报,包括白天天气现象文字及代码、晚间天气现象文字及代码、当天最高温度和最低温度、风向风速
  3. 6 项基本类生活指数,包括穿衣、紫外线强度、洗车、旅游、感冒、运动指数

 

获得报文方式:公钥+私钥或者私钥的方式

//-------------------------------------------------

使用arduinojson工具做切片解析 https://arduinojson.org/v5/assistant/

是用范例,以下面的生活指数为例

 

const size_t capacity = JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(1) + 6*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 2*JSON_OBJECT_SIZE(6) + 350;
DynamicJsonBuffer jsonBuffer(capacity);

const char* json = "{\"results\":[{\"location\":{\"id\":\"WTMKQ069CCJ7\",\"name\":\"杭州\",\"country\":\"CN\",\"path\":\"杭州,杭州,浙江,中国\",\"timezone\":\"Asia/Shanghai\",\"timezone_offset\":\"+08:00\"},\"suggestion\":{\"car_washing\":{\"brief\":\"不宜\",\"details\":\"\"},\"dressing\":{\"brief\":\"热\",\"details\":\"\"},\"flu\":{\"brief\":\"易发\",\"details\":\"\"},\"sport\":{\"brief\":\"较不宜\",\"details\":\"\"},\"travel\":{\"brief\":\"较不宜\",\"details\":\"\"},\"uv\":{\"brief\":\"弱\",\"details\":\"\"}},\"last_update\":\"2019-06-30T13:49:49+08:00\"}]}";

JsonObject& root = jsonBuffer.parseObject(json);

JsonObject& results_0 = root["results"][0];

JsonObject& results_0_location = results_0["location"];
const char* results_0_location_id = results_0_location["id"]; // "WTMKQ069CCJ7"
const char* results_0_location_name = results_0_location["name"]; // "杭州"
const char* results_0_location_country = results_0_location["country"]; // "CN"
const char* results_0_location_path = results_0_location["path"]; // "杭州,杭州,浙江,中国"
const char* results_0_location_timezone = results_0_location["timezone"]; // "Asia/Shanghai"
const char* results_0_location_timezone_offset = results_0_location["timezone_offset"]; // "+08:00"

JsonObject& results_0_suggestion = results_0["suggestion"];

const char* results_0_suggestion_car_washing_brief = results_0_suggestion["car_washing"]["brief"]; // "不宜"
const char* results_0_suggestion_car_washing_details = results_0_suggestion["car_washing"]["details"]; // ""

const char* results_0_suggestion_dressing_brief = results_0_suggestion["dressing"]["brief"]; // "热"
const char* results_0_suggestion_dressing_details = results_0_suggestion["dressing"]["details"]; // ""

const char* results_0_suggestion_flu_brief = results_0_suggestion["flu"]["brief"]; // "易发"
const char* results_0_suggestion_flu_details = results_0_suggestion["flu"]["details"]; // ""

const char* results_0_suggestion_sport_brief = results_0_suggestion["sport"]["brief"]; // "较不宜"
const char* results_0_suggestion_sport_details = results_0_suggestion["sport"]["details"]; // ""

const char* results_0_suggestion_travel_brief = results_0_suggestion["travel"]["brief"]; // "较不宜"
const char* results_0_suggestion_travel_details = results_0_suggestion["travel"]["details"]; // ""

const char* results_0_suggestion_uv_brief = results_0_suggestion["uv"]["brief"]; // "弱"
const char* results_0_suggestion_uv_details = results_0_suggestion["uv"]["details"]; // ""

const char* results_0_last_update = results_0["last_update"]; // "2019-06-30T13:49:49+08:00"

 

//-------------------------------------------------

使用API请求最近三天天气

https://api.seniverse.com/v3/weather/daily.json?key=youkey&location=hangzhou&language=zh-Hans&unit=c&start=0&days=4

{"results":[{"location":{"id":"WTMKQ069CCJ7","name":"杭州","country":"CN","path":"杭州,杭州,浙江,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"},"daily":[{"date":"2019-

06-30
","text_day":"暴雨","code_day":"16","text_night":"中雨","code_night":"14","high":"29","low":"25","precip":"","wind_direction":"","wind_direction_degree":"0","wind_speed":"15","wind_scale":"3"},{"date":"2019-07-01","text_day":"中雨","code_day":"14","text_night":"中雨","code_night":"14","high":"27","low":"24","precip":"","wind_direction":"无持续风向","wind_direction_degree":"","wind_speed":"10","wind_scale":"2"},{"date":"2019-07-02","text_day":"小雨","code_day":"13","text_night":"小雨","code_night":"13","high":"24","low":"22","precip":"","wind_direction":"","wind_direction_degree":"90","wind_speed":"15","wind_scale":"3"}],"last_update":"2019-06-30T11:00:00+08:00"}]}

请求当前天气温度

https://api.thinkpage.cn/v3/weather/now.json?key=youkey&location=hangzhou&language=zh-Hans&unit=c

{"results":[{"location":{"id":"WTMKQ069CCJ7","name":"杭州","country":"CN","path":"杭州,杭州,浙江,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"},"now":{"text":"多云","c
ode
":"4","temperature":"28"},"last_update":"2019-06-30T16:20:00+08:00"}]}



请求生活指数

https://api.seniverse.com/v3/life/suggestion.json?key=youkey&location=shanghai&language=zh-Hans

 

{"results":[{"location":{"id":"WTW3SJ5ZBJUY","name":"上海","country":"CN","path":"上海,上海,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"},"suggestion":{"car_washing":{"brief":"不宜","details":""},"dressing":{"brief":"舒适","details":""},"flu":{"brief":"较易发","details":""},"sport":{"brief":"较不宜","details":""},"travel":{"brief":"一般","details":""},"uv":{"brief":"最弱","details":""}},"last_update":"2019-06-30T15:20:10+08:00"}]}

 

 

emmm,现在的问题提是,是否能够一次请求所有的数据,感觉不能

转载于:https://www.cnblogs.com/beyondsdo/p/11110324.html

该设计仿制国外ESP8266+OLED Weather Station成功,原文链接:https://blog.squix.org/2017/01/esp8266-weather-sta... 下面介绍本人的设计 安卓手机app下载地址:https://espressif.com/zh-hans/products/software/esp-touch/resources,ios直接在AppStore里搜索 esptouch即可。 最新进展,源码经过修改可以通过官方的手机app让Weather Station快连到WiFi,并自动记录最后一次快连成功的路由器,下次会自动连接。如果换了WiFi环境自动进入快连界面,这时在手机运行官方app(esptouch)输入WiFi密码即可连接。 附件zip已经打包好库文件,解压后放在没有中文路径的文件夹下面,再在arduino的“首选项”-- “项目文件夹位置” 指向这个文件夹。重启arduino,然后打开“文件”--”项目文件夹“--WeatherStationDemo,选择对应的板和COM口下载即可。 源码里面有一个wunderground 的key给大家试用,每天500次的API访问量,记得把城市改到对应的城市。从下午开始想着再申请几个key结果死活不行,或许对ip有限制吧? 源码改的乱七八糟,高手大侠见笑了。。。笑过之后请抽时间多指点能改进完善一下程序最好了! 注:修改好的源码及库文件见附件内容下载。 WIFI 气象站实物图展示: 使用NodeMCU1.0(ESP8266-12E),集成了CP2102,可以直接电脑USB ;OLED是SSD1306的128×64,IIC接口 初接触Arduino和ESP8266,现在仿制阶段。 所有资料来自网络,感兴趣的一起来完善它,高手大侠们多多指教! 作者博客:https://blog.squix.org/ 制作网页:https://www.instructables.com/id/ESP8266-Weather-Widget/ Arduino源码:https://github.com/squix78/esp8266-weather-station Arduino IDE可以像使用UNO一样使用ESP8266,编译环境的搭建:https://www.geek-workshop.com/thread-26170-1-1.html 目前改进设想 1、加入SmartConfig(WIFI快连),在手机或者PC上面通过APP配置路由器密码,不用再在源码里改动 2、把OLED换成LCD或者LED点阵屏,OLED太小了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值