雁飞•格物DMP平台设备属性数据上传(HTTP协议)
2022-02-17 本文已影响0人
羋学僧
雁飞•格物DMP平台设备属性数据上传(HTTP协议)

属性上报
import requests
import time
import json
timestamp = str(round(time.time() * 1000))
productKey = "cu3dvw7f1ql1lxDa"
deviceKey = "20220217"
url = "https://dmp-https.cuiot.cn:8943/topic/sys/{productKey}/{deviceKey}/property/pub".format(productKey = productKey,deviceKey = deviceKey)
payload = json.dumps({
"messageId": "12345",
"params":
{"key": "Uc", "value": 20.4,"ts": timestamp}
})
headers = {
'Content-Type': 'application/octet-stream',
'Authorization':"2936c67e98324255a4f0918c78bf1012"
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)

属性批量上报
import requests
import time
import json
timestamp = str(round(time.time() * 1000))
productKey = "cu3dvw7f1ql1lxDa"
deviceKey = "20220217"
url = "https://dmp-https.cuiot.cn:8943/topic/sys/{productKey}/{deviceKey}/property/batch".format(productKey = productKey,deviceKey = deviceKey)
payload = json.dumps({
"messageId": "12345",
"params":
{"data":[{"key": "Uc", "value": 28.4,"ts": timestamp},{"key": "Ub", "value": 25.4,"ts": timestamp}]}
})
headers = {
'Content-Type': 'application/octet-stream',
'Authorization':"2936c67e98324255a4f0918c78bf1012"
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)

