代码如下:
bindViewTap: function () {
var that = this;
wx.onBLECharacteristicValueChange(function (res) {
console.log(‘特征值变化’, res);
const CharacteristicVal = that.buf2hex(res.value);
if (res.characteristicId == that.data.wifi_uuid) {
that.setData({
device_char: CharacteristicVal
});
}
});
// 向蓝牙设备发送一个0x00的16进制数据
let buffer = new ArrayBuffer(1)
let dataView = new DataView(buffer)
dataView.setUint8(0, 0)
wx.writeBLECharacteristicValue({
deviceId: that.data.deviceId,
serviceId: that.data.wifi_data.service.uuid,
characteristicId: that.data.wifi_uuid,
value: buffer,
success: function (res) {
// success
console.log(“success 指令发送成功”);
console.log(res);
},
fail: function (res) {
// fail
console.log(res);
},
complete: function (res) {
// complete
wx.showModal({
title: ‘提示’,
content: res,
success: function (res) {
if (res.confirm) {
console.log(‘用户点击确定’)
} else if (res.cancel) {
console.log(‘用户点击取消’)
}
}
})
}
})
}
点击给设备发送一个16进制的数据,writeBLECharacteristicValue和onBLECharacteristicValueChange都没反应,咋回事??