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
Characteristic notification data automatically sent back to the device #60
Comments
Hello @vicobz, waitForNotification(characteristic)
.trigger(writeCharacteristic(characteristic, YYYs))
.with((device, data)->Log.i(TAG, "Data sent to device ... " + data))
.done(device-> Log.i(TAG, "onWriteDone")
.enqueue()
waitForNotification(characteristic)
.trigger(writeCharacteristic(characteristic, AAAs))
.with((device, data)->Log.i(TAG, "Data sent to device ... " + data))
.done(device-> Log.i(TAG, "onWriteDone")
.enqueue() If notification should be received before the new write, this should fix the issue, unless there's a bug in the library. However, if you indeed want to write independently from receiving notifications, than the problem lies on the Android side. As you are using the same characteristic to write and received data, both operations (write and notify) share the same |
Hello @philips77, thanks again for your quick reply. Our protocol does not require to wait for a notification receipt before writing the next message. The data value should be considered as independent even if in some cases, the device can reply through a notification with the same data. But from the app to the device, I never reply with the same exact data. To precise the logs a bit:
I don't think this could solve the issue as there is no direct link between write attempts and notification receipt at BLE level. It still seems strange that these AAAs are sent back anyway. |
@philips77 I just updated my last reply |
There is a direct link in Android. To send data you do: characteristic.setValue(AAA);
gatt.writeCharacteristic(characterstic); Then you will receive When the notification is received you get characteristic.setValue(AAA); but before the data were obtained from it and sent to controller. The notification will overwrite the data in |
Yes, I implemented the same features directly with the Android BLE SDK and thus used to implement those methods & callbacks before using your library ;) So, when you say:
... looking at the logs example & keeping in mind that I never try to write 1 - call characteristic.setValue(YYY);
gatt.writeCharacteristic(characteristic); 2 - Receive a notification with characteristic.setValue(BBB);
gatt.writeCharacteristic(characteristic); 4 - The instruction 3 value ( In that case, why would my Splitting communication into two characteristics is not an option in our case, and waiting for notification before writing is either not suitable as the device waits for the app to write on its characteristic before replying. |
It's rather like that:
|
Okay so I think we agree on this, but as I told you in my replies I never call by myself Anyway, I discussed with our embedded software team and we chose to decouple the characteristic into two as you advised: a first one for writing and a second for notification, and this works well. Android should improve that BLE stack and provide developers with quality documentation and guidelines... Thanks for your time and this great library! |
Thanks to both for the insightful description and comments. We are facing the same issue and I was absolutely baffled until i read these issue in detail. Let's see how we fix it, because we can't split the characteristic. @philips77 is there a ticket in Android's big tracker system? It sounds like it should be easy to fix on their side, so I wonder if they are aware |
Hi,
I use this nice library to connect to a Nordic device and subscribe to notifications from one specific characteristic.
To communicate in both ways, I (the Android app) receive notifications from the characteristic and when I need to send a message, I write to that characteristic and the device replies with the same exact data.
Multiple issues were fixed from 2.0.1 & 2.0.3 releases.
However, I'm still facing something weird. I sometimes receive a notification from the Nordic device and then, I can see in logs that the exact same data is automatically written to the device, without no link with my own code, meaning I'm not sending any write request for that specific message.
Unfortunately, this issue breaks the communication protocol between our Nordic device and the Android app as we rely on a specific sequence order.
Here are some logs:
All values have been changed , but the issue is visible with the AA-AA-AA-AA-AA-AA-AA-AA-AA-AA message.
I receive a notification with this value on line 8, and that same frame is automatically sent back to the device, visible on line 11, but I didn't chose to send this message from my code.
Thanks
The text was updated successfully, but these errors were encountered: