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

How to correctly read from a Characteristic

Good evening, 

   I had a question in respect to the exact procedure needed to read a characteristic with read permissions. I have just discovered a service i would like to read using the discovery module however I am a bit confused as to what i should do to read the values. From my understanding, after successfully discovering the services i can use the function sd_ble_gattc_char_value_by_uuid_read() to read the data. From there, the event  BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP will occur someplace in the application. Is this correct? Also, once i trigger  BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP which struct withing the characteristic will contain the attribute data? 

Thank you any help is very much appreciated. I am using nrf52840 board with SDK 15.0. I have modified the BLE_CENTRAL_MULTILINK example. Again, i am trying to make my central application read a characteristic sent by a peripheral. 

Parents
  • Would it be a possibility to send a notification from the peripheral to the central device like it is done in the multilink central & the ble_blinky peripheral example? Whenever you press button 1 on the peripheral nRF52 DK, you should receive a BLE_LBS_C_EVT_BUTTON_NOTIFICATION on the central in the lbs_c_evt_handler (multilink ex). This should work out of the box.

    You can check the logging by opening some kind of terminal emulator (e.g. teraterm), set the baudrate to 115200 & reset both boards by pressing the IF BOOT/RESET button on each DK.

  • Unfortunately the characteristic only has read permissions and i did not write the characteristic value and cannot edit the device.......However, I have successfully managed to read the first byte of a 16 byte attribute using sd_ble_gattc_read() but i cannot read the other 15 bytes. Is there a specific way in which i can read the final 15 bytes? Do i just consecutively call the function sd_ble_gattc_read() to read the rest? do i call the function, wait for a response and the call the function again? Please any help with this would be very much appreciated.  

  • Are you by any chance noticing the same problem that this user had? Could it be as simple as that the sd_ble_gattc_read() function returns all 16 bytes, but the IDE is only showing the first byte? Or that you are only printing out the first byte?

    In the description above the sd_ble_gattc_read() function in ble_gattc.h, you can read the following:

    "This function initiates or resumes a GATT Read (Long) Characteristic or Descriptor procedure. If the Characteristic or Descriptor
    * to be read is longer than ATT_MTU - 1, this function must be called multiple times with appropriate offset to read the
    * complete value."

    But unless you have made changes to the ATT_MTU value, it will most likely be BLE_GATT_ATT_MTU_DEFAULT, which is 23 by default. 

Reply
  • Are you by any chance noticing the same problem that this user had? Could it be as simple as that the sd_ble_gattc_read() function returns all 16 bytes, but the IDE is only showing the first byte? Or that you are only printing out the first byte?

    In the description above the sd_ble_gattc_read() function in ble_gattc.h, you can read the following:

    "This function initiates or resumes a GATT Read (Long) Characteristic or Descriptor procedure. If the Characteristic or Descriptor
    * to be read is longer than ATT_MTU - 1, this function must be called multiple times with appropriate offset to read the
    * complete value."

    But unless you have made changes to the ATT_MTU value, it will most likely be BLE_GATT_ATT_MTU_DEFAULT, which is 23 by default. 

Children
Related