其他分享
首页 > 其他分享> > yeelink平台试玩

yeelink平台试玩

作者:互联网

最近正在琢磨实现ESP8266的广域网功能,准备接入一些大的云平台。后续做了一些平台对接之后,会专门写一篇文章来总结对比各家的云平台。

这里很感谢yeelink为开发者提供的便利,两年多前接触以太网的时候就听过yeelink,后来看到他们出了自己的灯,后来又加入了小米生态链,感觉他们在良好地发展着。目前了解到yeelink的平台是接入门槛最低的,注册开发者帐号即可使用。于是乎做了一些尝试,写下这篇文章。

转载请注明:http://blog.csdn.net/sadshen/article/details/46872795

一、API梳理
梳理了yeelink的API(http://www.yeelink.net/develop/api),API满足http。因此我就从http中的方法和URL两个方面来讲述这个API。

1.方法

可以看到http四种方法分别对应yeelink的四种操作方式。

POST   -创建

PUT    -编辑

GET    -罗列/查看

DELETE -删除

 

2.URL

YeeLink的层次结构还是很清晰的,设备包含传感器,传感器包含数据点(图像传感器没有数据点,为图像数据)。

在/device目录下存放着用户创建的设备,具体的设备目录(/device/<device_id>)下存放着设备拥有的传感器。每个传感器目录(/device/<device_id>/sensors/<sensor_id>)下又包含数据点目录,存放着历次的数据点。我还是画个框图。

/device

├─DeviceId_1

│  │  title-Dev1,about-xx,tags-xx,local-xx,latitude-xx,longitude-xx

│  │  

│  └─sensors

│      ├─SensorId_1

│      │  │  type-value,title-Sensor1,about-xx,tags-xx,unit-xx

│      │  │  

│      │  └─datapoints

│      ├─SensorId_2

│      │  │  type-switch,title-Sensor2,about-xx,tags-xx,unit-xx

│      │  │  

│      │  └─datapoints

│      ├─SensorId_3

│      │  │  type-gen,title-Sensor3,about-xx,tags-xx,unit-xx

│      │  │  

│      │  └─datapoints

│      └─SensorId_4

│          │  type-photo,title-Sensor3,about-xx,tags-xx,unit-xx

│          │  

│          └─photos

└─DeviceId_2

3.总结

第1点是操作方法,第2点URL是操作对象,二者结合的一系列动作就是设备与云平台的交互了。

搞明白了这个之后,就能很轻松知道yeelink的罗列和查看的区别。

罗列设备:      Get /device

查看具体设备:  Get /device/<device_id>

罗列传感器:    Get /device/<device_id>/sensors

查看具体传感器:Get /device/<device_id>/sensors/<sensor_id>

 

二、cURL操作示例
在ESP局域网通信的学习笔记中,我已经安装了curl工具。接下来就模仿API示例来与yeelink平台进行通信,熟悉下yeelink的交互。

我在yeelink上建了DEV1和DEV2两个设备,在DEV1中还创建了几个传感器。

 

罗列设备

curl --request GET --header "U-ApiKey: e510ad132988d34c6fc9c3a9322f6f10" http://api.yeelink.net/v1.0/devices

 

 

罗列传感器

curl --request GET --header "U-ApiKey: e510ad132988d34c6fc9c3a9322f6f10" http://api.yeelink.net/v1.0/device/140430/sensors

 

 

上报数据点

curl -i --request POST --data “{\”value\”:26.6}” --header "U-ApiKey: e510ad132988d34c6fc9c3a9322f6f10" http://api.yeelink.net/v1.0/device/140430/sensor/159032/datapoints

查看数据点

curl --request GET --header "U-ApiKey: e510ad132988d34c6fc9c3a9322f6f10" http://api.yeelink.net/v1.0/device/140430/sensor/159032/datapoints

 

 

可以看到POST的26.6摄氏度在平台上也有了相应的变化:

 

三、总结
借助cURL工具,快速地熟悉了yeelink的交互。Yeelink的层次结构很清晰,上手很快。

接下去就是编写具体的嵌入式代码来实现http通信了。

转载原文:https://blog.csdn.net/sadshen/article/details/46872795 
 

标签:http,平台,xx,试玩,传感器,device,net,yeelink
来源: https://blog.csdn.net/zjy900507/article/details/97149337