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

Getting data from characteristic

Hello,

I'm using nrf52832, sdk17 and Seeger Embedded Studio. I am using ble_app_uart example.

I am connecting with my phone and using RX and TX characteristics. My question is how can I get the data of RX characteristic to a basic variable?

I know that when I write a data from my phone to characteristic, the application is getting data from BLE and writing to uart. I want it to also write to a variable. The point of my question is I am not sure how can I get the data written in some characteristic from main function. How can I get it, can you share me a basic code to do that.

Thank you for your support.

Parents
  • Hi

    In the main.c file you will find a function called nus_data_handler(ble_nus_evt_t * p_evt), which is called every time the nRF device receives some data from the connected central (phone typically). 

    The p_evt parameter contains the data, stored as a byte buffer, and you can get access to these bytes through the p_evt->params.rx_data.p_data and p_evt->params.rx_data.length fields. 

    To store this to a variable you can add your own code here, and remove the original code writing to the UART if you want. 

    Best regards
    Torbjørn

Reply
  • Hi

    In the main.c file you will find a function called nus_data_handler(ble_nus_evt_t * p_evt), which is called every time the nRF device receives some data from the connected central (phone typically). 

    The p_evt parameter contains the data, stored as a byte buffer, and you can get access to these bytes through the p_evt->params.rx_data.p_data and p_evt->params.rx_data.length fields. 

    To store this to a variable you can add your own code here, and remove the original code writing to the UART if you want. 

    Best regards
    Torbjørn

Children
Related