小程序效果:
小程序
開通阿里雲帳號,並經過支付寶實名認證 https://www.aliyun.comdom
產品官網 https://www.aliyun.com/product/iot
socket
JSON格式
阿里雲
添加產品屬性溫度 temperature,溼度 humidity
spa
在產品下注冊設備,得到身份三元組
3d
先點擊 訂閱主題,再去控制檯推送消息。
日誌
發佈指令日誌
code
小程序效果
blog
socket接口my.sendSocketMessage和my.onSocketMessage都是base64的string,不支持ArrayBuffer,須要本身轉換接口
import miniBase64 from 'mini-base64'; miniBase64.arrayBufferToBase64()
const params = { productKey: pageThat.data.productKey.trim(), deviceName: pageThat.data.deviceName.trim(), deviceSecret: pageThat.data.deviceSecret.trim(), timestamp: Date.now(), clientId: Math.random().toString(36).substr(2), } //1.生成clientId,username,password const contentStr = "clientId" + params.clientId + "deviceName" + params.deviceName + "productKey" + params.productKey + "timestamp" + params.timestamp; var clientId = `${params.clientId}|securemode=2,signmethod=hmacsha1,timestamp=${params.timestamp}|`; var username = `${params.deviceName}&${params.productKey}`; var password = crypto.HmacSHA1(contentStr, params.deviceSecret).toString();
本文做者:wongxmig
本文爲雲棲社區原創內容,未經容許不得轉載。