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

Higher precision in BLE_UUID_HEALTH_THERMOMETER_SERVICE

Hi,

I am trying to include temperature (read from DS18B20) in advertisement data using BLE_UUID_HEALTH_THERMOMETER_SERVICE. So far it works fine, but my temperature is multiplied by 10 (234 instead of 23.4). I use following code (inspired by examples I found), on nrf51822:

  uint32_t temperature_data = measure_temp_ds18b20();

  service_data[1].service_uuid = BLE_UUID_HEALTH_THERMOMETER_SERVICE;
  service_data[1].data.size    = sizeof(temperature_data);
  service_data[1].data.p_data  = (uint8_t *) &temperature_data;

Temperature is shown correctly (e.g. in nRF Temp app on android) but of course as 234, instead of 23.4. Is it possible to send this value as fractional?

greetings, Bartek

Parents
  • Hi Michael, thanks for answer. My measurement function returns temperature multiplied by ten, but of course I know how to get 23.4f from 234. But I don't how to put this float into service_data[1].data (or how to put '234' but inform "client" that information is of factor 10x). I'm really new to this stuff so I would appreciate working example. As nrfTemp shows temperature with one digit precision (23.0) so I guess there is a way to send out this information in a way it is interpreted correctly by BLE client. Bartek

Reply
  • Hi Michael, thanks for answer. My measurement function returns temperature multiplied by ten, but of course I know how to get 23.4f from 234. But I don't how to put this float into service_data[1].data (or how to put '234' but inform "client" that information is of factor 10x). I'm really new to this stuff so I would appreciate working example. As nrfTemp shows temperature with one digit precision (23.0) so I guess there is a way to send out this information in a way it is interpreted correctly by BLE client. Bartek

Children
No Data
Related