is there a way pass a service/characteristic uuid as a variable ?

Dear support

I am developing a generic client, after connection and service discovery,  there are usually a few characteristics with different uuids are found, I need to choose which characteristic to work on by its uuid, and pass the uuid as a parameter, I noticed in examples they are all passed by macro like BT_UUID_BAS etc. is it possible I define a variable like struct bt_uuid* my_uuid and pass it around like my_uuid = BT_UUID_BAS; ?

I tried and it doesn't work me, I wonder what is the solution.

Thank you!

Ping 

Parents Reply Children
  • Hi, Vidar

    You are right, I am doing a central based on UART commands, I listen to the command from upper app to connect to a particular peripheral and then do service discovery. 

    If upper app need to do data exchange on a characteristics, I am thinking of passing the uuid to the central and then assign handles and ready for data exchange. It is hard to pass uuid as parameters as I just found.

    I will try to use handles probably as you suggested, do I need to assign and keep all of them to my client variables before I know which one to operate? There are quite a few characteristics in the service. and find their handles need to pass some uuid too from the example I know, like Nordic LBS.

    Regards!

    Ping

  • Hi Ping,

    Thanks for the clarification.Still, I'm not sure I understand how the app is meant to be used. Is it going to work with a pre-defined set of supported characteristics, or is it going to work with any GATT server?

    If you haven't alread, I would suggest you try Bluetooth shell example to see if maybe does what you want. It's mainly used for testing in the Zephyr projet, so documentation for it a bit lacking, but should still be possible to use. You can add the --help argument to check what input parameters a particular command expects as shown below.

    UART serial client connected to Bluetooth shell sample

    Best regards,

    Vidar

  • Thanks, Vidar

    I am developing a bluetooth gateway and the module is hosted by a host processor via UART.   So the BLE central application has to be generic - work with any GATT server and passes whatever it scans to host processor and listen to commands from host processor to do connection, SDP and data exchange etc.

    The interface protocol between host and BLE is specific to the product only and will never need to interface with other hosts and don't have to be that readable in terms of format, so commands are not as complicated as the Shell example you pointed out - I tried it before and not be able to follow all of them and it is not easy to dig out all source modules it uses - look like it is everywhere and well hidden.

    I will try your suggest to use handles to communicate with host, probably that the better way, I am thinking of use BLE MAC address and handles to address each characteristic and pass data in between - read/write/notify etc. 

    I have to consider multiple connection as well, as the central is able to connect up to 20 peripherals at same time, in case of all of them sending data to BLE, I hope the data are not coming at same time? and when any connections are established, I guess I have to stop scanning, as the radio cannot support them both?

    Thanks you for contribution and suggestion.

    Ping

  • Hi Ping,

    Thanks, I understand your use case now. I agree that the shell sample can be a bit complicated to use. Still, if you want to see how the commands are implemented, you can have a look at the files in zephyr/subsys/bluetooth/shell.

    PingISTL said:
    I have to consider multiple connection as well, as the central is able to connect up to 20 peripherals at same time, in case of all of them sending data to BLE, I hope the data are not coming at same time? and when any connections are established, I guess I have to stop scanning, as the radio cannot support them both?

    The data will not come at the same time, no. The BT event handlers will also include a reference to the connection that raised the event so you can know which device the data came from (Connection Management).

    The RADIO cannot operate in RX and TX mode at the same time. However, the controller will take care of the scheduling the scan events to allow scanning to happen between connection events. Please see the "Scheduling" chapter of the Softdevice controller for details. It includes some good illustrations of how it works.

  • Thank you, Vidar

    I tried use handles to address the characteristics and to operate them, and it works fine, and this way it is easy to make it generic and so far works with 2 different peripherals when they are all connected. Thank you for your good suggestion!

    I will further look at the shell example, is there a document on the interface command? I struggled a few month ago to get some commands working before. 

    I have another question about SDP, service discovery is able to find all characteristics, their value/notification handles and properties, but the data exchange in between is peripheral specific, is that right? For example, I know LBS button characteristic has a 1 byte of data when read and notified, but other service/characteristics might have a different set of data to read and notify, the protocols are internal to a specific peripheral and I need to know this before I send data to read/write, is that right?

    Regards!

    Ping

Related