对接前,请先熟悉和了解中台使用:WEB控制台使用文档
名词解析:
网关ID:在MQTT服务中指网关Api接口响应结果中id、gateway_id、通信网关界面上的序号,为INT类型。
设备ID:在MQTT服务中指网关Api接口响应结果中id、device_id、设备实例界面上的序号,为INT类型。
数据点ID:在MQTT服务中指网关Api接口响应结果中id、data_id、数据点界面上的序号,为INT类型。
$IOTOS:由IOTOS定义的topic
接入要求:
MQTT最低版本3.1.1,授权认证处理使用物联中台帐号密码接入。
MQTT客户端ID(clientid):device_${网关ID}_ ${设备ID},如:device_171_401
"""Python MQTT连接样例代码"""
import paho.mqtt.client as mqtt
host = 'mqtt.aiotos.net' # 私有部署请使用私有IP
username = '平台帐号'
password = '帐号密码'
gateway_id = 171 # 网关ID
device_id = 401 # 设备ID
client_id = 'device_{}_{}'.format(gateway_id, device_id) # type: str # clientId必须device_开头
client = mqtt.Client(client_id=client_id)
client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.on_message = on_message
client.username_pw_set(username, password)
client.connect(host, 1883, 60) # 600为keepalive的时间间隔
client.loop_start()
设备实例驱动配置
事例代码,如下
{
"parentid": null,
"driver": "python/dr_mqtt.IOTOSMQTTDriver",
"param": {},
"bind": {}
}
MQTT设备数据上报格式
数据发布topic拼接规则:$IOTOS/device/platform/update/${网关ID}/${设备ID}
拼接事例:$IOTOS/device/platform/update/171/401
requestId,requestTime由设备端设置
{
"requestId": "966cb44c30464305bbea98694664b103",
"requestTime":1627737953514.123,
"data": {
"179f": {
"name": "数据点名称",
"id": 1963,
"oid": "7be6",
"ts": 1627737953.514,
"value": 1627737953.514
}
}
}
MQTT设备数据上报,平台将处理结果返回格式
数据发布topic拼接规则:$IOTOS/device/platform/update/${网关ID}/${设备ID}/${数据点ID}/result
拼接事例:$IOTOS/device/platform/update/171/401/1963/result
{
"id": 1963,
"oid": "7be6",
"name": "数据点名称",
"ts": 1627737953.514,
"value": 1627737953.514,
"requestId": "966cb44c30464305bbea98694664b103",
"requestTime": 1627737953514.123,
"responseId": "966cb44c30464305bbea98694664b103",
"responseTime": 1627737953514.123,
"responseCode": 0,
"responseDesc": "OK"
}
MQTT设备数据下发格式(平台下发数据到接入端(设备))
数据下发(设备反控)topic拼接规则:$IOTOS/device/endpoint/update/${网关ID}/${设备ID}/${数据点ID}
拼接事例:$IOTOS/device/endpoint/update/171/401/1963
设备端如需要接收平台数据下发,需要订阅此topic
{ "name": "数据点名称", "id": 1963, "oid": "7be6", "ts": 1642502674510.0, "value": "QWRYGSGSFDGFDS", "requestId": "966cb44c30464305bbea98694664b103", "requestTime":1627737953514.123, }
MQTT设备数据下发,设备端处理结果返回格式(接入端(设备)将处理结果上报到平台)
数据下发(设备反控)topic拼接规则:$IOTOS/device/endpoint/update/${网关ID}/${设备ID}/${数据点ID}/result
拼接事例:$IOTOS/device/endpoint/update/171/401/1963/result
此topic由平台端订阅,设备端向此发送数据。
responseId由接入设置随机字条,最大字符32.
responseCode、responseDesc字段设置请参考:错误定义附录
{
"id": 1963,
"oid": "7be6",
"name": "数据点名称",
"value": "QWRYGSGSFDGFDS",
"ts": 1642502674510.0,
"requestId": "966cb44c30464305bbea98694664b103",
"requestTime": 1627737953514.123,
"responseId": "966cb44c30464305bbea98694664b103",
"responseTime": 1627737953514.123,
"responseCode,": 0,
"responseDesc": "OK"
}
错误码
请参考:错误定义附录
最后编辑:IOTOS 更新时间:2023-11-29 09:38