-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix for negative temp in Eddystone TLM; solving #7618 #7791
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
Changes from 2 commits
ddd6496
1f3a941
cc893d5
f677580
50e1c7e
3ee9d53
125cdee
96faa77
0980a21
a42a513
1f406c6
f638759
c9bf68d
aa5486b
a64613d
5529457
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,7 +115,7 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks | |
foundEddyURL.setData(eddyContent); | ||
Serial.printf("Reported battery voltage: %dmV\n", foundEddyURL.getVolt()); | ||
Serial.printf("Reported temperature from TLM class: %.2fC\n", (double)foundEddyURL.getTemp()); | ||
int temp = (int)payLoad[16] + (int)(payLoad[15] << 8); | ||
int16_t temp = (int16_t)payLoad[16] + (int16_t)(payLoad[15] << 8); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is OK. Another way to do the same: We could improve it by testing if the beacon really supports temperature measuring : // BIG ENDIAN payload in signed 8.8 fixed-point notation. Unit is Celsius.
int16_t temp_payload = payLoad[16] + (payLoad[15] << 8);
if (payLoad[15] == 0x80 && payLoad[16] == 0) {
Serial.printf("This device can't measure temperatures.\n");
} else {
float calcTemp = temp_payload / 256.0f;
Serial.printf("Reported temperature from data: %.2fC\n", calcTemp);
} |
||
float calcTemp = temp / 256.0f; | ||
Serial.printf("Reported temperature from data: %.2fC\n", calcTemp); | ||
Serial.printf("Reported advertise count: %d\n", foundEddyURL.getCount()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ void setBeacon() | |
uint16_t volt = random(2800, 3700); // 3300mV = 3.3V | ||
float tempFloat = random(2000, 3100) / 100.0f; | ||
Serial.printf("Random temperature is %.2fC\n", tempFloat); | ||
int temp = (int)(tempFloat * 256); //(uint16_t)((float)23.00); | ||
int16_t temp = (int16_t)(tempFloat * 256); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The original code is correct. Please revert the change. The |
||
Serial.printf("Converted to 8.8 format %0X%0X\n", (temp >> 8), (temp & 0xFF)); | ||
|
||
BLEAdvertisementData oAdvertisementData = BLEAdvertisementData(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,7 @@ void BLEEddystoneTLM::setVolt(uint16_t volt) { | |
} // setVolt | ||
|
||
void BLEEddystoneTLM::setTemp(float temp) { | ||
m_eddystoneData.temp = (uint16_t)temp; | ||
m_eddystoneData.temp = (int16_t)temp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the C struct with raw data. BUT.... this data shall be 2 bigendian bytes in Fixed Point Notation 8.8 that represents the value of the float... The original code is completely wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we will leave the data model in its original type casting, it is now necessary to cast It is always better to leave the data processing logic in the API code that returns/gets and sets the information. float BLEEddystoneTLM::getTemp() {
return ((int16_t)ENDIAN_CHANGE_U16(m_eddystoneData.temp)) / 256.0f;
} // getTemp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is completely wrong as well. Running that original code line, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also needs to be casted to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Final suggestion: Create a static |
||
} // setTemp | ||
|
||
void BLEEddystoneTLM::setCount(uint32_t advCount) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ class BLEEddystoneTLM { | |
uint8_t frameType; | ||
uint8_t version; | ||
uint16_t volt; | ||
uint16_t temp; | ||
int16_t temp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a packed C struct with raw data from BLE advertising package. Better leave it like in the original code as |
||
uint32_t advCount; | ||
uint32_t tmil; | ||
} __attribute__((packed)) m_eddystoneData; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just changed Line 118 to:
int16_t temp = payLoad[22+5] + (payLoad[22+4] << 8);