关于本篇文章的背景知识如 ESP8266 介绍、开发环境搭建等可以参考之前写的 Arduino IDE 搭建 ESP8266 开发环境及项目演示,或者浏览网络上的其他文章,不做赘述。
这里使用的开发板为基于 ESP8266 芯片设计的 NodeMcu,开发环境为配置后的 Arduino IDE。
一、云端数据监控(DHT11 + NodeMcu +Dweet.io)
1. 前期准备
找到 DHT11 温湿度传感器组件并接好线路(DAT 引脚连接 NodeMcu 的 D1 引脚)
确认 Arduino IDE 已添加上 ESP8266 编译支持
NodeMcu & DHT11 线路连接
2. Dweet.io
Dweet.io 是一个可以通过非常简易的方式为物联网设备提供通信服务(包括报警等)的云端平台。它不需要任何的设置或注册步骤,只要终端设备连接上互联网,即可直接发布或订阅数据。
通过 Dweet.io 提供的云端服务,可以很方便的将传感器数据发布到在线平台并实时地进行远程监控。
Dweeting
Dweeting 即发送数据到云端,可以通过调用如下格式的 URL https://dweet.io/dweet/for/my-thing-name?hello=world&foo=bar,
$ http -b "https://dweet.io/dweet/for/rollingstarky?hello=world&foo=bar"
{
"by": "dweeting",
"the": "dweet",
"this": "succeeded",
"with": {
"content": {
"foo": "bar",
"hello": "world"
},
"created": "2019-01-14T19:15:34.524Z",
"thing": "rollingstarky",
"transaction": "6af2b067-229f-4b40-9af9-23d22e438ecd"
}
}
注:上述代码示例中的 http 命令(类似于 curl,但更加友好)来自于 HTTPie 软件包
也可以在发送请求时通过 POST 方法提交合法的 JSON 数据。
Get Dweets
获取最新发布的 dweet 可以访问如下格式的 URL:
https://dweet.io/get/latest/dweet/for/my-thing-name
而获取某个名字下所有的 dweets,则可以访问如下 URL:
https://dweet.io/get/dweets/for/my-thing-name
$ http -b "https://dweet.io/get/dweets/for/rollingstarky"
{
"by": "getting",
"the": "dweets",
"this": "succeeded",