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)

Parents
  • 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);
    	
    ...
    }

Reply
  • 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);
    	
    ...
    }

Children
  • I'm still searching and i really need help,

    I don't understand because even the "Solution" sources code (https://github.com/NordicPlayground/nrf5-ble-tutorial-characteristic/tree/master/Solution) do not work (do not advertise) :( ...

    here is my config in sdk_config.h :

    // <o> NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE - Attribute Table size in bytes. The size must be a multiple of 4. 
    #ifndef NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE
    #define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408
    #endif
    
    // <o> NRF_SDH_BLE_VS_UUID_COUNT - The number of vendor-specific UUIDs. 
    #ifndef NRF_SDH_BLE_VS_UUID_COUNT
    #define NRF_SDH_BLE_VS_UUID_COUNT 1
    #endif
    
    // <q> NRF_SDH_BLE_SERVICE_CHANGED  - Include the Service Changed characteristic in the Attribute Table.
     
    
    #ifndef NRF_SDH_BLE_SERVICE_CHANGED
    #define NRF_SDH_BLE_SERVICE_CHANGED 0
    #endif

  • Hi Geoffroy,

    The solution files are supposed to work with the nRF52832 DK so I am not sure they will work out of the box with nRF52840 DK. I recommend trying to start with the template project example for PCA10056 (nRF52840 DK) in the SDK v15.0.0 (located in SDK/examples/ble_peripheral/pca10056/s140/), add the solution files (our_services.c and .h) and modify both these and main.c as you go along in the tutorial.  You should also increase the UUID count in the sdk_config.h so you don't get any NRF_ERROR_NO_MEM error. Try increasing NRF_SDH_BLE_VS_UUID_COUNT to 4.

    Best Regards,

    Marjeris

  • Hi Marjeris,

    it's the way i did, i started from PCA10056 and i followed the tutorial to understand it and i checked with solution.

    I also tryied to copy files from folder Solution without modification.

    I tryed to increase NRF_SDH_BLE_VS_UUID_COUNT : still err_code 0x07.

    But as i said, if i comment APP_ERROR_CHECK(err_code); (the one with err_code 0x07),

    I can see my module advertising with nRF connect app : advertising is correct, i see the service but it's empty...

Related