h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
667 stars 138 forks source link

Error in converting EddystoneTLM negative temperatures to float #675

Closed giovanni-foorban closed 3 weeks ago

giovanni-foorban commented 4 weeks ago

In NimBLEEddystoneTLM.cpp there is an issue when receiving negative numbers for temperature readings and when setting temperature.

For example: -0,1C is converted to approximately 256C.

On our side we fixed the issue like this:

/**
 * @brief Set the temperature to advertise.
 * @param [in] temp The temperature value.
 */
void NimBLEEddystoneTLM::setTemp(float temp) {
-  m_eddystoneData.temp = (uint16_t)temp;
+  m_eddystoneData.temp = ENDIAN_CHANGE_U16((int16_t)(temp * 256.0f)) ;
} // setTemp
/**
 * @brief Get the temperature being advertised.
 * @return The temperature value.
 */
float NimBLEEddystoneTLM::getTemp() {
-    return ENDIAN_CHANGE_U16(m_eddystoneData.temp) / 256.0f;
+ return (int16_t)ENDIAN_CHANGE_U16(m_eddystoneData.temp) / 256.0f;
} // getTemp
h2zero commented 4 weeks ago

Thanks! would you mind making a PR for this?

Max93 commented 4 weeks ago

Hello @h2zero

I am a colleague of Giovanni (@giovanni-foorban), who opened this issue. I have created a pull request to address the problem with negative temperature readings #677.

You can find the pull request here.

Thank you for your attention.

Max93 commented 3 weeks ago

Hi @h2zero, when are you planning the next release ? Was it right to open the pr to release 1.4 ?

h2zero commented 3 weeks ago

I'll look to make a new release soon, hard to say when exactly