-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Library should timeout read / write operations in case of BLE stack misbehaviour #118
Comments
Hello @lowwor |
This is the log before the process stop. We can see that after the last writeCharacteristic operation, no corresponding onCharacteristicWrite is invoked, so the lib do nothing because of that, no further operation, and no onError onNext or onComplete is invoked at all. It looks like the phones problem not invoking the onCharacteristicWrite, but I think I should do something to take care of this kind of weird situation as well. |
Also, after that, further ble operation like writing or reading characteristic、disconnecting from the ble device take no effect at all. Only turning off the phone's bluetooth and open it again can make the ble work again. |
That's true. The library should timeout read / write operations after a reasonable time. We should dig through the BLE specification to check what is the maximum delay after which a device needs to acknowledge the operation. Btw. as a temporary workaround - what would happen if you would make the delay bigger? Like 100 ms? |
Yeah, tried that already. Everything is OK after increasing the delay ( like 200ms). But the minimum value varies from different devices, so I can't really tell what a safe delay is. Considering the risk and speed, I am now using a higher delay for general case and a lower delay for the devices tested as a white list. |
I think the issue may not lie in the BLE stack but in the peripheral you're talking to - perhaps it doesn't work fast enough to consume the next chunk of data. It lacks some flow control features. Maybe if it would inform the app by a notification that it is ready for the next chunk the problem could be solved. (But still the library should timeout operations after some time.) |
Yeah, the peripheral's processing capacity may be a factor for the problem of transfering data. But in this case, in fact, most phone don't have this kind of problem with the delay of 50ms and the peripheral can deal with the data correctly (tell from the ble device's serial port log) . So I blame the phone‘s (mostly Chinese OEM phone) poor ble stack for this problem. The flow control feature is a good idea and we have implemented it in another situation (say a different working mode of the ble device) like tranfering command data which may take time to process. But in this situation, the peripheral is more like a transparent proxy ( pass through data to elsewhere without doing anything), so to maximize the speed, we had decided to omit the flow control part. Anyway, I'm looking forward to the timeout feature and thanks for your kind support. |
I am looking into the topic. I have found this: http://stackoverflow.com/questions/30420137/writecharacteristic-returns-true-but-does-not-call-oncharacteristicwrite |
I have found that too when I searched for the topic.
And after using higher delay, I do a few check too.
So, I think it's not the same kind of problem. And I think it's really rare and abnormal that the phone can't even just send a single byte which I don't see on all the phone I tested. Following is the interval code and chunkify() code I use
chunkify()
|
@lowwor Sorry for a late response. So with a delay longer than 50 ms the code works without a problem? |
Yes, it is. |
I have a branch with added timeouts for all operations. It should be enough to keep the library working. |
Reviewers: pawel.urban Reviewed By: pawel.urban Differential Revision: https://phabricator.polidea.com/D2144
A fix was pushed to the master branch and should be available in the SNAPSHOT shortly. The library should no longer stop in case of the issue you have suffered. Best Regards. |
Thanks a lot for the great job! |
I have digged through the Bluetooth Specification to check if it has a maximum time for a device response specified. Actually the time varies by two factors - the time between the activities of the device and the number of the activities the device may skip but still consider the connection open. It roughly translates to a time between several milliseconds to 32 seconds (or so). The Android OS is considering a connection not being able to start after 30 seconds ( |
Understood, thanks! |
In some phone, when chunkifying data and sending them to ble device in sequence using the following code.
It's OK in the begining, but after sometime. Strange things happen. System's writeCharacteristic was called but onCharacteristicWrite was not called after that. And then the whole process stop. But RxAndroidBle was not throwing out exception.
I was wondering how can I handle such situation. Should the library provide a way to set operation timeout and notify this kind of error or anything I can do at the application level? Thanks.
The text was updated successfully, but these errors were encountered: