-
Notifications
You must be signed in to change notification settings - Fork 44
/
app.js
46 lines (41 loc) · 1.41 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
_ _ __
| | (_) / _|
_ __ ___ __ _ | | __ _ _ __ __ _ | |_ _ _ _ __ __ __ _ _ ____
| '_ ` _ \ / _` || |/ /| || '_ \ / _` || _|| | | || '_ \ \ \/ /| | | ||_ /
| | | | | || (_| || < | || | | || (_| || | | |_| || | | | _ > < | |_| | / /
|_| |_| |_| \__,_||_|\_\|_||_| |_| \__, ||_| \__,_||_| |_|(_)/_/\_\ \__, |/___|
__/ | __/ |
|___/ |___/
*/
//app.js
import mqtt from './utils/mqtt.js';
const host = 'wxs://1v1r5ep.mqtt.iot.bj.baidubce.com/mqtt';
const options = {
protocolVersion: 4, //MQTT连接协议版本
clientId: randomString(10),
clean: true,
username: '1v1r5ep/zhihu_iamliubo',
password: 'tNVKODyl2chbm5yp',
reconnectPeriod: 1000,
connectTimeout: 30 * 1000,
resubscribe: true
};
App({
onLaunch: function() {
},
globalData: {
client_ID: randomString(10),
client: mqtt.connect(host, options),
},
})
function randomString(len) {
len = len || 32;
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
var maxPos = $chars.length;
var pwd = '';
for (let i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}