1. 官网注册用户,建立产品,建立设备
2. 查看设备详情,主要用到的参数:设备ID,API-KEY,另外要建立数据流
3. 先用API调试工具进行数据获取和加入的测试
GET:
POST:
注意报文格式:
{"datastreams":[{"id":"bingxiang_data","datapoints":[{"value":42}]}]}}
上述报文为测试成功的报文
3. 更灵活的调试方式:使用Fiddler工具
GET:
查看raw data
POST
3. Python调用requests库添加数据
import requests
url="https://api.heclouds.com/devices/20551455/datapoints"
headers={"api-key":"afUupPXvofGVVkacw0FMoI45zyk="}
payload={"datastreams":[{"id":"bingxiang_data","datapoints":[{"value":42}]}]}
r = requests.get(url, headers=headers,data=payload)
print (r.status_code)
print (r.content)
返回结果
200
b'{"errno":0,"data":{"count":2,"datastreams":[{"datapoints":[{"at":"2017-12-24 20:03:33.690","value":"60"}],"id":"bingxiang_humidity"},{"datapoints":[{"at":"2018-10-14 01:22:31.384","value":42}],"id":"bingxiang_data"}]},"error":"succ"}'