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

How to get the characteristic data with array?

Hi.

I have a customize characteristic that allow user to typing 8 bytes of data send from cell phone,

And I want to get this buffer out to go with my process, but I used sd_ble_gatts_value_get() I get the data seems like the register address.

Also the ble_gatts_evt_write_t -> data[1] called in on_write function that only stored with 1 bytes.

So how can I get the full buffer of data? Is there a example or some tutorial that shows how to do it?

Thanks.

Parents
  • Hello,

    If you see in the ble_gatts.h file in the SDK on line 353 (in SDK15), it says:

      uint8_t                     data[1];            /**< Received data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
                                                           See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */

     

    So the data coming at the event is longer than 1 byte. The length of the array is 

    ble_gatts_evt_write_t->len;

    the 1 is only a placeholder for the compilator.

     

    You can check out the ble_app_uart example found in SDK\examples\ble_peripheral\ble_app_uart. In main.c, you will see a function called nus_data_handler(...)

    It is actually a ble_gatts_evt_write_t event, but it is "translated" to a NUS (Nordic UART Service) event in ble_nus.c, in the on_write() function, then calling the nus_data_handler(...) with the translated event. 

    You can see that 

    evt.params.rx_data.p_data = p_evt_write->data;

    evt.params.rx_data.length = p_evt_write->len;

    and that these are used in the nus_data_handler(...) in main.c.

     

    Best regards,

    Edvin

  • Hi Edvin

    Thanks for your help, now I known relation of that.

    The problem has resolved, thanks.

Reply Children
No Data
Related