Android Question BLE2 enable notification success?

TnP

Member
Licensed User
Longtime User
Hi everyone,
I'm looking for a way to confirm that subscribing to a notification is successful or not using the BLE2 library?
When I enable a notification, I can see in the console the following, which I assume is being generated by the library's internal code:
B4X:
Setting descriptor. Success = true
writing descriptor: true

Is there a way for my App to access this? The reason for asking is I want to be sure and avoid having to add a delay between enabling multiple notifications.

Thanks!
 

TnP

Member
Licensed User
Longtime User
I haven't, no. I have been using fixed delays between subscribing to two different notifications so far and occasionally I notice they take longer to register than usual.
I was looking for a way to make absolutely sure they were enabled before proceeding instead of waiting a fixed time and hoping so.

Is my only solution at the moment to increase the delay time? (This isn't a problem if it is)
Thanks!
 
Upvote 0

TnP

Member
Licensed User
Longtime User
Apologies for dredging up an old thread, but it is a bit of a continuation of this thread.
Occasionally we are seeing :
B4X:
Setting descriptor. Success = true
writing descriptor: false

There are 3 notifications total in our app and enabling notifications goes something like this (rough log output):
B4X:
<300ms delay>
setting notification listener 1
Setting descriptor. Success = true
writing descriptor: true
<300ms delay>
setting notification listener 2
Setting descriptor. Success = true
writing descriptor: false
<300ms delay>
setting notification listener 3
Setting descriptor. Success = true
writing descriptor: false
<300ms delay>

Observations:
  • It seems that the descriptor set/write response is happening rather quickly after setNotify and there is plenty of delay until the next setNotify.
  • Typically, if I try again, it works (writing descriptor: true).
  • Every time I've seen this problem, it fails on the 2nd notification and subsequently the third.
  • Changing the order of the notifications doesn't make any difference.
  • I've only been able to reproduce this on a Galaxy S7 with Android 6. I've never been able to reproduce it on Galaxy S7 running Android 8.
Is there anything we can try to prevent this from happening? Or rather, I read somewhere that I can read the descriptor using javaObject? How would I go about that?
Do you think it would help if I read the descriptor and tried again upon failure?

Thanks in advance!
Terry
 
Upvote 0

TnP

Member
Licensed User
Longtime User
Sorry Erel, duly noted.
If you could do that, that would be great! Thank you
 
Upvote 0

TnP

Member
Licensed User
Longtime User
Fantastic, thank you!
I look forward to trying it out in the morning

EDIT: With this I was able to implement 3 retries for each step and it solved the issue. Thanks again Erel!
 
Last edited:
Upvote 0
Top