GTaylor
GTaylor
  • 发布:2021-07-05 15:41
  • 更新:2021-07-05 15:41
  • 阅读:789

蓝牙通信正常写入数据给蓝牙设备但提示写入错误,能监听到蓝牙设备返回数据的动作,但是监听结果为空

分类:uni-app

IOS启动蓝牙监听,写入数据报错。但是设备能正常接收。
错误如下:
send-error-{"errMsg":"writeBLECharacteristicValue:fail Error Domain=CBATTErrorDomain Code=14 \"Unlikely error.\" UserInfo={NSLocalizedDescription=Unlikely error.},https://ask.dcloud.net.cn/article/282","errCode":10007,"code":10007}

接收到的数据打印如下:
value-succ{"characteristicId":"0000FFE1-0000-1000-8000-00805F9B34FB","deviceId":"78E496C9-3688-8D6C-B60D-B17D69A597C1","serviceId":"0000FFE0-0000-1000-8000-00805F9B34FB","value":{}}

value 是空的,但是确实每次都监听到了。

实现代码如下。
await uni.notifyBLECharacteristicValueChange({
state: true, // 启用 notify 功能
deviceId,
serviceId,
characteristicId,
success: res => {
console.log('notify-succ:' + JSON.stringify(res));
that.iGlobal.uploadlog('notify-succ'+JSON.stringify(res))

                        uni.onBLECharacteristicValueChange((res2) => {  
                            console.log('value-succ:' + JSON.stringify(res2));  
                            that.iGlobal.uploadlog('value-succ'+JSON.stringify(res2))  
                        });  
                    },  
                    fail: err => {  
                        console.log('notify-failed:' + JSON.stringify(err));  
                        that.iGlobal.uploadlog('notify-failed'+JSON.stringify(err))  
                    }  
                });  

写入代码如下。

that.iBluetooth.writeBLECharacteristicValue(encoded)
.then(res => {
that.iGlobal.uploadlog('woshou-'+JSON.stringify(res))
that.iGlobal.addCache('selectBlueTooth',that.iBluetooth,30 * 36000);

                        //跳入操作页面  
                        setTimeout(() => {  
                            that.iGlobal.togo2('../../pages/index/index')  
                        },200);  

                    })  
                    .catch(error => {  
                        that.iGlobal.uploadlog('woshou-'+JSON.stringify(error))  
                        that.iGlobal.addCache('selectBlueTooth',that.iBluetooth,30 * 36000);  

                        //跳入操作页面  
                        setTimeout(() => {  
                            that.iGlobal.togo2('../../pages/index/index')  
                        },200);  
                        //this.iGlobal.showToast('握手失败');  
                    });
2021-07-05 15:41 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复