-
Notifications
You must be signed in to change notification settings - Fork 7.6k
BLE Beacon Scanner example might not handle negative temperatures? #7618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Your sketch doesn't match the example. Note the (int) cast on each payload byte. Also we don't have your hardware. It would be very helpful to know the actual bytes received in ServiceData[] as well as the actual temperature. |
This seems to be just a casting matter. Casting it to whatever struct or type is an application subject, |
I'll add this fix. Thanks. |
The temperature is represented in signed 8.8 fixed-point notation and measured in Celsius. When Temperature is not supported BLE will return 0x8000, which means -128 °C. Note: All multi-byte values are big-endian --> MSB:LSB |
As we talked, the change shall be in I think that it just has to use // BIG ENDIAN payload in signed 8.8 fixed-ppint notation. Unit is Celsius.
int16_t temp_payload = payLoad[16] + (payLoad[15] << 8);
if (payLoad[15] == 0x80 && payLoad[16] == 0) {
Serial.printf("This device does not support measuring temperature.\n");
} else {
float calcTemp = temp_payload / 256.0f;
Serial.printf("Reported temperature from data: %.2fC\n", calcTemp);
} But it shall be verified by testing some cases, like below: For instance: Signed Short Value -32768 = 0x8000 shall be calculated as -128 °C |
@PilnyTomas - The exactly same issue also happens with the code in This also needs to be fixed. |
@Humancell could you please try the change in #7791 ? |
* Changed data type of temperature * Changed data type in EddystoneTLM class and example * Revert "Changed data type in EddystoneTLM class and example" This reverts commit 1f3a941. * Draft of Eddystone TLM example * Adds MACROs to convert beacon temperature 2 Macros EDDYSTONE_TEMP_U16_TO_FLOAT(tempU16) - takes the TLM BigEndian 8.8 fixed point representation and returns its float value EDDYSTONE_TEMP_FLOAT_TO_U16(tempFloat) - takes a float (temperature) and returns its BigEndian 8.8 fixed point representation * Fixed temp * Changed to conform with PR comments * Fixed comment on closing bracket * Prints negative TEMP big endian as just 2 bytes * Extacts correct Eddyston Service Data * Fixes BLEEddystoneTLM::toString() negative temp * Fixes URL field length * Fixes Eddystone URL decoding * Fixes MSB for iBeacon UUID iBeacons use big endian BLE fields. * Fix to detect iBeacon that also has Service UUID This fix makes the BLE_iBeacon.ino to work correctly with the BLE_Beacon_Scanner.ino example --------- Co-authored-by: Rodrigo Garcia <[email protected]>
Board
Olimex ESP32 PoE ISO
Device Description
PoE PCB using the ESP32 WROOM 32UE
Hardware Configuration
Nothing special
Version
latest master (checkout manually)
IDE Name
Arduino IDE
Operating System
All
Flash frequency
80Mhz
PSRAM enabled
no
Upload speed
115200
Description
https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/examples/BLE_Beacon_Scanner/BLE_Beacon_Scanner.ino#L118
When low temperatures occur, and go below 0 C, the calculations do not seem to be correct. It appears that using these 16-bit values in a 32-bit INT doesn't detect/use twos complement to handle the negative numbers properly.
In my final code I moved to a "signed short" which seems to fix the issue.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: