Alipay applet -MQTT simulator by WSS access Ali cloud IoT platform of Things
Applet effects:
1. Preparations
1.1 Registration Ali cloud account
Ali cloud account opened, and through the payment of treasure authentication www.aliyun.com
1.2 free open IoT Things kit
Products official website www.aliyun.com/product/iot
2. The console procedure
2.1 Create Product
JSON format
2.2 Product definition
Add product attributes temperature of temperature, humidity, humidity
2.3 Register Equipment
In the device product registration, obtain identity triples
3. Small program operation
3.1 on-line device
3.2 reporting data
3.3 Sub topics and data downlink
First click subscribe to a topic , go to the console push messages.
Issue instructions Log
Applet effect
4. applet development process
4.1 Alipay applet socket interface adapter
socket interface my.sendSocketMessage and my.onSocketMessage is the base64 string, does not support ArrayBuffer, it needs its own conversion
import miniBase64 from 'mini-base64';
miniBase64.arrayBufferToBase64()复制代码
4.2 IoT Ali cloud authentication signature
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();复制代码
This article Yunqi community original content may not be reproduced without permission.
Reproduced in: https: //juejin.im/post/5cf0ce70e51d4577407b1cd1