注意, 在进行MQTT CONNECT协议设置的时候
MQTT 连接域名:
使用域名:${productKey}.iot-as-mqtt.cn-shanghai.aliyuncs.com:1883${productKey}请替换为您的产品key,mqtt的Connect报文参数如下:mqtt的Connect报文参数如下:mqttClientId: clientId+"|securemode=3,signmethod=hmacsha1,timestamp=132323232|"mqttUsername: deviceName+"&"+productKeymqttPassword: sign_hmac(deviceSecret,content)sign签名需要把以下参数按字典序排序后,再根据signmethod加签。content=提交给服务器的参数(productKey,deviceName,timestamp,clientId), 按照字母顺序排序, 然后将参数值依次拼接其中clientId是客户端自表示id,建议mac或sn,64字符内;timestamp当前时间毫秒值,仅做混淆,可以不传递;mqttClientId格式中||内为扩展参数;signmethod代表签名算法类型,可支持hmacSha1,hmacSha256,hmacMd5;securemode代表目前安全模式,可选值有2 (TLS直连模式)、3(TCP直连模式;实例
如果clientId = 12345,deviceName = device, productKey = pk, timestamp = 789,signmethod=hmacsha1,deviceSecret=secret,那么使用tcp方式提交给mqtt参数分别如下:mqttclientId=12345|securemode=3,signmethod=hmacsha1,timestamp=789|username=device&pkpassword=hmacsha1("secret","clientId12345deviceNamedeviceproductKeypktimestamp789").toHexString(); //最后是二进制转16制字符串,大小写不敏感。 这个例子结果为 FAFD82A3D602B37FB0FA8B7892F24A477F851A14注意上面3个参数分别是mqtt Connect登录报文的mqttClientId,mqttUsername,mqttPasswrod设备端直接通过上发自定义二进制数据, 云端对上传上来的二进制数据直接进行解析(通过云端转换脚本, 需自行开发), 并转换为标准Alink协议数据的格式。而在下行时, 云端同样会通过经过解析, 把标准的Alink协议数据转换成二进制数据, 并发送到设备端。
透传相关的Topic定义如下,传输数据为二进制数据。
下行 Topic
设备端订阅Topic:/sys/{productKey}/{deviceName}/thing/model/down_raw
设备端回复Topic:/sys/{productKey}/{deviceName}/thing/model/down_raw_reply
上行 Topic
设备端发布Topic:/sys/{productKey}/{deviceName}/thing/model/up_raw
服务端回复Topic(需设备端订阅):/sys/{productKey}/{deviceName}/thing/model/up_raw_reply
设备直接构造对应Topic以及对应的json格式数据, 云端直接进行解析。
设备属性上报设备端发布Topic: /sys/{productKey}/{deviceName}/thing/event/property/postpayload:{ "id" : "123", "version":"1.0", "params" : { "Power" : "on", "WF" : "2" }, "method":"thing.event.property.post"}服务端回复Topic(需设备端订阅): /sys/{productKey}/{deviceName}/thing/event/property/post_replypayload:{ "id":"123", "code":200, "data":{}}异步模式下:
设备端订阅Topic: /sys/{productKey}/{deviceName}/thing/service/{tsl.service.identifer}payload:{ "id" : "123", "version":"1.0", "params" : { "Power" : "on", "WF" : "2" }, "method":"thing.service.{tsl.service.identifer}"}设备端回复Topic:/sys/{productKey}/{deviceName}/thing/service/{tsl.service.identifer}_replypayload:{ "id":"123", "code":200, "data":{}}同步模式下:
注: messageId请参考【同步调用】中具体描述
欢迎光临 (http://www.51hei.com/bbs/) | Powered by Discuz! X3.1 |