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

Characteristic tutorial : error when adding a characteristic to a service

I have a question concerning this tutorial : devzone.nordicsemi.com/.../ble-characteristics-a-beginners-tutorial

i have same problem than Milton (comment under the tutorial) : "I was able to add a custom service and verify it successfully on MCP. However, when I included the code to add a characteristic to the service, I always get "NRF_ERROR_INVALID_PARAM'."

he found a solution :

//for service
err_code = sd_ble_uuid_vs_add(&base_uuid, &m_base_uuid_type);
uuid.type   = m_base_uuid_type;
uuid.uuid   = BLE_UUID_OUR_SERVICE_UUID;

//For the characteristic:

char_uuid.uuid      = BLE_UUID_OUR_CHARACTERISTC_UUID;
char_uuid.type      = m_base_uuid_type;

i tryed his solution but i failed, i think it's because i do'nt know how to implement correctly the solution ...

(the tutorial work and advertise for me until this problem)

  • here is original code

    Our_service.c
    
    void our_service_init(ble_os_t * p_our_service)
    {
        uint32_t   err_code; // Variable to hold return codes from library and softdevice functions
    
        // FROM_SERVICE_TUTORIAL: Declare 16-bit service and 128-bit base UUIDs and add them to the BLE stack
        ble_uuid_t        service_uuid;
        ble_uuid128_t     base_uuid = BLE_UUID_OUR_BASE_UUID;
        service_uuid.uuid = BLE_UUID_OUR_SERVICE_UUID;
        err_code = sd_ble_uuid_vs_add(&base_uuid, &service_uuid.type);
        APP_ERROR_CHECK(err_code);
    ...    
    }
    
    ...
    
    static uint32_t our_char_add(ble_os_t * p_our_service)
    {
        // OUR_JOB: Step 2.A, Add a custom characteristic UUID
    		uint32_t            err_code;
    		ble_uuid_t          char_uuid;
    		ble_uuid128_t       base_uuid = BLE_UUID_OUR_BASE_UUID;
    		char_uuid.uuid      = BLE_UUID_OUR_CHARACTERISTC_UUID;
    		err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
    		APP_ERROR_CHECK(err_code);
    ...
    }

    and the solution i tryed without success

    Our_service.c
    
    uint8_t m_base_uuid_type;
    
    void our_service_init(ble_os_t * p_our_service)
    {
        uint32_t   err_code; // Variable to hold return codes from library and softdevice
        // FROM_SERVICE_TUTORIAL: Declare 16-bit service and 128-bit base UUIDs and add them to the BLE stack
        ble_uuid_t        service_uuid;
        ble_uuid128_t     base_uuid = BLE_UUID_OUR_BASE_UUID;
        service_uuid.uuid = BLE_UUID_OUR_SERVICE_UUID;
        err_code = sd_ble_uuid_vs_add(&base_uuid, &m_base_uuid_type);
        service_uuid.type   = m_base_uuid_type;
        service_uuid.uuid   = BLE_UUID_OUR_SERVICE_UUID;
        APP_ERROR_CHECK(err_code); 
    ...
    }
    
    static uint32_t our_char_add(ble_os_t * p_our_service)
    {
        // OUR_JOB: Step 2.A, Add a custom characteristic UUID
    	uint32_t            err_code;
    	ble_uuid_t          char_uuid;
    	ble_uuid128_t       base_uuid = BLE_UUID_OUR_BASE_UUID;
    	char_uuid.uuid      = BLE_UUID_OUR_CHARACTERISTC_UUID;
    	char_uuid.type      = m_base_uuid_type;
    	err_code = sd_ble_uuid_vs_add(&base_uuid, &char_uuid.type);
    	APP_ERROR_CHECK(err_code);
    	
    ...
    }

  • HI Geoffroy,

    Firstly, the MCP software is outdated, you should use nRF Connect app to test this example.

    Which SDK are you using and how far have you come in the tutorial? It seems like you haven't finish all the steps in "Step 2: Add the Characteristic". If you are struggling I recommend you take a look at the completed code in this github branch: https://github.com/NordicPlayground/nrf5-ble-tutorial-characteristic/tree/master/Solution

    Remember that this tutorial have only been tested for SDK 15.0.0.

    Best Regards,

    Marjeris

  • Hi Marjeris

    i'm using using SDK15.0.0 with nrf52840, i also use nrf connect application.

    In this tutorial i finished all steps, code is compiling, it was advertising (i could see it on nrf connect app) until i add characteristic.

    my problem is same that Milton reported (comments under tutorial)

    thank you Geoffroy

  • Hi,

    Sorry, I linked to the old solution in my last post. This is the solution for SDK v15.0.0 https://github.com/NordicPlayground/nrf5-ble-tutorial-characteristic/tree/master/Solution

    Did you finish all steps in "Step 2" in the characteristic tutorial?

    - Marjeris

  • Ok so that's files i used as help.

    I loaded Solution files (main and our_service.c .h) without modifying them (except adding a trace at 2.E after the call  sd_ble_gatts_characteristic_add... to get err_code).

    and i get same err_code 0x07.

    yes i finished all steps 2 and 3...

Related