Skip to content
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

WEC-2103 checksum algorithm #2661

Closed
tommie opened this issue Oct 6, 2023 · 8 comments · Fixed by #2662
Closed

WEC-2103 checksum algorithm #2661

tommie opened this issue Oct 6, 2023 · 8 comments · Fixed by #2662
Labels
device support Request for a new/improved device decoder

Comments

@tommie
Copy link
Contributor

tommie commented Oct 6, 2023

#2185 added support for WEC-2103, by @tthurnreiter. It never received a resolution about the checksum.

I've spent some time figuring out the protocol of my cheap temp/humidity sensor, and it seems the protocol is identical. Here's a decoder: https://github.com/tommie/tx07k-reverse/

However, I think I also managed to figure out the checksum, though I can't be sure the WEC-2103 and my TX07K-THC (as written on the PCB) are the same. Looking at the WEC-2103 FCC internal photo, it's labeled TX07Y-THC, so very likely the same.

The checksum is a modified/broken CRC-4. I'd love to contribute that, but since I don't, technically, have a WEC-2103 to confirm this with, I'm not sure if it would be accepted. Seeking contribution guidance, or help confirming the checksum.

@zuckschwerdt
Copy link
Collaborator

Your findings look plausible enough and entirely what we expect from those implementations :)

Do the recordings in #2185 (comment) work with your checksum?
If so then just PR the addition.

@merbanan
Copy link
Owner

merbanan commented Oct 6, 2023

@tommie there are some signals and decoded messages you can test the crc-4 code with. One thing I'm not sure this is a broken crc-4 checksum.

uint8_t crc4(uint8_t const message[], unsigned nBytes, uint8_t polynomial, uint8_t init)

compared to

https://github.com/tommie/tx07k-reverse/blob/3907833c7b46ba3116255916ddd04a8eebeb298a/tempdec.py#L28

it looks fairly similar. Maybe it just needs to be reflected? Ie poly 0x9.

@tommie
Copy link
Contributor Author

tommie commented Oct 6, 2023

Re. the CRC-4, the problem is the last operation needs to be an XOR, AFAICT. The normal CRC-4 ends with the shift, which doesn't align with my samples. Though I'm by no means a CRC authority. (I go into depth of this RE process in https://tommie.github.io/a/2023/10/reverse-engineering-checksum).

Confirmed the #2185 recordings pass CRC check.

@tommie
Copy link
Contributor Author

tommie commented Oct 6, 2023

For future reference, the #2185 recordings look like this in hexadecimal:

ec b 8 67b 66 1
ec 6 8 67d 66 1
37 f 8 657 61 1
37 2 8 664 61 1
37 f 8 664 61 2
37 0 0 664 61 3

None of them have batt-low set, but I'll assume it's the same as on my device.

@gdt gdt added the device support Request for a new/improved device decoder label Oct 15, 2023
@zuckschwerdt
Copy link
Collaborator

zuckschwerdt commented Oct 18, 2023

Reordering the CRC-4 in that way has the effect of "laging" the data behind:
The first operations don't do anything but change the init.
Then the data is pushed in (lagging behind the CRC ops), so only the next round processes the data.
The last chunk of data is never processed. The CRC stops short.

I'd say, compared to a normal CRC, this one is a nibble shorter and just xor's the last nibble (instead of CRC'ing it).
(note: that remainder ^= message[byte]; is an optimization, each bit would go in one by one with the conditional.)

@merbanan
Copy link
Owner

This is my interpretation also. The original implementation should possible to use with some light change of the logic.

@zuckschwerdt
Copy link
Collaborator

In other words this is equivalent (tested):

    int crc_received   = b[1] >> 4;

    b[1] = (b[1] & 0x0f) | ((b[4] & 0x0f) << 4); // The last nibble is moved here.

    int crc_calculated = crc4(b, 4, 3, 0) ^ (b[4] >> 4);

It could be that the original CRC used operates byte-wise and the "designers" wanted to patch on a last nibble ;)

@tommie
Copy link
Contributor Author

tommie commented Oct 18, 2023

Thanks for thinking and testing! I've updated #2662.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
device support Request for a new/improved device decoder
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants