cyberman54 / ESP32-Paxcounter

Wifi & BLE driven passenger flow metering with cheap ESP32 boards

Home Page:https://cyberman54.github.io/ESP32-Paxcounter/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Endian Encoding wrong: BMExxx Temperature in Mode PAYLOAD_ENCODER == 2

commeco opened this issue · comments

Hello,
imho in the case of PAYLOAD_ENCODER == 2 the endian encoding here is wrong.

buffer[cursor++] = (byte)((t >> 8) & 0xFF);

The lines 287 and 288 have to be switched.

Or am i wrong? :)

Regards Matthias

Why do you think the endianess is wrong? It depends on your decoder. If you use the enclosed encoder, it should work. Float conversion is used for temperature values.

The code was taken from https://github.com/thesolarnomad/lora-serialization/tree/master

Hi,
the code itself is correct, but it's the same endian here like in PAYLOAD_DECODER == 1.

e.g. PAYLOAD_ENCODER == 1

void PayloadConvert::addVoltage(uint16_t value) {
buffer[cursor++] = highByte(value);
buffer[cursor++] = lowByte(value);
}

Definition of the highByte macro
-> #define highByte(w) ((uint8_t) ((w) >> 8))

And in PAYLOAD_DECODER == 2 the order is the same, and that is imho wrong.
buffer[cursor++] = (byte)((t >> 8) & 0xFF);
buffer[cursor++] = (byte)t & 0xFF;

Regards
Matthias

What's the problem here? If it is matching with the logic of the decoder, it has no impact?

I understand. But we don't use the TTN Decoder backend. We use the Webhook integration and wrote our own "encoder" in PHP, based on the documentation here: https://cyberman54.github.io/ESP32-Paxcounter/payloadformat/
In the documentation isn't mentioned that the temperature float values (Function writeFloat) are always represented in big endian. Anyway, if no one else have a problem, than i solve it on my side. :)

Regards
Matthias

Thus, we have a documentation problem, not a code issue. I will edit the docs. Thanks for your hint!

You're welcome. :)