SimpleBLE icon indicating copy to clipboard operation
SimpleBLE copied to clipboard

Expose peripheral handle in notification and indication callback functions

Open eriklins opened this issue 3 years ago • 9 comments

I'm working on a (graphical) application which scans for adverts and can connect to one or more devices which are displayed in one or more windows/dialogs, showing the gatt structure and allowing to read, write and subscribe to notification/indications etc. Since I don't know about the gatt structure and how many characteristics of each device support notifications (or indications), I (need to) use one callback for all subscriptions. This is not an issue when having just one device since the service and characteristic uuids exposed in the callback can be considered unique. But this is no longer the case when connecting to two similar devices simultaneously which expose the same gatt structure and uuids. It's no longer possible to determine which device gave the notification from just the service and characteristic uuid in the callback. So, would be great (necessary) to have access to the peripheral handle in the notification and indication callback, similar to the other callbacks. Thanks!

eriklins avatar Feb 14 '23 22:02 eriklins

That's a great idea!

kdewald avatar Feb 15 '23 02:02 kdewald

Did you have a chance to look into this...?

eriklins avatar Aug 04 '23 08:08 eriklins

Couldn't the userdata be used to pass the peripheralHandle?

KlemenDEV avatar Dec 20 '23 11:12 KlemenDEV

Hello @kdewald , just wanted to emphasize this missing feature, since it definitely limits the use of SimpleBLE for any application where we would want to connect and interact with identical devices exposing the same GATT table configuration. It's not possible to identify which device did throw a notification or indication based on what's currently exposed in the callback functions. We just get the service UUID and characteristic UUID and those would be the same for devices with same GATT configuration. Exposing the mac address as an additional parameter (or at least in the *userdata) would solve this. Or just exposing the simpleble_peripheral_t (as is the case for connect/disconnect callbacks) would the job as well.

eriklins avatar Feb 21 '24 09:02 eriklins

Agreed with @eriklins.

@kdewald I am facing a similar issue of peripheral handle not being exposed in callback functions of Peripheral class.

void set_callback_on_connected(std::function<void()> on_connected) void set_callback_on_disconnected(std::function<void()> on_disconnected)

It would be great if peripheral handle was exposed for the above two functions along with others mentioned by @eriklins.

darshan-slx avatar Apr 19 '24 07:04 darshan-slx

Hey all, thank you for bringing this up.

This is part of our current batch of features, so we are actively going to pursue this soon. Please hang tight for a little bit longer :D

kdewald avatar Apr 19 '24 07:04 kdewald

@darshan-slx

I am using the C version of SimpleBLE and the peripheral handle is exposed into the connect and disconnect callback functions, but just missing in the notify and indicate callbacks:

SIMPLEBLE_EXPORT simpleble_err_t simpleble_peripheral_set_callback_on_connected(simpleble_peripheral_t handle, void (*callback)(simpleble_peripheral_t peripheral, void* userdata), void* userdata);

Not sure about the cpp version, though.

eriklins avatar Apr 19 '24 07:04 eriklins

@darshan-slx

I am using the C version of SimpleBLE and the peripheral handle is exposed into the connect and disconnect callback functions, but just missing in the notify and indicate callbacks:

SIMPLEBLE_EXPORT simpleble_err_t simpleble_peripheral_set_callback_on_connected(simpleble_peripheral_t handle, void (*callback)(simpleble_peripheral_t peripheral, void* userdata), void* userdata);

Not sure about the cpp version, though.

Thanks a lot for your reply. I was using the cpp version of SimpleBLE so far and hadn't used the C version. Will check out the C version of SimpleBLE. Thank you!

darshan-slx avatar Apr 19 '24 09:04 darshan-slx

Hey all, thank you for bringing this up.

This is part of our current batch of features, so we are actively going to pursue this soon. Please hang tight for a little bit longer :D

Thank you!

darshan-slx avatar Apr 19 '24 09:04 darshan-slx

Any chance to look into this enhancement? Still not possible to subscribe notifications/indications when connected to multiple devices exposing an identical gatt table. Would „just“ need to expose the peripheral handle into the callback functions either as additional parameter or into the user data. Thanks!

eriklins avatar Jul 28 '24 15:07 eriklins

I shortlisted it for the v0.8.x release. I need to finish a contract for a client and I'll see if I can sneak this in right now.

kdewald avatar Jul 29 '24 05:07 kdewald

Implemented in the most recent commit: https://github.com/OpenBluetoothToolbox/SimpleBLE/commit/96038864f454793b2c7f135dbd1885aa60eba765

kdewald avatar Jul 29 '24 06:07 kdewald