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

S120 adding 2 uuids for 2 peripherals

Hello, I am working on S120 SD v2.1.0 for central and S110 v8.0 SD for peripheral and SDK9.0 and I am able to configure 1 single uuid on central and connect to multiple peripherals with the same UUID.

But now I am trying to configure different UUID for 2 different peripherals, and on the central side I added the UUID as follows:

	ble_uuid_t uuid;
uuid.type = m_base_uuid_type;
uuid.uuid = BLE_UUID_NUS_SERVICE;

err_code = ble_db_discovery_evt_register(&uuid, db_discovery_evt_handler);
APP_ERROR_CHECK(err_code);

uuid.type = m_base_uuid_type;
uuid.uuid = 0x0002;

err_code = ble_db_discovery_evt_register(&uuid, db_discovery_evt_handler);
APP_ERROR_CHECK(err_code);

i.e., one with NUS service and other with UUID = 0x0002. Now the issue I am facing is, the ID with 0x0002 is not able to connect. When the central connects to the device, I am getting BLE_DB_DISCOVERY_SRV_NOT_FOUND event . Since this is major requirement for my application, can anyone help me in configuring this? I'm I missing anything in configuration?

Regards,
Sowmya

Parents
  • Hey!

    Does both the peripherals have the same base uuid? If not, you must add the second base uuid as well with sd_ble_uuid_vs_add (ble_uuid128_t const *p_vs_uuid, uint8_t *p_uuid_type). Store the p_uuid_type, and put this in uuid.type when you call ble_db_discovery_evt_register.

    As your code is not, it will use the same base uuid for both services.

    Update 1

    Since you add two services with ble_db_discovery_evt_register, but with the same callback function, you might be mixing which event comes after which service discovery. The db_discovery module will try to discovery BOTH the services when connection to a new device.

    Try adding the second service with a second event handler like this:

    err_code = ble_db_discovery_evt_register(&uuid1, db_discovery_evt_handler1);
    APP_ERROR_CHECK(err_code);
    err_code = ble_db_discovery_evt_register(&uuid2, db_discovery_evt_handler2);
    APP_ERROR_CHECK(err_code);
    

    Let us call the NUS service device for device 1. When you connect to it, and do service discovery this should happen:

    • db_discovery_evt_handler1 will be called, with the event BLE_DB_DISCOVERY_COMPLETE.
    • db_discovery_evt_handler2 will be called, with the event BLEE_DB_DISCOVERY_SRV_NOT_FOUND

    Let us call the second device for device 2. When you connect to it, and do service discovery this should happen:

    • db_discovery_evt_handler1 will be called, with the event BLEE_DB_DISCOVERY_SRV_NOT_FOUND .
    • db_discovery_evt_handler2 will be called, with the event BLE_DB_DISCOVERY_COMPLETE

    Can you check the following?

    • That your central successfully connects to both devices
    • Which results the db_discovery event handlers report for both devices.
Reply
  • Hey!

    Does both the peripherals have the same base uuid? If not, you must add the second base uuid as well with sd_ble_uuid_vs_add (ble_uuid128_t const *p_vs_uuid, uint8_t *p_uuid_type). Store the p_uuid_type, and put this in uuid.type when you call ble_db_discovery_evt_register.

    As your code is not, it will use the same base uuid for both services.

    Update 1

    Since you add two services with ble_db_discovery_evt_register, but with the same callback function, you might be mixing which event comes after which service discovery. The db_discovery module will try to discovery BOTH the services when connection to a new device.

    Try adding the second service with a second event handler like this:

    err_code = ble_db_discovery_evt_register(&uuid1, db_discovery_evt_handler1);
    APP_ERROR_CHECK(err_code);
    err_code = ble_db_discovery_evt_register(&uuid2, db_discovery_evt_handler2);
    APP_ERROR_CHECK(err_code);
    

    Let us call the NUS service device for device 1. When you connect to it, and do service discovery this should happen:

    • db_discovery_evt_handler1 will be called, with the event BLE_DB_DISCOVERY_COMPLETE.
    • db_discovery_evt_handler2 will be called, with the event BLEE_DB_DISCOVERY_SRV_NOT_FOUND

    Let us call the second device for device 2. When you connect to it, and do service discovery this should happen:

    • db_discovery_evt_handler1 will be called, with the event BLEE_DB_DISCOVERY_SRV_NOT_FOUND .
    • db_discovery_evt_handler2 will be called, with the event BLE_DB_DISCOVERY_COMPLETE

    Can you check the following?

    • That your central successfully connects to both devices
    • Which results the db_discovery event handlers report for both devices.
Children
  • Hi Anders, Yes both peripherals have the same base UUID but different 16-bit service UUID. I am adding UUID in central as follows:

    	ble_uuid128_t base_uuid = BLE_UUID_OUR_BASE_UUID;
    
    err_code = sd_ble_uuid_vs_add(&base_uuid, &m_base_uuid_type);
    APP_ERROR_CHECK(err_code);
    
    for (i = 0; i < MAX_CLIENTS; i++)
    {
    	m_client[i].state  = IDLE;
    }
    m_client_count = 0;
    db_discovery_init();
    
    // Register with discovery module for the discovery of the service.
    ble_uuid_t uuid;
    uuid.type = m_base_uuid_type;
    uuid.uuid = BLE_UUID_NUS_SERVICE;
    
    err_code = ble_db_discovery_evt_register(&uuid,
    												db_discovery_evt_handler);
    APP_ERROR_CHECK(err_code);
    
        err_code = sd_ble_uuid_vs_add(&base_uuid, &m_base_uuid_type);
    APP_ERROR_CHECK(err_code);
    
    uuid.type = m_base_uuid_type;
    uuid.uuid = 0x0002;
    
    err_code = ble_db_discovery_evt_register(&uuid,
    												db_discovery_evt_handler);
    APP_ERROR_CHECK(err_code);
    

    This is the code snippet in,peripheral:

        ble_uuid_t        service_uuid;
        ble_uuid128_t     base_uuid = BLE_UUID_OUR_BASE_UUID;
        service_uuid.uuid = BLE_UUID_NUS_SERVICE;
    
        // Initialize the service structure.
        p_sos->conn_handle             = BLE_CONN_HANDLE_INVALID;
        p_sos->data_handler            = p_sos_init->evt_handler;
        p_sos->is_notification_enabled = false;
    
        // add custom base UUID
        err_code = sd_ble_uuid_vs_add(&base_uuid, &p_sos->uuid_type);
        if(err_code != NRF_SUCCESS)
     {
     	return err_code;
     }
         
         service_uuid.type = p_sos->uuid_type;
         
         // Add the service
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                        &service_uuid,
                                        &p_sos->service_handle);
    

    And the other peripheral configuration is same but the service UUID is set to 0x0002.

    I think this is proper, correct?

    Regards,
    Sowmya

  • I added the different discovery handler for two different services, and this is the code snippet:

    	ble_uuid128_t base_uuid = BLE_UUID_OUR_BASE_UUID;
    
    err_code = sd_ble_uuid_vs_add(&base_uuid, &m_base_uuid_type);
    APP_ERROR_CHECK(err_code);
    
    for (i = 0; i < MAX_CLIENTS; i++)
    {
    	m_client[i].state  = IDLE;
    }
    m_client_count = 0;
    db_discovery_init();
    
    // Register with discovery module for the discovery of the service.
    ble_uuid_t uuid;
    uuid.type = m_base_uuid_type;
    uuid.uuid = BLE_UUID_NUS_SERVICE;
    
    err_code = ble_db_discovery_evt_register(&uuid,
    												db_discovery_evt_handler);
    APP_ERROR_CHECK(err_code);
    
    uuid.type = m_base_uuid_type;
    uuid.uuid = 0x0002;
    
    err_code = ble_db_discovery_evt_register(&uuid,
    												db_discovery_evt_handler_1);
    APP_ERROR_CHECK(err_code);
    

    First I tested for service with UUID = 0x0002 and it is getting service complete and connected. But when I scan and the device with NUS_SERVICE is advertise, central is not getting the scan report event.

Related