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

how to send float value using Heart Rate Monitor example code and nrf51 DK

Hi, I am using Heart Rate rate monitor code to send floating value instead of unit16_t.

I am using the heart rate service to send the data. Instead of using simulated sensor function, I have explicitly declared the heart rate to be 5.29. I eventually want to send ADC value using this service which will have floating numbers. App ( Heart Rate App in nRF toolbox) still shows 5 instead of 5.29. Where else should I make a change?

static void heart_rate_meas_timeout_handler(void * p_context){
   static uint32_t cnt = 0;
   uint32_t        err_code;
   double       heart_rate;     //Changed from unit16_t

UNUSED_PARAMETER(p_context);

heart_rate = 5.29;           //instead simulated sensor data
cnt++;
err_code = ble_hrs_heart_rate_measurement_send(&m_hrs, heart_rate);
if ((err_code != NRF_SUCCESS) &&
    (err_code != NRF_ERROR_INVALID_STATE) &&
    (err_code != BLE_ERROR_NO_TX_BUFFERS) &&
    (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
    )
{
    APP_ERROR_HANDLER(err_code);
}

// Disable RR Interval recording every third heart rate measurement.
// NOTE: An application will normally not do this. It is done here just for testing generation
//       of messages without RR Interval measurements.
m_rr_interval_enabled = ((cnt % 3) != 0);

}

Parents
  • Well you can't really change it - the Heart Rate Service has a specification which defines the heart rate to be a uint8_t or uint16_t, so if you change it to a double, that's no longer compatible with the spec so it's not the heart rate service any more.

    As a basic C programming question the answer is ble_hrs_heart_rate_measurement_send() which is defined to take a uint16_t so it will convert any argument to a uint16_t. Changing that requires changing the source to ble_hrs.c which then violates the text at the top of that file about certification, as it should, see me comments in the first paragraph.

  • well if what you're doing is a real BTLE defined service, use that, if it's not, then you need to create a custom service. You can do what many people do which is use the Nordic UART Service, that's just data, send what you want, just shuffle it into a byte format you define (endianess, data format), pop it in the buffer and send it. If your service is simple and just wants to send out a double, writing your own is pretty simple.

Reply
  • well if what you're doing is a real BTLE defined service, use that, if it's not, then you need to create a custom service. You can do what many people do which is use the Nordic UART Service, that's just data, send what you want, just shuffle it into a byte format you define (endianess, data format), pop it in the buffer and send it. If your service is simple and just wants to send out a double, writing your own is pretty simple.

Children
No Data
Related