EspressifApp / EspBlufiForAndroid

EspBlufi is based on the BLUFI protocol, which connect with IOT devices for BLE data communication, realizes device config network, and custom data transmission and reception. EspBlufi is developed and maintained by Espressif Corp.
Other
322 stars 124 forks source link

mWriteLock.wait()卡死 #29

Closed zhubinsheng closed 2 years ago

zhubinsheng commented 3 years ago

synchronized (mWriteLock) { mWriteChar.setValue(data); mGatt.writeCharacteristic(mWriteChar); mWriteLock.wait(); } } finally { mWriteLock.unlock(); }

mWriteLock.unlock()依赖下面写入成功回调的notify,如果没有写入成功,将一直卡在了写入方法中,无法再次写入,应该增加写入超时机制 public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { synchronized (mWriteLock) { mWriteLock.notify(); }

XuXiangJun commented 3 years ago

一般来说 Gatt Write 不管成功或失败应该都会走 onCharacteristicWrite 回调,通过 status 来判断是否成功 如果一直等不到回调,即使设置超时解锁,后续的写操作也不会成功,这个时候实际上可以直接关闭这次 Gatt 连接了。 所以可以自己实现超时功能,一旦超时,调用 BlufiClient 的 close() 即可

XuXiangJun commented 2 years ago

lib 2.3.7 增加写超时