Closed
Description
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
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
signed short value;
// extract the temperature
value = (cServiceData[TEMP_MSB] << 8) + cServiceData[TEMP_LSB];
Debug Message
No debug ... just wrong calculated values.
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
Type
Projects
Status
Done
Activity
mrengineer7777 commentedon Dec 28, 2022
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.
SuGlider commentedon Dec 29, 2022
This seems to be just a casting matter.
uint32_t
with just 16 bits in the LSB will be always positive.Casting it to whatever struct or type is an application subject,
notrelated to the BLE Beacon Scanner example.SuGlider commentedon Dec 29, 2022
I'll add this fix. Thanks.
SuGlider commentedon Feb 2, 2023
@PilnyTomas
The temperature is represented in signed 8.8 fixed-point notation and measured in Celsius.
https://github.com/google/eddystone/blob/master/eddystone-tlm/tlm-plain.md
When Temperature is not supported BLE will return 0x8000, which means -128 °C.
In that case, it could be nice to check this value and send out the correct message, instead of reporting the temperature.
Note: All multi-byte values are big-endian --> MSB:LSB
SuGlider commentedon Feb 3, 2023
As we talked, the change shall be in
https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/examples/BLE_Beacon_Scanner/BLE_Beacon_Scanner.ino#L118-L120
I think that it just has to use
signed short
, likeBut it shall be verified by testing some cases, like below:
For instance:
Signed Short Value -32768 = 0x8000 shall be calculated as -128 °C
Signed Short Value -9024 = 0xDCC0 shall be calculated as -35.25 °C
Signed Short Value 9024 = 0x2340 shall be calculated as +35.25 °C
Signed Short Value 384 = 0x0180 shall be calculated as +1.50 °C
Signed Short Value -1024 = 0xFC00 shall be calculated as -4.00 °C
9 remaining items