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. 

 

Parents
  • You will need to add a BASE UUID for each of these. So make sure that NRF_SDH_BLE_VS_UUID_COUNT is set to 3 (or more).

    To add a BASE UUID you will need to call sd_ble_uuid_vs_add() for each BASE UUID you want to add, e.g. something like:

    sd_ble_uuid_vs_add(base_uuid1, uuid_type1);

    Then to add the service or characteristic you use sd_ble_gatts_service_add(), where you refer to the uuid_type you received from sd_ble_uuid_vs_add() above, e.g. something like:

    sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, uuid_type1, service_handle);

    Kenneth

  • Hi,

    Yeah, all of that was done, i think you didn't get what i mean exactly,

    in ble_nus_c.c i added that : 

    uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init)
    {
    	
        ble_uuid_t    uart_uuid;
        ble_uuid128_t nus_base_uuid = NUS_BASE_UUID;
    	
        ble_uuid128_t char1_base_uuid = CHAR1_BASE_UUID;
        ble_uuid128_t char2_base_uuid = CHAR2_BASE_UUID;
    	
        VERIFY_PARAM_NOT_NULL(p_ble_nus_c);
        VERIFY_PARAM_NOT_NULL(p_ble_nus_c_init);
    
    
        err2 = sd_ble_uuid_vs_add(&char1_base_uuid, &p_ble_nus_c->uuid_type);
        //VERIFY_SUCCESS(err_code);
    		APP_ERROR_CHECK (err2);
    		uart_uuid.type = p_ble_nus_c->uuid_type;
        uart_uuid.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;
    
        err3 = sd_ble_uuid_vs_add(&char2_base_uuid, &p_ble_nus_c->uuid_type);
        //VERIFY_SUCCESS(err3);
    		APP_ERROR_CHECK (err3);
    		//printf("error_code = %d\n",err3);
        uart_uuid.type = p_ble_nus_c->uuid_type;
        uart_uuid.uuid = BLE_UUID_NUS_RX_CHARACTERISTIC;
    
    
    
    		err1 = sd_ble_uuid_vs_add(&nus_base_uuid, &p_ble_nus_c->uuid_type);
        //VERIFY_SUCCESS(err_code);
    		APP_ERROR_CHECK (err1);
    		uart_uuid.type = p_ble_nus_c->uuid_type;
        uart_uuid.uuid = BLE_UUID_NUS_SERVICE;
    		
        p_ble_nus_c->conn_handle           = BLE_CONN_HANDLE_INVALID;
        p_ble_nus_c->evt_handler           = p_ble_nus_c_init->evt_handler;
        p_ble_nus_c->handles.nus_rx_handle = BLE_GATT_HANDLE_INVALID;
        p_ble_nus_c->handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;
    
        return ble_db_discovery_evt_register(&uart_uuid);
    }

    the problem here will be in this function in ble_nus_c.c: 

    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);
            }
        }
    }

    as BLE_UUID_NUS_RX_CHARACTERISTIC = BLE_UUID_NUS_TX_CHARACTERISTIC = 0x5343

    which will make an error on ble_nus_c_on_db_disc_evt() function.

    Also NRF_SDH_BLE_VS_UUID_COUNT = 3 is well done.

    i won't be able to send /receive messsages in this case between the central (nrf51) and the periph (RN4871).

    i hope i clarified what i mean!

Reply
  • Hi,

    Yeah, all of that was done, i think you didn't get what i mean exactly,

    in ble_nus_c.c i added that : 

    uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init)
    {
    	
        ble_uuid_t    uart_uuid;
        ble_uuid128_t nus_base_uuid = NUS_BASE_UUID;
    	
        ble_uuid128_t char1_base_uuid = CHAR1_BASE_UUID;
        ble_uuid128_t char2_base_uuid = CHAR2_BASE_UUID;
    	
        VERIFY_PARAM_NOT_NULL(p_ble_nus_c);
        VERIFY_PARAM_NOT_NULL(p_ble_nus_c_init);
    
    
        err2 = sd_ble_uuid_vs_add(&char1_base_uuid, &p_ble_nus_c->uuid_type);
        //VERIFY_SUCCESS(err_code);
    		APP_ERROR_CHECK (err2);
    		uart_uuid.type = p_ble_nus_c->uuid_type;
        uart_uuid.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;
    
        err3 = sd_ble_uuid_vs_add(&char2_base_uuid, &p_ble_nus_c->uuid_type);
        //VERIFY_SUCCESS(err3);
    		APP_ERROR_CHECK (err3);
    		//printf("error_code = %d\n",err3);
        uart_uuid.type = p_ble_nus_c->uuid_type;
        uart_uuid.uuid = BLE_UUID_NUS_RX_CHARACTERISTIC;
    
    
    
    		err1 = sd_ble_uuid_vs_add(&nus_base_uuid, &p_ble_nus_c->uuid_type);
        //VERIFY_SUCCESS(err_code);
    		APP_ERROR_CHECK (err1);
    		uart_uuid.type = p_ble_nus_c->uuid_type;
        uart_uuid.uuid = BLE_UUID_NUS_SERVICE;
    		
        p_ble_nus_c->conn_handle           = BLE_CONN_HANDLE_INVALID;
        p_ble_nus_c->evt_handler           = p_ble_nus_c_init->evt_handler;
        p_ble_nus_c->handles.nus_rx_handle = BLE_GATT_HANDLE_INVALID;
        p_ble_nus_c->handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;
    
        return ble_db_discovery_evt_register(&uart_uuid);
    }

    the problem here will be in this function in ble_nus_c.c: 

    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);
            }
        }
    }

    as BLE_UUID_NUS_RX_CHARACTERISTIC = BLE_UUID_NUS_TX_CHARACTERISTIC = 0x5343

    which will make an error on ble_nus_c_on_db_disc_evt() function.

    Also NRF_SDH_BLE_VS_UUID_COUNT = 3 is well done.

    i won't be able to send /receive messsages in this case between the central (nrf51) and the periph (RN4871).

    i hope i clarified what i mean!

Children
No Data
Related