BluetoothRemoteGATTCharacteristic.startNotifications() does not capture indications. #5421
Replies: 1 comment
-
Posted at 2022-07-12 by Mark_M Actually it works. I had to add in another place in Android to capture and process indications requests. Posted at 2022-07-12 by Mark_M Well. Actually it does not work. Additionally to setting PROPERTY_INDICATE to the characteristc, the actual notification call BluetoothDevice.notifyCharacteristicChanged had hardcoded confirm=false parameter.
Do I have to send indication acknowledgements from the Bangle code, like from the event handler that is my updateTime(event) func? If so how to do it? Posted at 2022-07-13 by @gfwilliams So you're saying that if in android you choose to send indications, with It's entirely possible that Espruino doesn't send a response for indications automatically - Notifications seem to be the preferred options, with Indications kind of a legacy thing, so as a result extremely few people use them. If you can show me what needs to be added in Espruino to get this working then I'm happy to include it, however as it seems you control both sides of this connection, unless there's a very good reason to use indications you may be better off using Notifications as that does seem to be the preferred way to do this kind of thing in Bluetooth now anyway. Posted at 2022-07-13 by Mark_M Hi Gordon, In my case I control the both sides. But I want to make the sides maximally standard. For example my Bangle "Speed display" should work not only with mine Android GATT Location and Navigation service but with any other GATT Location and Navigation service that other GNSS devices can provide.
The Server should use indications in other transactions as well, where Client writes values to the server, for example - "The response shall be indicated when the route has been selected using the Response Code Op Code, the Request Op Code along with “Success” or other appropriate Response Value." I've found a good article with clarification of how the confirmations work. So, it looks like the App should issue the confirmation. I assume it should be done from a notification/indication handler function. Posted at 2022-07-14 by @gfwilliams Thanks! Yes, it looks like Posted at 2022-07-14 by Mark_M Great! Just one thing. I read different opinions how the confirmation should work: I thought C should be universally cover all cases. But, of course, it will require to manually place the confirmation call. Which is not a big deal. On the diagram from KBA_BT_0104: Acknowledged vs Unacknowledged GATT operations Posted at 2022-07-15 by @gfwilliams I think as far as Bluetooth is concerned, Espruino is the 'app'. Doing it in the handler matches what we do for other Bluetooth events too (eg write response), and also what other Nordic example code does. IMO it's got to be 'A'. We can't have just the first indication sending and then subsequent ones just not working without any warning to the user - that's going to be extremely frustrating for pretty much all users. ... and even if you did send a response in JS, if for some reason your code had an exception before calling it, it'd 'lock up' the connection until you reconnected. Posted at 2022-07-15 by Mark_M 'A' does make sense.
Response "After Done" will serve scenarios where processing of a message may take time. So it will prevent flooding the Client by too frequent indications. Otherwise some additional synchronization logic should be done, like skipping next coming indications if a current one is still in processing. Posted at 2022-07-18 by @gfwilliams Yes, it could be more flexible (but also super easy for someone to have it just 'not work')... However it seems you're the first person to use indications with confirmations in 5+ years or someone else would have reported issues, so while it's really good to fix it, I feel like it's probably not worth putting too much extra development work into ;) If someone comes along and actually really needs the functionality then it could be added, but right now there are definitely higher priority things :) Posted at 2022-07-18 by Mark_M I am confused. Does it mean that "auto-confirmation" is implemented starting with build 2v14.52 and you, for time being, just do not want to change it to the "manual confirmation"? Posted at 2022-07-19 by @gfwilliams
That's correct, yes :) Posted at 2022-07-21 by Mark_M Hi Gordon,
Posted at 2022-07-22 by @gfwilliams Argh, sorry about that - I've just put a fix in so it should be sorted in 2v14.65 For now, Posted at 2022-07-22 by Mark_M Great! The warning gone with the workaround. Posted at 2022-07-26 by @gfwilliams Sorry - I see this here now too. I've just put fix in, and it should be in espruino_2v14.91_banglejs2.zip Posted at 2022-07-26 by Mark_M You are SUPER! Posted at 2022-11-25 by @yerpj Supporting confirmations seems great ! I didn't test it but it could happen soon. By the way, I just wondered, is there any way for the application that just sent an Indication packet ( Posted at 2022-11-28 by @gfwilliams I don't think there's anything in there at the moment. If the nRF SDK actually exposes an event when the response to an indication is received then it could almost certainly be exposed somewhere in JS though. Posted at 2022-11-29 by @yerpj it looks like something is done here. Moreover, in release 2v15, the changelog says Posted at 2022-11-29 by @yerpj Actually I misunderstood the behavior of the BLE stack. Posted at 2022-11-30 by @gfwilliams You could try just adding a handler here and see what happens? https://github.com/espruino/Espruino/blob/5be68a80baeca1ab4e6ab31b9d78244afd2092c1/targets/nrf5x/bluetooth.c#L1445 Even if you only printed to the console you might be able to see if it is at least getting called? Posted at 2022-11-30 by @yerpj The modification has been done in this way:
Everytime an Now I just need to understand how to update this in order to be able to react on this event on the JS layer. If anyone has a clue, Please share :-) Posted at 2022-12-01 by @gfwilliams Looks from that mod like you're just responding to But I'd create a new BLE_INDICATION (or similar) enum and then do Posted at 2022-12-01 by @yerpj Sorry I just mixed up the 2 events actually. here is a proposal: espruino/Espruino#2299 Feel free to reject it and ask me to modify it if needed. Usage:
Posted at 2022-12-02 by @gfwilliams Thanks! That's great! As mentioned on the PR I don't think I'll merge as is (it breaks the nRF51 builds that don't include central mode) but it's a great starting point, and when I get a second I'll tweak it to send the event on the characteristic that's been changed. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2022-07-12 by Mark_M
The BluetoothRemoteGATTCharacteristic.startNotifications() works fine when in Android program I configure characteristic to send notifications (PROPERTY_NOTIFY).
Bangle does not receive anything when I set to send indications (PROPERTY_INDICATE)
Android code:
Bangle code:
Am I doing something wrong?
Is there a way to receive indications?
Beta Was this translation helpful? Give feedback.
All reactions