var buffer = new ArrayBuffer(16)
var dataView = new DataView(buffer)
var str = ‘0xd3,0x80,0x60,0x79,0x76,0xc9,0xdd,0x46,0xe5,0x18,0xf4,0x31,0xf6,0x4e,0xb6,0x44’;
var arr = str.split(’,’)
var val;
for (var i = 0; i < arr.length; i++) {
val = parseInt(arr[i], 16)
dataView.setInt8(i, val);
}
wx.writeBLECharacteristicValue({
deviceId: that.data.deviceId,
serviceId: that.data.services,
characteristicId: that.data.characteristicsFEC7,
value: buffer,
success: function (res) {
console.log(res,‘writeBLECharacteristicValue success’);
//启用低功耗蓝牙设备特征值变化时的 notify 功能
wx.notifyBLECharacteristicValueChanged({
deviceId: that.data.deviceId,
serviceId: that.data.services,
characteristicId: that.data.characteristicsFEC8,
state: true,
success: function (res) {
console.log(“notifyBLECharacteristicValueChanged”, res);
},
fail: function (res) {
console.log(“uuid ble cvc fail>>>>>>>888888888”, res);
},
});
// 必须在这里的回调才能获\
setTimeout(function(){
wx.onBLECharacteristicValueChange(function (characteristic) {
console.log(‘onBLECharacteristicValueChang:’, characteristic);
const base64 = Array.prototype.map.call(new Uint8Array(characteristic.value), x => (‘00’ + x.toString(16)).slice(-2)).join(’’);
console.log(base64)
})
},3000)
setTimeout(function(){
//读取低功耗蓝牙设备的特征值的二进制数据值
wx.readBLECharacteristicValue({
deviceId: that.data.deviceId,
serviceId: that.data.services,
characteristicId: that.data.characteristicsFEC9,
success: function (res) {
console.log(‘readBLECharacteristicValue++++++++++++++++++++++:’, res)
},
fail: function (res) {
console.log(‘readBLECharacteristicValue fail:’, res)
},
})
},3000)
},
fail: function (res) {
console.log(res,‘buff fail’)
}
})
readBLECharacteristicValue成功后不应该返回两个参数吗
characteristic | object | 设备特征值信息 |
errMsg | string | 成功:ok,错误:详细信息 |
我怎么都没有characteristic这个参数
只有errMsg与errcode ++++加号后面的是我的返回值