我正在使用网络 BLE。我根据心率测量的示例建立了我的代码。
大多数时候一切都运行良好。但有时,即使连接成功,当我尝试绑定通知时,它也不起作用。
链接是在这个函数中建立的:
_startNotifications(characteristicUuid) {
let characteristic = this._characteristics.get(characteristicUuid);
console.log(characteristic);
return characteristic.startNotifications().then(() => characteristic);
}
当一切正常时,我可以在控制台中看到BluetoothRemoteGATTCharacteristic
一个value : DataView(2) {}
否则,当它不工作时,它有一个value : null
如果我检测到该值为空,我希望能够自动重试。但我对 Promise 不熟悉(我认为就是这样),console.log(characteristic.value)
在这里不起作用。
你会如何处理这个?