BLE connection by UUID

Hello there,
I want to connect my nordic nrf52840 with another BLE device and then I'll try to send from the nordic to the device some data.

The nordic acts as central and I made it scan by name the BLE devices.
So I can connect to the other device.

But I want to scan filtering by UUID and connect with the device that has certain specific UUID and/pr characteristics.
I know the other device has these BLE settings:


Service UUID: 49535343FE7D4AE58FA99FAFD205E455
TX characteristic UUID: 495353431E4D4BD9BA6123C647249616
RX characteristic UUID: 49535343884143F4A8D4ECBE34729BB3

#define BT_UUID_MICROCHIP_VAL \
	BT_UUID_128_ENCODE(0x49535343, 0xfe7d, 0x4ae5, 0x8fa9, 0x9fafd205e455)
#define BT_UUID_MICROCHIP_TX_VAL \
	BT_UUID_128_ENCODE(0x49535343, 0x1e4d, 0x4bd9, 0xba61, 0x23c647249616)
#define BT_UUID_MICROCHIP_RX_VAL \
	BT_UUID_128_ENCODE(0x49535343, 0x8841, 0x43f4, 0xa8d4, 0xecbe34729bb3)

#define BT_UUID_MICROCHIP_SERVICE   BT_UUID_DECLARE_128(BT_UUID_MICROCHIP_VAL)
#define BT_UUID_MICROCHIP_TX        BT_UUID_DECLARE_128(BT_UUID_MICROCHIP_TX_VAL)
#define BT_UUID_MICROCHIP_RX        BT_UUID_DECLARE_128(BT_UUID_MICROCHIP_RX_VAL)

...

bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, BT_UUID_MICROCHIP_SERVICE);

...


I tried to scan adding an UUID filter but it apparently doesn't work. What I'm doing wrong with this? 
Trying filtering by name of device the connection succeded well and immediately.

but I'm not able to use the UUID service and characteristics of the other device to send data from the nordic to the other device.
What are the steps to make this?

Thank you in advance for your help.

  • Hello,
    I am sorry, but we are short staffed this week due to Public Holidays in Norway. We will be back on Monday 22nd and hope to be able to answer all incoming requests within a couple of days, depending on the backlog. I am sorry for the inconvenience.

    Best regards,
    Edvin

  • Hello,

    The first thing that comes to mind is the way that UUIDs are represented, which is not really that intuitive. 

    Service UUID: 49535343FE7D4AE58FA99FAFD205E455
    TX characteristic UUID: 495353431E4D4BD9BA6123C647249616
    RX characteristic UUID: 49535343884143F4A8D4ECBE34729BB3

    Where did you find these values? Typically, UUIDs are represented in chunks of 4 + 2 + 2 + 2 + 6 bytes, where the endianness is a bit weird. What I suggest you do is to flash a DK with the peripheral_uart sample, and connect to it with whatever central you have available (extra DK running with nRF Connect for Desktop -> Bluetooth Low Energy, or a mobile phone). Take note of the UUID that you see for this service/characteristic. Then connect to your peripheral, and take note of it's UUID. Then compare the Nordic UART Service UUID with the way it is represented in the nus.h file:

    /** @brief UUID of the NUS Service. **/
    #define BT_UUID_NUS_VAL \
    	BT_UUID_128_ENCODE(0x6e400001, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)
    
    /** @brief UUID of the TX Characteristic. **/
    #define BT_UUID_NUS_TX_VAL \
    	BT_UUID_128_ENCODE(0x6e400003, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)
    
    /** @brief UUID of the RX Characteristic. **/
    #define BT_UUID_NUS_RX_VAL \
    	BT_UUID_128_ENCODE(0x6e400002, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)

    Looking at nRF Connect for Desktop -> Bluetooth Low Energy, the Nordic UART Service UUID looks like this:

    Is your peripheral's UUID represented in the same order as you wrote, or are the chunks perhaps swapped?

    Best regards,

    Edvin

  • Hello there!

    I tried to do as you described:
    I installed on my DK the peripheral example and on nRF connect app I looked at the uuids my peripheral chip "shares".
    I put here pictures of how the two peripherals UUID appeared.

    Here is how Nordic's UUID appears

    Here, instead, you can see the other chip's ones


    It seems they have the same shape exactly you described, but the little difference that they has all different values (not for the one weird byte)

    So, what can I do to make them comunicate? 
    Using a no security connection I see them connected using on the nordic the "central_uart" example modified a little because of make a connection.
    But I can not filter in scan phase for UUID services...

    After this I can't understand how to send a data from the central to peripheral using the chip uuid.
    Can you help me in this? Am I clear?
    Thank you for your help.


  • It looks like the UUID byte order is fine.

    I am a bit confused. You talk about sending data, but are you actually able to find the device and connect?

    DenRatio said:
    Using a no security connection I see them connected using on the nordic the "central_uart" example modified a little because of make a connection.

    I assume they are connected.

    Did you enable notifications from your central application, like the ble_app_uart_c does? This is needed for the peripheral to send data to the central. Then you can write to the RX characteristic, it appears, just like you can write to the RX characteristic of the Nordic UART service. 

    How are you currently trying to send the data? What does it say/return when you are trying to do so?

    Are you able to send data to the device using the mobile app that your screenshots are from (nRF Connect for Android, I guess)?

    Best regards,

    Edvin

  • Hello Edvin! 
    of course! they are connected!, but I'm not able to send data from the central to the peripheral. 

    No, I didn't enable notifications from my central app. I'll try to enable them, but for now I need to send data from central to peripheral; then later I'll try to send from the peripheral to the central. 

    More than this, I tried to find services using the function bt_gatt_dm_start as done in the central_uart example, but passing to the function bt_gatt_dm_start the service I indicated in the first post.
    Something like this:

    #define BT_UUID_MICROCHIP_VAL \
    	BT_UUID_128_ENCODE(0x49535343, 0xfe7d, 0x4ae5, 0x8fa9, 0x9fafd205e455)
    #define BT_UUID_MICROCHIP_TX_VAL \
    	BT_UUID_128_ENCODE(0x49535343, 0x1e4d, 0x4bd9, 0xba61, 0x23c647249616)
    #define BT_UUID_MICROCHIP_RX_VAL \
    	BT_UUID_128_ENCODE(0x49535343, 0x8841, 0x43f4, 0xa8d4, 0xecbe34729bb3)
    
    ....
    
    static void gatt_discover(struct bt_conn *conn)
    {
    	int err;
        ...
    	err = bt_gatt_dm_start(conn, BT_UUID_MICROCHIP_SERVICE, &discovery_cb, &nus_client);
        ...
    }

    The gatt_discover function is called in the "connected" callback after MTU has been axchanged.

    How can I print discovered services? I tried with the function bt_gatt_dm_data_print enabling it in my prj.conf but I have not a print result.

    And how can I send (or try to) data over gatt? I tried with bt_nus_send function but I'm doing something wrong, probably...

    Thank you again for your help.



Related