使用python3上传数据流到OneNet云平台

import requests
import json
import sys
import random
import time
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
    reload(sys)
    sys.setdefaultencoding(defaultencoding)
#设备ID
DEVICEID = ' xxxxxxxxxx'
#数据流名称
SENSORID = ' xxxxxxxxxx'
#数值
VALUE = {"lon": "118.87104","lat": "31.924043"}       
#APIKEY
APIKEY = ' xxxxxxxxxx'
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 * '*')

你可能感兴趣的:(python,云平台)