iDevicesInc / SweetBlue

BLE on Android, the easy way. THIS IS NOW DEPRECATED. Please visit website for info on new versions.
https://sweetblue.io
GNU General Public License v3.0
357 stars 57 forks source link

Writing data issues on One Plus 5 #351

Open linkinamine opened 7 years ago

linkinamine commented 7 years ago

The sdk was tested on various devices Samsung Samsung S5 S6 S7 and Sony Xperia Z3, Huawei P8, LG G4, Nexus5 and seems to be working good for typical use cases : Scan, connect, read, write. However while testing on One plus 5 the scan takes a long time and fails multiple times, and the writing times out


       status     = TIMED_OUT                                                      
      data =  20 bytes data 
      type       = WRITE_NO_RESPONSE
      gattStatus = GATT_STATUS_NOT_APPLICABLE(-1)
 uhOh Got WRITE_TIMED_OUT with remedy WAIT_AND_SEE```
ryanhubbell commented 7 years ago

Could you explain what the issue is? I don't know what you mean by writing data issues. Please be specific on the problem you're having.

linkinamine commented 7 years ago

Done comment updtated so I am writing a 20 bytes key to BT device and in all other mentionned phones it worked seamlessily, in the one plus 5 I kept getting the aforementionned error.

ryanhubbell commented 7 years ago

Is the characteristic you're writing to actually a WRITE_NO_RESPONSE?

linkinamine commented 7 years ago

yes it is a WRITE_NO_RESPONSE .

Petrulak commented 7 years ago

Just to give a little bit more context about the issue. The scenario is that we are connecting to a ring lock, which is mounted on a bike. We are opening it and closing it afterward.

This scenario consists of several steps, which are being done in code our code:

  1. Scan & connect to the device.
  2. Enable notifications, to get the change of the state.
  3. Write secret token (5x20 bytes) to activate the lock.
  4. Write OPT (20 bytes) which opens the lock.
  5. Write OPT (20 bytes) which closes the lock.

Step 5. (closing the lock) sometimes takes pretty long time on One Plus 5 or it doesn't work at all. It works fine with Nexus 5, Nexus 5X, Moto G2/3, Samsung S5/S6/S7/S8, Huawei P8, LG G4 and Sony Xperia Z3 so we are assuming that there is some issue with One Plus 5

Please see the logs for writing which took around 7 seconds.

08-30 12:03:24.252 5461-5461/one.noatech.rider.debug I/NoaBleSdk: writing : 54120E4F0FEBB6CC122AF52683261DDFFA069C3E
08-30 12:03:24.254 5461-5461/one.noatech.rider.debug I/P_TaskQueue: MAIN print() - Read(EXECUTING axa:5af8d57c4f83b8284cbd_94AD 00001524-e513-11e5-9260-0002a5d5c51b txn==null 181460627 ) [Write(QUEUED axa:5af8d57c4f83b8284cbd_94AD 00001525-e513-11e5-9260-0002a5d5c51b txn!=null 76819016 )]
08-30 12:03:29.496 5461-5461/one.noatech.rider.debug W/BleManager: MAIN update() - Update loop took longer to run than the current interval of 20ms
08-30 12:03:31.436 5461-10322/one.noatech.rider.debug W/BluetoothGatt: onCharacteristicRead() - Device=CC:EC:9D:3D:94:AD handle=14 Status=0
08-30 12:03:31.437 5461-5461/one.noatech.rider.debug I/P_BleDevice_Listeners: MAIN onCharacteristicRead_updateThread() - char=00001524-e513-11e5-9260-0002a5d5c51b
08-30 12:03:31.437 5461-5461/one.noatech.rider.debug I/P_BleDevice_Listeners: MAIN onCharacteristicRead_updateThread() - GATT_SUCCESS(0) 
08-30 12:03:31.438 5461-5461/one.noatech.rider.debug I/PA_Task: MAIN setState() - Read(SUCCEEDED axa:5af8d57c4f83b8284cbd_94AD 00001524-e513-11e5-9260-0002a5d5c51b txn==null 181460627 ) - 8112

Logs for failed transaction:

08-30 13:24:41.205 18693-18693/one.noatech.rider.debug I/NoaBleSdk: writing : 551267E366516B0EBE8DDC52A075CD72B8BDA531
08-30 13:24:41.206 18693-18693/one.noatech.rider.debug I/P_TaskQueue: MAIN print() - no current task [Write(QUEUED axa:de6da6eba2d77c35b738_4F7F 00001525-e513-11e5-9260-0002a5d5c51b txn!=null 177397517 )]
08-30 13:24:41.222 18693-18693/one.noatech.rider.debug D/BluetoothManager: getConnectionState()
08-30 13:24:41.222 18693-18693/one.noatech.rider.debug D/BluetoothManager: getConnectedDevices
08-30 13:24:41.227 18693-18693/one.noatech.rider.debug I/P_TaskQueue: MAIN print() - Write(EXECUTING axa:de6da6eba2d77c35b738_4F7F 00001525-e513-11e5-9260-0002a5d5c51b txn!=null 177397517 ) [queue empty]
08-30 13:24:44.839 18693-18750/one.noatech.rider.debug I/DpmTcmClient: RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
08-30 13:24:46.635 18693-18693/one.noatech.rider.debug D/P_BleManager_Listeners$2: MAIN onReceive() - 
08-30 13:24:48.104 18693-18693/one.noatech.rider.debug I/P_TaskQueue: MAIN print() - Write(EXECUTING axa:de6da6eba2d77c35b738_4F7F 00001525-e513-11e5-9260-0002a5d5c51b txn!=null 177397517 ) [Read(QUEUED axa:de6da6eba2d77c35b738_4F7F 00001524-e513-11e5-9260-0002a5d5c51b txn!=null 99499279 )]
08-30 13:24:53.749 18693-18693/one.noatech.rider.debug I/PA_Task: MAIN setState() - Write(TIMED_OUT axa:de6da6eba2d77c35b738_4F7F 00001525-e513-11e5-9260-0002a5d5c51b txn!=null 177397517 ) - 9097
08-30 13:24:53.751 18693-18693/one.noatech.rider.debug W/P_Task_Write: MAIN onStateChange() - char=00001525-e513-11e5-9260-0002a5d5c51b write timed out!
08-30 13:24:53.753 18693-18693/one.noatech.rider.debug W/P_UhOhThrottler: MAIN uhOh() - WRITE_TIMED_OUT
08-30 13:24:53.777 18693-18693/one.noatech.rider.debug D/BluetoothManager: getConnectionState()
08-30 13:24:53.777 18693-18693/one.noatech.rider.debug D/BluetoothManager: getConnectedDevices
08-30 13:24:53.785 18693-18693/one.noatech.rider.debug I/P_TaskQueue: MAIN print() - Read(EXECUTING axa:de6da6eba2d77c35b738_4F7F 00001524-e513-11e5-9260-0002a5d5c51b txn!=null 99499279 ) [queue empty]
08-30 13:24:53.788 18693-18693/one.noatech.rider.debug I/PA_Task: MAIN setState() - Read(FAILED axa:de6da6eba2d77c35b738_4F7F 00001524-e513-11e5-9260-0002a5d5c51b txn!=null 99499279 ) - 9097
08-30 13:24:53.790 18693-18693/one.noatech.rider.debug I/P_TaskQueue: MAIN print() - no current task [queue empty]
08-30 13:24:53.792 18693-18693/one.noatech.rider.debug W/BleManager: MAIN update() - Update loop took longer to run than the current interval of 20ms
08-30 13:24:53.793 18693-18693/one.noatech.rider.debug E/NoaBleSdk: Writing failed!
08-30 13:24:53.794 18693-18693/one.noatech.rider.debug I/BleTransaction: MAIN end() - transaction FAILED
ryanhubbell commented 6 years ago

For a test, try bonding before connecting to the OnePlus 5. Some phones need to be bonded in order for them to work correctly (even if you're not using default bluetooth bonding/pairing).

dtingz commented 6 years ago

"try bonding before connecting to the OnePlus 5" did it help?