1、notify返回成功
2、write也返回成功
3、问题是onBLECharacteristicValueChange没回调,没有数据
wx.notifyBLECharacteristicValueChange({
deviceId: deviceId,
serviceId: bleServiceUUID,
characteristicId: character.uuid,
state: true,
type:'notification',
success(res) {
console.log('notification通知数据', res);
// 操作之前先监听,保证第一时间获取数据
console.log("监听设备返回数据--->"); //5d0000000001be304d
wx.onBLECharacteristicValueChange((res) =>{
console.log(`characteristic ${res.characteristicId} has changed, now is ${res.value}`)
var resData = ab2hex(res.value); //转16进制
console.log("设备返回数据--->", resData); //5d0000000001be304d
// that.closeBLEConnection(that._deviceId);
// that.closeBluetoothAdapter();
})
},
fail(res) {
console.log('notifyBLECharacteristicValueChange fali', res);
}
})
这是notify成功后调用wx.onBLECharacteristicValueChange监听
//类型转换
let buffer1 = new ArrayBuffer(2)
let dataView = new DataView(buffer1)
dataView.setUint8(0, 0x01)
// dataView.setUint8(1, 0x01)
wx.writeBLECharacteristicValue({
deviceId: this._deviceId,
serviceId: this._serviceId,
characteristicId: this._writeId,
value: buffer1,
success: (res) => {
console.log("写数据返回结果", res.errMsg);
//项目需求: 发送某个指令后的需要处理回调
// if (action == 'lastZero') {
// console.log('最后一次写入00需执行回调========》');
// //回调 目的: 执行调用提交接口
// eyeCareObj.eyeCareCallback();
// }
},
fail(res) {
console.log("写数据失败..", res);
// asddErrorCallback(res.errCode, "");
}
})这个是写入的代码
你好,麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,时间点