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

BLE UART custom service (bis)

Hi,

I'm openning a new case (following the proposal of Einar Thorsrud).

I want to do a BLE NUS project with custom service 128bits and with custom characteristics also differents fro the service.

You can found my project with this link: drive.google.com/.../view

I use the TEST\examples\ble_central\ble_app_uart_c\pca10040\s132\ses\ble_app_uart_c_pca10040_s132 for the central board (NRF52-DK)
and TEST\examples\ble_peripheral\ble_app_uart\pca10056\s140\ses\ble_app_uart_pca10056_s140 for the peripheral board (NRF52840-DK )

My problem is during the scan process or during the activation of notification.

In the function uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init) I have tried with differents solutions (adding or not the "sd_ble_uuid_vs_add() function) but result are not relevant.

My bloc code:

   //AJOUT
        
    ble_uuid128_t tx_base_uuid = {BLE_UUID_COMMANDE_TX_UUID};
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c);
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c_init);
    err_code = sd_ble_uuid_vs_add(&tx_base_uuid, &p_ble_nus_c->uuid_type);
    VERIFY_SUCCESS(err_code);

    ble_uuid128_t rx_base_uuid = {BLE_UUID_COMMANDE_RX_UUID};
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c);
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c_init);
    err_code = sd_ble_uuid_vs_add(&rx_base_uuid, &p_ble_nus_c->uuid_type);
    VERIFY_SUCCESS(err_code);
    
    // FIN AJOUT

1) If I comment the bloc code (function is similar to the example project function)

Log:

<info> app_timer: RTC: initialized.
<debug> ble_scan: Added filter on UUID 4778
<info> app: BLE UART central example started.
<debug> ble_scan: Scanning
<debug> ble_scan: Connecting
<debug> ble_scan: Connection status: 0
<debug> nrf_ble_gatt: Requesting to update ATT MTU to 247 bytes on connection 0x0.
<debug> nrf_ble_gatt: Updating data length to 251 on connection 0x0.
<info> app: Connecting to target 542667A20DCA
<debug> nrf_ble_gq: Registering connection handle: 0x0000
<debug> ble_db_disc: Starting discovery of service with UUID 0x4778 on connection handle 0x0.
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Primary Services Discovery Request
<debug> nrf_ble_gq: SD is currently busy. The GATT request procedure will be attempted                       again later.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gatt: ATT MTU updated to 247 bytes on connection 0x0 (response).
<info> app: ATT MTU exchange completed.
<info> app: Ble NUS max data length set to 0xF4(244)
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: GATTC Primary Service Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (2) succeeded on connection handle: 0.
<debug> nrf_ble_gatt: Data length updated to 251 on connection 0x0.
<debug> nrf_ble_gatt: max_rx_octets: 251
<debug> nrf_ble_gatt: max_tx_octets: 251
<debug> nrf_ble_gatt: max_rx_time: 2120
<debug> nrf_ble_gatt: max_tx_time: 2120
<debug> ble_db_disc: Found service UUID 0x4778.
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Descriptor Request
<debug> nrf_ble_gq: SD GATT procedure (4) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Descriptor Request
<debug> nrf_ble_gq: SD GATT procedure (4) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> ble_db_disc: Discovery of service with UUID 0x4778 completed with success on connection handle 0x0.
<info> app: Discovery complete.
<error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at C:\Users\julien.HORIZONTELECOM\Downloads\TEST\examples\ble_central\ble_app_uart_c\main.c:336
PC at: 0x0002F797
<error> app: End of error report


The problem is "err_code = ble_nus_c_tx_notif_enable(p_ble_nus_c);"(main.c line 335). I can't enable notification. When I debbug, I see uuid = 0. And I don't know why...

2) When I add my bloc code just before the line "return ble_db_discovery_evt_register(&uart_uuid);" in the "uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init)" function:

Log:

<info> app_timer: RTC: initialized.
<debug> ble_scan: Added filter on UUID 4778
<info> app: BLE UART central example started.
<debug> ble_scan: Scanning
<debug> ble_scan: Connecting
<debug> ble_scan: Connection status: 0
<debug> nrf_ble_gatt: Requesting to update ATT MTU to 247 bytes on connection 0x0.
<debug> nrf_ble_gatt: Updating data length to 251 on connection 0x0.
<info> app: Connecting to target 542667A20DCA
<debug> nrf_ble_gq: Registering connection handle: 0x0000
<debug> ble_db_disc: Starting discovery of service with UUID 0x4778 on connection handle 0x0.
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Primary Services Discovery Request
U of 247 bytes.
<debug> nrf_ble_gatt: Updating ATT MTU to 247 bytes (desired: 247) on connection 0x0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: GATTC Primary Service Discovery Request
<debug> nrf_ble_gq: SD is currently busy. The GATT request procedure will be attempted                           again later.
<debug> nrf_ble_gatt: ATT MTU updated to 247 bytes on connection 0x0 (response).
<info> app: ATT MTU exchange completed.
<info> app: Ble NUS max data length set to 0xF4(244)
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: GATTC Primary Service Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (2) succeeded on connection handle: 0.
<debug> nrf_ble_gatt: Data length updated to 251 on connection 0x0.
<debug> nrf_ble_gatt: max_rx_octets: 251
<debug> nrf_ble_gatt: max_tx_octets: 251
<debug> nrf_ble_gatt: max_rx_time: 2120
<debug> nrf_ble_gatt: max_tx_time: 2120
<debug> ble_db_disc: Found service UUID 0x4778.
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (3) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Descriptor Request
<debug> nrf_ble_gq: SD GATT procedure (4) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Characteristic Descriptor Request
<debug> nrf_ble_gq: SD GATT procedure (4) succeeded on connection handle: 0.
<debug> nrf_ble_gq: Processing the request queue...
<debug> ble_db_disc: Discovery of service with UUID 0x4778 completed with success on connection handle 0x0.
<debug> nrf_ble_gq: Processing the request queue...

Discovery seems to be ok but no event "BLE_NUS_C_EVT_DISCOVERY_COMPLETE"

3) f i move the bloc code before "uart_uuid.type = p_ble_nus_c->uuid_type;"

Log:

<info> app_timer: RTC: initialized.
<debug> ble_scan: Added filter on UUID 4778
<info> app: BLE UART central example started.
<debug> ble_scan: Scanning
<debug> ble_scan: Connecting
<debug> ble_scan: Connection status: 0
<debug> nrf_ble_gatt: Requesting to update ATT MTU to 247 bytes on connection 0x0.
<debug> nrf_ble_gatt: Updating data length to 251 on connection 0x0.
<info> app: Connecting to target 542667A20DCA
<debug> nrf_ble_gq: Registering connection handle: 0x0000
<debug> ble_db_disc: Starting discovery of service with UUID 0x4778 on connection handle 0x0.
<debug> nrf_ble_gq: Adding item to the request queue
<debug> nrf_ble_gq: GATTC Primary Services Discovery Request
dure will be attempted                       again later.
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: GATTC Primary Service Discovery Request
<debug> nrf_ble_gq: SD is currently busy. The GATT request proce<debug> nrf_ble_gatt: ATT MTU updated to 247 bytes on connection 0x0 (response).
<info> app: ATT MTU exchange completed.
<info> app: Ble NUS max data length set to 0xF4(244)
<debug> nrf_ble_gq: Processing the request queue...
<debug> nrf_ble_gq: GATTC Primary Service Discovery Request
<debug> nrf_ble_gq: SD GATT procedure (2) succeeded on connection handle: 0.
<debug> nrf_ble_gatt: Data length updated to 251 on connection 0x0.
<debug> nrf_ble_gatt: max_rx_octets: 251
<debug> nrf_ble_gatt: max_tx_octets: 251
<debug> nrf_ble_gatt: max_rx_time: 2120
<debug> nrf_ble_gatt: max_tx_time: 2120
<debug> ble_db_disc: Service UUID 0x4778 not found.
<debug> nrf_ble_gq: Processing the request queue...

Discovery failed...

I don't know if sd_ble_uuid_vs_add() function is a good solution. Like Einar says, I store the ID in the same variable (&p_ble_nus_c->uuid_type). Do you have a way to do correctly do the storage and solve my problem?

I have found a solution but it's a cheating way... I comment my bloc code in ble_nus_c_init(..) function and I add some line in ble_nus_c_on_db_disc_evt() 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_COMMANDE_SERVICE)   //BLE_UUID_NUS_SERVICE)
        &&  (p_evt->params.discovered_db.srv_uuid.type == p_ble_nus_c->uuid_type))
    {
        NRF_LOG_INFO("nbr: %x",  p_evt->params.discovered_db.char_count);
        for (uint32_t i = 0; i < p_evt->params.discovered_db.char_count; i++)
        {
            //START
            if( p_evt->params.discovered_db.charateristics[i].characteristic.handle_value == 0x0010)
            {
              p_evt->params.discovered_db.charateristics[i].characteristic.uuid.uuid = BLE_UUID_COMMANDE_RX_CHARACTERISTIC;
              p_chars[i].characteristic.uuid.uuid =p_evt->params.discovered_db.charateristics[i].characteristic.uuid.uuid;

            }else if( p_evt->params.discovered_db.charateristics[i].characteristic.handle_value == 0x000D)
            {
              p_evt->params.discovered_db.charateristics[i].characteristic.uuid.uuid = BLE_UUID_COMMANDE_TX_CHARACTERISTIC;
              p_chars[i].characteristic.uuid.uuid =p_evt->params.discovered_db.charateristics[i].characteristic.uuid.uuid;
            }
            //END
            
            NRF_LOG_INFO("uuid: %x", p_chars[i].characteristic.uuid.uuid);
            NRF_LOG_INFO("ccd: %x", p_chars[i].cccd_handle);
            NRF_LOG_INFO("handle_value: %x", p_chars[i].characteristic.handle_value);
            
            switch (p_chars[i].characteristic.uuid.uuid)
            {
                
                case BLE_UUID_COMMANDE_RX_CHARACTERISTIC: //BLE_UUID_NUS_RX_CHARACTERISTIC:
                    nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
                    break;

                case BLE_UUID_COMMANDE_TX_CHARACTERISTIC: //BLE_UUID_NUS_TX_CHARACTERISTIC:
                    nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
                    nus_c_evt.handles.nus_tx_cccd_handle = p_chars[i].cccd_handle;
                    break;

               case BLE_UUID_INFO_MOTEUR_RX_CHARACTERISTIC:
                //  nus_c_evt.handles.nus_rx_mot_handle = p_chars[i].characteristic.handle_value;
                  break;

                default:
                    break;
            }
        }
        NRF_LOG_INFO("Nordic UART Service discovered at peer.\r\n");
        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);
        }
    }
}

So uuid is not null and I can enable notification and doing uart over BLE. But, I think is not a proper solution.

Thanks.

Parents
  • Hi

    My apologies for the late reply, but we're rather understaffed during the summer vacation period, so delayed replies are expected.

    Regarding the storing of the UUIDs that Einar mentioned in your previous ticket, you will need to store these UUIDs at separate places in the memory so you can call them separately when searching for them later.

    Have you taken a look at our custom BLE service tutorial available on GitHub? It should explain how to add your own services and UUIDs to your application in detail.

    Best regards,

    Simon

  • Hi,

    My problem is not solved. I have already look this project and doing this (adding service) for my server project in witch I use 3 services without problems . But for my client example in this project I don't have solution...

    Have you tried to test with my zip project ant the two examples project I described in the main ticket?

    Regards,

Reply Children
No Data
Related