代码拉取完成,页面将自动刷新
const { mqttMatch } = require("./dist/alibabacloud-iot-device-sdk")
// app.js
App({
onLaunch() {
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
//调用mqtt
var iot = require('./dist/alibabacloud-iot-device-sdk.js');
const sdk_device = {
"productKey": "a1QZ2VjPWD5",
"deviceName": "GROZA_YYDS",
"deviceSecret": "ea6ab3ba58ad22668c295ce45cbd59cd",
"protocol": 'wxs://',
}
// 和云端建立连接,返回一个 `Device` 连接实例
let device = iot.device(sdk_device);
device.on('message', (topic, payload) => {
//console.log('topic:',topic);
if(payload){
console.log('payload',payload.toString());
this.globalData.payload2 = payload
}
});
device.on('connect', () => {
console.log('>>>>>connect');
device.subscribe('/a1aq9sQk2JE/sdk_device3/user/forward');
setInterval(()=>{
let jsonString = JSON.stringify({ "a":"hello"});
device.publish('/a1aq9sQk2JE/sdk_device3/user/userpost',jsonString );
},8000)
});
},
globalData: {
userInfo: null,
payload2:'',
}
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。