蓝牙控制器连接成功,第一次通讯是正常的,但是在连接状态下再次跟蓝牙通讯,就会出现,写数据成功,但是接收不到设备返回给我的数据

(不知道是不是跟写的顺序有关,但是他是有时候可以接受到,有时候接收不到,有没那个哥们遇到过同样的问题呢)

getTargetCharacteric: function (serviceid) {

var that = this

wx.getBLEDeviceCharacteristics({

deviceId: that.data.connectedDeviceId,

serviceId: serviceid,

success: function (res) {

console.log('设置写监听:', res.characteristics[0].uuid)

console.log("判断是否支持notify和write操作");

console.log(res.characteristics[0].properties);

that.setData({

serviceId: serviceid,

writecharacId: res.characteristics[0].uuid

})


// //写入开始命令

var code = that.getstate_params();

wx.notifyBLECharacteristicValueChange({

state: true, // 启用 notify 功能

deviceId: that.data.connectedDeviceId,

serviceId: serviceid,

characteristicId: res.characteristics[0].uuid,

success: function (res) {

console.log('监听蓝牙notify服务成功 characteristicId')

that.data.mJianHuStatus = 2;

setTimeout(function () {

that.writeBleData(code);

that.recieveequ();

}, 1000)

},

fail: function (res) {

console.log('监听notify服务失败')

that.data.mJianHuStatus = 0;

}

})


}

})

},

/**

  * 监听蓝牙获取的数据

  * */

recieveequ: function () {

var that = this

wx.onBLECharacteristicValueChange(function (characteristic) {

that.data.mJianHuStatus = 0;

let buffer = characteristic.value

console.log("接收解密前的数据为:hex==" + Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join(''))

var tmpStrr = Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');

that.dataHandle(tmpStrr);

})


},


展开全部
收起
0回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部