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

how to received data from peripheral?

Hi, I'm using nRF52832 Software Development Kit, PCA10040, S132.

I am trying to test ble_app_blinky_c.

I have problem with received data from peripheral which is my own BLE device.

First of all, I tested blinky central and peripheral with two nordic borad.

When I pressed peripheral button 1, breakpoint stop at "case BLE_GATTC_EVT_HVX:"

void ble_lbs_c_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
    if ((p_context == NULL) || (p_ble_evt == NULL))
    {
        return;
    }

    ble_lbs_c_t * p_ble_lbs_c = (ble_lbs_c_t *)p_context;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
            on_hvx(p_ble_lbs_c, p_ble_evt);
            break;

        case BLE_GATTC_EVT_HVX:
            on_hvx(p_ble_lbs_c, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnected(p_ble_lbs_c, p_ble_evt);
            break;

        default:
            break;
    }
}

 

In ble_app_blinky_c, I found that the change in the charteristic status of the peripheral was received from on_hvx() of BLE_GATTC_EVT_HVX.

All I want to do is just read the data from the bl device and record it on the terminal.

To do this, can I use BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP?

Is this the right way to add cases above code like this, 

Switch (p_ble_evt->header.evt_id)
{
Case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
on_hvx (p_ble_lbs_c, p_ble_evt);
break;

...

or... Should I create a new function in main()?

 

* I think it might be difficult to understand the intent of my question because I didn't fully understand the example code.
My key problem is that I don't know where the data from my device is located in the example.
(or I don't know how to add the code.)

Best Regards,

Lyrics

  • Hello Lyrics,

    First of all, I tested blinky central and peripheral with two nordic borad.

    When I pressed peripheral button 1, breakpoint stop at "case BLE_GATTC_EVT_HVX:"

    Yes, the BLE Blinky application uses notifications to alert the connected device that the button has been pressed.
    The BLE_GATTC_EVT_HVX event is generated when a notification is received, which contains all the events information

    All I want to do is just read the data from the bl device and record it on the terminal.

    To do this, can I use BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP?
    or... Should I create a new function in main()?

    I would not recommend that you make changes in the drivers directly - since this may break the drivers, or place it in an invalid state.
    In this particular case, the button-led-central module does this information processing for you, and then sends an event to the applications lbs_c_evt_handler, which handles the button led information in the BLE_LBS_C_EVT_BUTTON_NOTIFICATION case of the handler. From there, you could write out any of the contents of the BLE_LBS_C_EVT_BUTTON_NOTIFICATION, if you would like.

    If you instead are looking for the general method to receive data transferred over BLE in your application, you could instead take a look at the ble_app_uart example, which does exactly this - with very little other things going on.

    I think it might be difficult to understand the intent of my question because I didn't fully understand the example code.

    I might not have understood your intentions correctly - so if my reply above does not answer your questions, please do not hesitate to let me know!
    In that case, please elaborate exactly what you would like to see happening in your application / what functionality you would like to extract from the example.

    Best regards,
    Karl

  • Thank you very much for your quick reply.
    I understood the basics.
    And I will study again with 'ble_app_uart_c'.

    Few more questions.

    Does the example ble_app_blinky_c handler only the events caused by the button?
    In addition, can't we use 'BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP' to bring the charterical values?

  • lyrics said:
    Thank you very much for your quick reply.

    No problem at all, I am happy to help!

    lyrics said:
    I understood the basics.
    And I will study again with 'ble_app_uart_c'.

    Great, just let me know if you should have any further questions on this!

    lyrics said:
    Does the example ble_app_blinky_c handler only the events caused by the button?

    The button LED notification service is made to send a notification if a button is pressed in order to set a LED, as such, the connected device will only receive button and LED information through this service - since it is its only contents.
    I am not sure if this is what you were asking about. As you can see from the ble_app_blinky_c lbs event handler, it handles all ( both ) of the available LBS events.

    lyrics said:
    In addition, can't we use 'BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP' to bring the charterical values?

    That depends, which data exactly are you interested in seeing?
    If you would like to see the contents of a received notification, you should use the contents of the BLE_GATTC_EVT_HVX event instead.

    Best regards,
    Karl

Related