-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.js
49 lines (40 loc) · 1.29 KB
/
index.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
47
48
49
const configOptions = {
autoConnect: false,
debug: true,
timeout: false, // seconds
keepAlive: false,
autoFixConnect: true,
maxReconnectTimes: 5,
connectOptions: {
interval: 0,
services: [],
allowDuplicatesKey: false,
deviceName: 'YourDeviceName',
// characteristicId: '0000FFE1-0000-1000-8000-00805F9B34FB'
},
onFound (devices) {
console.log(devices)
},
onConnect () {
console.log(`now this bluetooth instance ${this.config.connectOptions.deviceName || this.uuid} has been becoming connected state.`)
// 如果 keepAlive 为真的话,需要自己手动在 sendData 成功后执行
// `return this.trigger('success', true)`
// 以触发 finish 状态以进入关闭蓝牙连接和蓝牙适配器操作
this.sendData('01').then(res => {
console.log(res)
wx.showToast({
title: '发送数据成功',
})
})
},
onNotify (value) {
console.log(`The value be notified is ${value}`)
},
onTimeout () {
console.log(`Sorry, current bluetooth ${this.config.connectOptions.deviceName || this.uuid} connect timeout.`)
},
onFail (error) {
console.log(`Sorry, current bluetooth ${this.config.connectOptions.deviceName || this.uuid} connect fail. Error info ${error}`)
}
}
export default configOptions