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

Heart Rate collector example - how is it suppose to work?

Hi, 

i'm running the Heart Rate collector example and have a question. What is the expected behaviour? From the description on the infocenter I read that it should print out the HR reading from the connected HRM. And while it does so the first time I run it on a fresh dongle, it doesn't do it the next time or any other time for that matter. I cannot figure out the difference and don't know what is going on. The following runs only print out the following info on the log:

00> <info> app_timer: RTC: initialized.
00> 
00> <info> app: Heart Rate collector example started.
00> 
00> <info> app: Starting scan.
00> 
00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
00> 
00> <info> app: Connected.
00> 
00> <info> app: GATT ATT MTU on connection 0x0 changed to 23.
00> 
00> <info> peer_manager_handler: Connection secured: role: Central, conn_handle: 0, procedure: Encryption
00> 
00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
00> 
00> <info> app: Data length for connection 0x0 updated to 27.
00> 
00> <info> peer_manager_handler: Connection secured: role: Central, conn_handle: 0, procedure: Encryption
00> 
00> <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change
00> 
00> <info> app: Battery Level Read as 85 %.

PS: I use the NRF52 dongle together with a j-link debugger and I'm displyaing the logs via RTT. I use the example from the SDK 17.0.2, with SD 340.

  • Hi Lukasz,

    I added this code into bsp_event_handler() and can enable notification without service discovery. When pressing button 4 on the DK it will send the write request. 

    2133.main.zip


    You may want to modify the handle to 0x0028 as in the Garmin HRM. Also service discovery need to be disabled. 

    Is there any chance that the Garmin HRM only response to the paired device and you may need to clear all paired device before it response  ? 

  • Hi. I tried modyfing the handle to 0x0028 but with no luck. I think service discovery is disbaled. I removed the peer_manager entirely, so there is no pairing/bonding. Also I think pairing is NOT required as the HRM sends notofication to NRF Connect BLE app on my PC, and there is no pairing there. 

    I deleted the whole pairing information from the device as well (I cleared the flash and installed the Softdevice and my program again).

    Today I also tried calling sd_ble_gattc_write directly. I ended up just adding the following code to the ble_evt_handler (case BLE_GAP_EVT_CONNECTED:)

    err_code = nrf_ble_gq_conn_handle_register(m_hrs_c.p_gatt_queue, p_ble_evt->evt.gap_evt.conn_handle);			
    APP_ERROR_CHECK(err_code);
    
    ble_gattc_write_params_t params;
    					
    uint16_t cccd_val = 1;
    uint8_t cccd[2];
    
    // originally it was reversed, but then it sends 0x0100, and it should send 0x0001?
    cccd[1] = LSB_16(cccd_val);
    cccd[0] = MSB_16(cccd_val);
    					
    params.write_op = 1;
    params.offset = 0;		
    params.handle = 0x0028;
    params.len = 2;
    params.p_value = cccd;
    
    err_code = sd_ble_gattc_write(p_ble_evt->evt.gap_evt.conn_handle, &params);
    APP_ERROR_CHECK(err_code);

    The results are basically the same all the time.

    PS: I did try both 0x0100 and 0x0001. I understand it should be in little endian, but I just checked both ways to eliminate all possible mistakes.

    After your last reply I also skipped nrf_ble_gq_conn_handle_register and just used the m_conn_handle.The code is simpler but works the same :(

    I tried lookng for some information about garmin HRM specific BLE data, but coudln't find anything. I also tried removing the batter from the HRM itself to somehow reset it, but with no luck.

    I'm looking for some other ideas. Do you have any?

  • I would suggest to try using a phone or other central device to connect to the HRM and check if it can receive the notification. 

    In the sniffer trace have you checked if the write request and the write response is exactly the same as when the nRF Connect on PC connected to the HRM ? 
    If they are matched I don't see any reason why the notification shouldn't sent. 
    Please try to test on the ble_app_hrs to check if you can get the notification. Then please try to test on other HRM device on the market. If it works with other HRM device then it's could be something tricky with the Garmin one. 

  • I did try to get notifications on my phone. I used NRF Connect BLE for my android phone and it works. I can enable and disable the notifications without any problems.

    However there is something strange happening to the HRM when I try to use the NRF Connect BLE on my PC now, Wireshark shows that the HRM sends notifications as soon as I connect to it from my PC. It sends them right away and I cannot stop it. I can't even expand the Heart Rate section - it freezes (see the screen). 

    Is it possible that the HRM somehow remembers my PC? Or maybe it's the dongle that stored some information and enables the notifications instantly when connected?

    Is there a way I could have broken the HRM by sending some weird data to wrong handles? I guess it shouldn't be possible, but maybe?

  • If you see the HRM send notification as soon as you connect to it meaning that it's bonded and stored the CCCD value so it send the notification automatically. 
    The nRF COnnect on PC on the other hand may not store the bond information or cache the CCCD value. For some reason the Heart Rate service discovery wasn't finished properly. 
    I think you would need to find a way to erase bonding on the HRM or at least set it to pairing mode to pair again. 

Related