微信小程序 蓝牙的实现实例代码
微信小程序 蓝牙的实现实例代码1.简述蓝牙适配器接口是基础库版本 1.1.0 开始支持。 iOS 微信客户端 6.5.6 版本开始支持,Android 客户端暂不支持 蓝牙总共增加了18个api接口。 2.Api分类搜索类 连接类 通信类 3.API的具体使用详细见官网: https://mp.weixin.qq.com/debug/wxadoc/dev/api/bluetooth.html#wxgetconnectedbluethoothdevicesobject 4. 案例实现4.1 搜索蓝牙设备 // const canIUse = apiName => {
// if (apiName === 'showModal.cancel') { // return MAJOR >= 1 && MINOR >= 1 // } // return true // } // wx.showModal({ },fail: function(res) { wx.getBluetoothDevices({ },onShow:function(){ },//点击事件处理 var title = e.currentTarget.dataset.title; 4.2连接 获取数据 })
/**
* 顺序开发设备特征notifiy
*/
wx.notifyBLECharacteristicValueChanged({
deviceId: that.data.deviceId,serviceId: that.data.serviceId,characteristicId: that.data.cd01,state: true,success: function (res) {
// success
console.log('notifyBLECharacteristicValueChanged success',res);
},fail: function (res) {
// fail
},complete: function (res) {
// complete
}
})
wx.notifyBLECharacteristicValueChanged({
deviceId: that.data.deviceId,characteristicId: that.data.cd02,characteristicId: that.data.cd03,complete: function (res) {
// complete
}
})
wx.notifyBLECharacteristicValueChanged({
// 启用 notify 功能
// 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
deviceId: that.data.deviceId,characteristicId: that.data.cd04,success: function (res) {
console.log('notifyBLECharacteristicValueChanged success',res)
}
})
},fail: function (res) {
console.log(res);
}
})
},1500);
}
})
},fail: function (res) {
// fail
},complete: function (res) {
// complete
}
})
},/**
},/**
5.效果展示发送校验指令。获取结果 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |