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

hrs_c) how to add 'on_read_rsp' function

Hi, I'm using nRF52832 Software Development Kit, PCA10040, S132.
I'm trying to connect the hrs central to my device and read the data from that.
But the feature of my device is that after it's connected, it doesn't send data until it's brought to the skin.

I am trying to read the data by changing the battery UUID.
'BLE_GATTC_EVT_READ_RSP' calls but fails to read data, so 'BLE_GATTC_EVT_HVX' is not called and 'on_hvx' is also not called.
I think I should activate the 'on_read_rsp' function to get the data from my device.
(I think I should call the function one more time.)

So when I press button 3, I want to call one of those functions, but I don't know how to approach it.
I wrote a case statement about pressing button, and I just need to call it.
 case BSP_INDICATE_ALERT_2:
    m_leds_clear = true;
    bsp_board_led_invert(BSP_LED_BUTTON_3);
    err_code = app_timer_start(m_bsp_leds_tmr, APP_TIMER_TICKS(BSP_BUTTON_PUSH_INTERVAL), NULL);
        
    //add here something...?  

    break;
I don't know if this is the right approach, but I can't think of anything else.
Anyway, is there a way to call the 'on_read_rsp' function again?

Besides what I thought, please tell me various solutions.
BR,
lyrics
Parents
  • Hello,

    I am having some issues understanding exactly what you are trying to acheive. 

    Can you try to explain in a less technical way what you want to do? Do you want to send the battery percentage on a button press? Or do you want to send custom data? Either way, I think you have started digging in the wrong areas. Please let me know what you want to acheive, and perhaps I can suggest some way to do so. Also, I think you should change the battery service UUID back. Most likely, this is not allowing you to do what you want to. 

    Best regards,

    Edvin

Reply
  • Hello,

    I am having some issues understanding exactly what you are trying to acheive. 

    Can you try to explain in a less technical way what you want to do? Do you want to send the battery percentage on a button press? Or do you want to send custom data? Either way, I think you have started digging in the wrong areas. Please let me know what you want to acheive, and perhaps I can suggest some way to do so. Also, I think you should change the battery service UUID back. Most likely, this is not allowing you to do what you want to. 

    Best regards,

    Edvin

Children
  • Hello, thank you for your answer.

    I'll explain what I'm trying to do more accurately.


    I would like to have my device custom data received by central.

    This is using the nRF connect program.

      

    After pressing the notification button (red circle),
    let my device send data, and then press the read button below.

    Then read the changed charteristic value.
    I would like to read the value of that characteristic from the nordic central as well.

    The connection was successful, but the value could not be read.
    I think it's because BLE_GATTC_EVT_HVX wasn't called, but I can't find the reason.

    How should I approach it?

  • I suggest that you check out the examples: ble_app_uart and ble_app_uart_c instead of the ble_app_hrs_c example. 

     

    lyrics said:
    I think it's because BLE_GATTC_EVT_HVX wasn't called, but I can't find the reason.

     Where do you call it from? I am not sure I understand. You talk about the ble_app_hrs_c example, but your screenshots are from nRF Connect. What are you connected to? It looks like you are connected to a peripheral, but the ble_app_hrs_c is a central. 

  • I suggest that you check out the examples: ble_app_uart and ble_app_uart_c instead of the ble_app_hrs_c example. 

    ok, thank you. I studied a little bit, but I'll try again.

    You talk about the ble_app_hrs_c example, but your screenshots are from nRF Connect.

    That screenshot was just a description of how to get values from my device.

    If those screenshots are confusing, you don't have to mind.

    It seems that trying to explain in detail rather confused you. :) ...

    What are you connected to?

    I want to connect my central Nordic device with my peripheral device.

    So I want to modify the example of hrs_c to connect the two devices and read the data of peripheral.

    Where do you call it from?

    According to this, "After notifications are enabled, new notifications arrive as BLE_GATTC_EVT_HVX ble events. "

    So, 

    static void bas_c_evt_handler(ble_bas_c_t * p_bas_c, ble_bas_c_evt_t * p_bas_c_evt)
    {
        ret_code_t err_code;
    
        switch (p_bas_c_evt->evt_type)
        {
            case BLE_BAS_C_EVT_DISCOVERY_COMPLETE:
            {
                err_code = ble_bas_c_handles_assign(p_bas_c,
                                                    p_bas_c_evt->conn_handle,
                                                    &p_bas_c_evt->params.bas_db);
                APP_ERROR_CHECK(err_code);
    
                // Battery service discovered. Enable notification of Battery Level.
                NRF_LOG_DEBUG("Battery Service discovered. Reading battery level.");
    
                err_code = ble_bas_c_bl_read(p_bas_c);
                APP_ERROR_CHECK(err_code);
    
                NRF_LOG_DEBUG("Enabling Battery Level Notification.");
                err_code = ble_bas_c_bl_notif_enable(p_bas_c);
                APP_ERROR_CHECK(err_code);
    
            } break;

    I thought BLE_GATTC_EVT_HVX would be called if there was no error in this part (line21).

  • Ok. What confused me is that you mention the ble_app_hrs_c example, but your screenshot is from a connection with a peripheral. The ble_app_hrs_c is a central. So these are not connected at the same time?

    So perhaps you can just use notifications when you send data from your peripheral to your centrals, or do you need to use the "read" function specifically? In my opinion using notifications is better, because you don't need to poll all the time to check if the value is updated.

     

    lyrics said:
    So I want to modify the example of hrs_c to connect the two devices and read the data of peripheral.

     What kind of data? Is it heart rate data, or can you use the ble_app_uart peripheral? 

  • but your screenshot is from a connection with a peripheral.

    Yes.. 

    Those screenshots show 'My own device' connected to the nRF connect.
    Because it was to explain what data I wanted to receive through the picture.

    In other words, I would like to connect with my own device through the example of hrs_c, as if it were connected to nRF. And I want to read the data that my device sends.
    (Just in case, I organized it one more time. I hope you understand)

    So these are not connected at the same time?

    It is not connected at the same time, but only with hrs_c and my own device.

    What kind of data? Is it heart rate data, or can you use the ble_app_uart peripheral? 

    The data my device sends is not a heart rate.
    It sends long data continuously, such as the yellow underline of screenshots.

    or can you use the ble_app_uart peripheral? 

    I'm not sure I understand. My device is like beacon.. I can't use that example.

Related