This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

creating custom service and characteristics with different Base UUID : connecting and discovering

Hi,

Am using nrf51822 as central, i want to discover and to commuinicate with the service of another ble module (which is RN4871 from microship).

My problem here is that this RN4871 advertise a service with a different base UUID for service and for its two characteristics.

i've been adjusting the ble_nus_c.c / ble_nus_c.c from ble_app_uart_c.

the service i want to discover is below: 

#define NUS_BASE_UUID {{0x55, 0xE4, 0x05, 0xD2, 0xAF, 0x9F, 0xA9, 0x8F, 0xE5, 0x4A, 0x7D, 0xFE, 0x43, 0x53, 0x53, 0x49}} //Used vendor specific UUID.
#define CHAR1_BASE_UUID {{0x16, 0x96, 0x24, 0x47, 0xC6, 0x23, 0x61, 0xBA, 0xD9, 0x4B, 0x4D, 0x1E, 0x43, 0x53, 0x53, 0x49}} // Used vendor specific UUID.
#define CHAR2_BASE_UUID {{0xB3, 0x9B, 0x72, 0x34, 0xBE, 0xEC, 0xD4, 0xA8, 0xF4, 0x43, 0x41, 0x88, 0x43, 0x53, 0x53, 0x49}} // Used vendor specific UUID.

the problem here is that the defines below are all the same according to the service definition of the RN4871 datasheet

#define BLE_UUID_NUS_SERVICE 0x5343 .
#define BLE_UUID_NUS_TX_CHARACTERISTIC 0x5343 
#define BLE_UUID_NUS_RX_CHARACTERISTIC 0x5343

this will make a problem in this function :

void ble_nus_c_on_db_disc_evt(ble_nus_c_t * p_ble_nus_c, ble_db_discovery_evt_t * p_evt)
{
    ble_nus_c_evt_t nus_c_evt;
    memset(&nus_c_evt,0,sizeof(ble_nus_c_evt_t));

    ble_gatt_db_char_t * p_chars = p_evt->params.discovered_db.charateristics;

    // Check if the NUS was discovered.
    if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE &&
        p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE &&
        p_evt->params.discovered_db.srv_uuid.type == p_ble_nus_c->uuid_type)
    {

        uint32_t i;

        for (i = 0; i < p_evt->params.discovered_db.char_count; i++)
        {
            switch (p_chars[i].characteristic.uuid.uuid)
            {
							
							case BLE_UUID_NUS_TX_CHARACTERISTIC:
                    nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
                    break;

                case BLE_UUID_NUS_RX_CHARACTERISTIC:
                    nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
                    nus_c_evt.handles.nus_rx_cccd_handle = p_chars[i].cccd_handle;
                    break;

                default:
                    break;
							
            }
        }
        if (p_ble_nus_c->evt_handler != NULL)
        {
            nus_c_evt.conn_handle = p_evt->conn_handle;
            nus_c_evt.evt_type    = BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
            p_ble_nus_c->evt_handler(p_ble_nus_c, &nus_c_evt);
        }
    }
}

PS: if i make different values in these macros : #define BLE_UUID_NUS_SERVICE 0x5343 .
#define BLE_UUID_NUS_TX_CHARACTERISTIC 0x5343 
#define BLE_UUID_NUS_RX_CHARACTERISTIC 0x5343

my code works fine and i discover/connect, sending and receiving data is the problem then, this remark is only to tell that i used carrefully the function "sd_ble_uuid_vs_add()" and my ram is well adjusted so as my uuid_count.

would someone help please!

Thanks in advance. 

 

  • The ble_nus_c_on_db_disc_evt() was not designed to handle your UUID configuration no. So you would need to re-write the code to handle your setup, unfortunately I don't have time to do this for you, but it should be doable if you understand that you need 2 of these if statements:

    if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE &&
    p_evt->params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE &&
    p_evt->params.discovered_db.srv_uuid.type == p_ble_nus_c->uuid_type)

    Because even if BLE_UUID_NUS_TX_CHARACTERISTIC and BLE_UUID_NUS_RX_CHARACTERISTIC share the same value, they don't have the same uuid_type.

    Kenneth

Related