使用Python2.7 POST 数据到 onenet 平台
功能
发送数据名称为SENSORID(这里用TEST测试),数值为VALUE(这里用49值做测试)的数据,发送到自己的onenet对应设备
效果发送成功
代码
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: onenetPostTest
Description :
Author : 神秘藏宝室
date: 2018-02-02
-------------------------------------------------
Change Activity:
2018-02-02:
-------------------------------------------------
"""
import requests
import json
import sys
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
#设备ID
DEVICEID = '3225187'
#数据流名称
SENSORID = 'TEST'
#数值
VALUE = 49
#APIKEY
APIKEY = 'R9xO5NZm6oVI4YBHvCPKEqtwYtMA'
url = 'http://api.heclouds.com/devices/%s/datapoints'%(DEVICEID)
print url
dict = {"datastreams":[{"id":"TEMP","datapoints":[{"value":50}]}]}
dict['datastreams'][0]['id'] = SENSORID
dict['datastreams'][0]['datapoints'][0]['value'] = VALUE
print dict
s = json.dumps(dict)
headers = {
"api-key":APIKEY,
"Connection":"close"
}
r = requests.post(url,headers=headers,data = s)
print r.headers
print '1',20 * '*'
print r.text
print '2',20 * '*'
文章对您有帮助,开心可以打赏我,金额随意,欢迎来赏!
需要电子方面开发板/传感器/模块等硬件可以到我的淘宝店逛逛