小程序连接低功耗蓝牙流程
参考官方api:https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth/wx.openBluetoothAdapter.html
1、初始化蓝牙模块,主要检查用户设备支持蓝牙或是否开启蓝牙(wx.openBluetoothAdapter)
2、监听蓝牙适配器状态(wx.onBluetoothAdapterStateChange)
3、开始搜索附近蓝牙设备(wx.startBluetoothDevicesDiscovery)
4、发现外围设备,返回deviceId设备id,取出要用的id并保存便于下面流程使用,(wx.getBluetoothDevices)
5、连接低功耗蓝牙设备(wx.createBLEConnection)
6、连接成功之后,一定要停止搜索外围设备,一定!如不然消耗过大(wx.stopBluetoothDevicesDiscovery)
7、获取蓝牙服务UUID,有多个具体看需要那个(wx.getBLEDeviceServices)
8、获取蓝牙特征值一般分为读和写(wx.getBLEDeviceCharacteristics)
9、监听特征值变化(wx.notifyBLECharacteristicValueChange)
10、像蓝牙发送消息或读取消息(wx.writeBLECharacteristicValue),(wx.readBLECharacteristicValue)
let p = new Promise((resolve,reject)=>{
resolve()
console.log("0")
wx.openBluetoothAdapter({ // 调用 手机蓝牙
success: function (res) {
console.log("初始化蓝牙适配器成功")
wx.onBl