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

How to display float number in MCP App?

Hi there!

I want to send a float from nRF51822 to MCP App. I use this code:

float m_temperature = 26.3f;
uint8_array_t temperature_data_array;
temperature_data_array.p_data = (uint8_t*)(&m_temperature);
temperature_data_array.size = sizeof(m_temperature);

ble_advdata_service_data_t service_data[1] = {{APP_TEMPERATURE_UUID, temperature_data_array},
												};

sradvdata.p_service_data_array    = service_data;                // Pointer to Service Data structure.
sradvdata.service_data_count      = 1;
ble_advdata_set(&advdata, &sradvdata);

But in MCP App, It display "-Infinity" error when I select data format Float32.

Thanks.

Parents
  • Hi

    I believe this is an issue regarding endianness and floating point formats. Bluetooth and our SDKs are using the IEEE-11073 format while the app is using IEEE-754 format. Here is an overveiw of what the IEEE-11073 is all about.

    IEEE-11073 standard (from PDF):

    image description

    IEEE-754 standard:

    image description

    The endianness issue is discussed here.

    It seems like there is an easy fix on the Android side (I have not tried it), but it is not implemented in the app. If you look in the ble_app_hts example in the SDK you can see how the temperature value's exponent and mantissa is stored in a struct:

    typedef struct
    {
      int8_t  exponent;   /**< Base 10 exponent */
      int32_t mantissa;   /**< Mantissa, should be using only 24 bits */
    } ieee_float32_t;
    

    Before transmission the exponent and mantissa are encoded into a four bytes long buffer and the bytes are reversed (it happens in hts_measurement_encode() in the SDK example). Finally the float is treated as a 11073 format float on the other side.

Reply
  • Hi

    I believe this is an issue regarding endianness and floating point formats. Bluetooth and our SDKs are using the IEEE-11073 format while the app is using IEEE-754 format. Here is an overveiw of what the IEEE-11073 is all about.

    IEEE-11073 standard (from PDF):

    image description

    IEEE-754 standard:

    image description

    The endianness issue is discussed here.

    It seems like there is an easy fix on the Android side (I have not tried it), but it is not implemented in the app. If you look in the ble_app_hts example in the SDK you can see how the temperature value's exponent and mantissa is stored in a struct:

    typedef struct
    {
      int8_t  exponent;   /**< Base 10 exponent */
      int32_t mantissa;   /**< Mantissa, should be using only 24 bits */
    } ieee_float32_t;
    

    Before transmission the exponent and mantissa are encoded into a four bytes long buffer and the bytes are reversed (it happens in hts_measurement_encode() in the SDK example). Finally the float is treated as a 11073 format float on the other side.

Children
No Data
Related