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

Characteristic Value Read

Hello together,

i know, there are similar questions about "Reading Characteristic Value", but i don't get a solution for me. My Problem: I use nRF51DK with SD130 and the Example Project from the Characteristics Tutorial. I added 1 service and 2 characteristics with each 5 bytes.

image description

Service: UUID: 0x2800 Handle: 0x000C

Char Decl. UUID: 0x2803 Handle: 0x000D

Char Value: UUID: 0x0001 Handle: 0x000E Array: 01-02-03-00-00

Char2 Decl. UUID: 0x2803 Handle: 0x000F

Char2 Value: UUID: 0x0002 Handle: 0x0010 Array: 00-00-00-00-00

I set the permissions for read and write and i can read out and change the values with my smartphone. Now i want to do something with this 10(2x5) bytes from the peripheral device. And here is my problem. I need them at different times while running, not only when writing/written, and i dont get it, to read these bytes out.

I tried this in the main loop for a simple test to read the value 01-02-03-00-00 of Char1:

   	ble_gatts_value_t *  	temp;
    memset(&temp, 0, sizeof(ble_gatts_value_t));
    err_code = sd_ble_gatts_value_get(BLE_CONN_HANDLE_INVALID, 0x000E, temp);
    APP_ERROR_CHECK(err_code);

But i only get the err_code 0x00000010.

image description

I hope u understand what i mean/need. Perhaps you can help me. Thanks a lot.

Parents
  • FormerMember
    0 FormerMember

    ble_gatts_value_t is defined the following way:

    typedef struct
    {
      uint16_t  len;       
      uint16_t  offset;    
      uint8_t   *p_value;   
    } ble_gatts_value_t;
    

    In your example, in order to make temp contain the value of the attribute after calling sd_ble_gatts_value_get(), p_value in ble_gatts_value_t has to be set to point to a location:

    uint8_t location_for_my_value;
    
    
    temp.p_value   = &location_for_my_value;
    temp.len      = number_of_bytes_you_want_to_read;
    temp.offset   = 0;
    err_code = sd_ble_gatts_value_set(BLE_CONN_HANDLE_INVALID, 0x000E, temp);
    

    To make the code more robust, I would recommend you to refer to the reference for the attribute handle value, rather than hard code the handle value. For retrieving the battery level value in the ble_app_hrs example in the SDK, it would be the following:

    err_code = sd_ble_gatts_value_set(m_conn_handle,m_bas.battery_level_handles.value_handle, temp);
    
  • what if location_for_my_value is an array of 16 values of uint8_t?

    i set the temp.len to 16, but whenever I printf the resulted array, I get the same values all the time, which seem to be addresses, not the actual data.

Reply Children
Related