Skip to content
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

BLEClientCharacteristic events for "indicate" notifications #113

Closed
savageautomate opened this issue Jan 12, 2018 · 10 comments
Closed

BLEClientCharacteristic events for "indicate" notifications #113

savageautomate opened this issue Jan 12, 2018 · 10 comments
Milestone

Comments

@savageautomate
Copy link

How does one receive events for "indicate" notifications on a CHARACTERISTIC?
I tried using the BLEClientCharacteristic::setNotifyCallback() method, but I'm not seeing any callback invocations for indicated events. I am seeing the following debug statements printed:

[BLE   ] BLE_EVT_TX_COMPLETE : Conn Handle = 0
[BLE   ] BLE_GATTC_EVT_HVX : Conn Handle = 0

In looking at the code, I see a placeholder in BLEClientCharacteristic.h for:

typedef void (*indicate_cb_t) (BLEClientCharacteristic& chr, uint8_t* data, uint16_t len);

But there is no method to establish the callback function pointer such as:
void setIndicateCallback(indicate_cb_t fp);

Also in BLEClientCharacteristic.cpp::_eventHandler(ble_evt_t* evt), there is no BLE_GATTC_EVT_HVX type handler for BLE_GATT_HVX_INDICATION, only BLE_GATT_HVX_NOTIFICATION.
(https://devzone.nordicsemi.com/documentation/nrf51/4.4.0/html/group___b_l_e___g_a_t_t___h_v_x___t_y_p_e_s.html)

I'm new to this, so my assumptions above may be wrong, but I'm just struggling to try and get events for a characteristic on an embedded device that only uses INDICATE and not NOTIFY.

Thanks!

@hathach
Copy link
Member

hathach commented Jan 13, 2018

We are glad that you ask, the indicate haven't used so far. So we forgot to add it to the API. We will include it (first in the develop branch), then in the next release.

@hathach hathach added this to the 0.9.0 milestone Jan 13, 2018
@hathach
Copy link
Member

hathach commented Jan 13, 2018

PS: We are planning to change the signature of callback for better deferred with adacallback as well.

@savageautomate
Copy link
Author

Great, looking forward to testing the fix. Thanks!

@hathach hathach modified the milestone: 0.9.0 Jan 17, 2018
@hathach
Copy link
Member

hathach commented Jan 18, 2018

we just pushed the new code to branch 0.8.x that implement the indicate callback.
If you could test it out, we will include it in the next release.

https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/0.8.x/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.h#L104

Note: the callback signature is changed from using Reference to pointer. This allow easy integration to ada callback. Which is a separate thread used for all the callback. setNotifyCallback() / setIndicateCallback() has optional parameter that you could choose whether callback should be called in callback thread or main ble thread (blocking other event).

https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/0.8.x/libraries/Bluefruit52Lib/src/BLEClientCharacteristic.h#L50

@hathach
Copy link
Member

hathach commented Jan 18, 2018

There are cases where you want a callback is called in main ble thread. E.g you are in characteristic A's callback (in callback thread) and waiting for another event of characteristic B's callback. Therefore A's callback and B's callback must be on separate threads (ble & callback thread). Otherwise it will go into deadlock.

@hathach hathach modified the milestones: 0.9.0, 0.8.2 Jan 18, 2018
@savageautomate
Copy link
Author

I spent a few minutes today setting up my environment for testing the development brach (0.8.x) locally. On a first cursory attempt ... I am now receiving characteristic indication events issued by a BLE (hardware) device.

I'll spend a little more time tomorrow digging in a bit further .. but initial test is all good!

Thank You

@hathach
Copy link
Member

hathach commented Jan 19, 2018

Thanks, we are looking forward to hear from your testing. Once it is done, we will release it as 0.8.2 . Bug discovered later will fire as separate bug/issue.

@hathach
Copy link
Member

hathach commented Jan 22, 2018

we will release the code as 0.8.2 and close this issue, please file an different issue as bug if you have any troubles with this.

@hathach hathach closed this as completed Jan 22, 2018
@savageautomate
Copy link
Author

In my limited testing over the weekend it all seemed to work fine.
Thanks again for the quick fix.

@hathach
Copy link
Member

hathach commented Jan 23, 2018

@savageautomate thanks for your confirmation. It is good enough to roll out for other folks to test with :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants