# Mr Cool Remote Control Checksum Algorithm

For fun I've decided to reverse engineer the Mr Cool IR Remote, and build my own version of it.

I've been able to capture the IR sequence for a lot of different button presses. It appears to use a coding scheme similar to the NEC standard, the main difference being it appears to be Msb first. I think it is Msb first because the byte that I think represents the temperature changes logically if I assume Msb first, if I assume Lsb first then it is not as logical. Below is a table of values I've captured along with the associated button press. What I can't make heads or tails of is how the last byte, which I assume is a checksum, is calculated. I've tried various combinations of sums and XOR and haven't gotten it. Any help/tips or tricks for figuring out the algorithm to calculate the last byte would be greatly appreciated. Note, I tried to ask ChatGPT and Bard AI to help and they were laughably bad, so hopefully us normal humans can figure this out!

• Here are the values if you want to copy and paste, in multi posts due to character limit: A1826AFFFF67 A18269FFFF65 A18268FFFF64 A18267FFFF6A A18266FFFF6B A18265FFFF69 A18264FFFF68 A1A06AFFFF44 A1A069FFFF47 A1A068FFFF46 A1A067FFFF49 A1A066FFFF48 A1A065FFFF4B A1A064FFFF4A A1886AFFFF68 A18869FFFF6B A18868FFFF6A A18867FFFF61 A18866FFFF60 A18865FFFF63 A18864FFFF62 A1906AFFFF78 A19069FFFF7B A19068FFFF7A A19067FFFF71 A19066FFFF70 A19065FFFF73 A19064FFFF72 A1986AFFFF70 A19869FFFF73 A19868FFFF72 A19867FFFF7E A19866FFFF7F A19865FFFF7D A19864FFFF7C A1816AFFFF65 Commented Sep 3, 2023 at 23:15
• A18169FFFF66 A18168FFFF67 A18167FFFF68 A18166FFFF69 A18165FFFF6A A18164FFFF6B A1A36AFFFF46 A1A369FFFF44 A1A368FFFF45 A1A367FFFF4B A1A366FFFF4A A1A365FFFF48 A1A364FFFF49 A18B6AFFFF6A A18B69FFFF68 A18B68FFFF69 A18B67FFFF63 A18B66FFFF62 A18B65FFFF60 A18B64FFFF61 A1936AFFFF7A A19369FFFF78 A19368FFFF79 A19367FFFF73 A19366FFFF72 A19365FFFF70 A19364FFFF71 A19B6AFFFF72 A19B69FFFF70 A19B68FFFF71 A19B67FFFF7D A19B66FFFF7C A19B65FFFF7F A19B64FFFF7E A1A47EFFFF5B A18C7EFFFF73 A1947EFFFF6B A19C7EFFFF63 A202FFFFFF7E A208FFFFFF75 A212FFFFFF6E A213FFFFFF6F Commented Sep 3, 2023 at 23:15
• A201FFFFFF7C A209FFFFFF74 A20DFFFFFF70 A4A0697F2A77 Commented Sep 3, 2023 at 23:16

I found this IR protocol documented in IRremoteESP8266 in the source code files ir_Midea.h and ir_Midea.cpp. The parts of the code I focused on were the struct definition and the calcChecksum function.

In the struct definition, the bytes are ordered with the checksum first, so the bytes in the struct are in the reverse order compared to the bytes in your list. However within each byte, the bits appear to be ordered in the same way as your list. (The struct uses C bit fields. The colon numbers indicate how many bits each value uses. It appears this code expects the compiler to build the bit fields starting from the least significant bit of each byte. And it appears the `:0` happens to skip over the remaining bits of the byte it appears in.)

The checksum method used in the code is the following:

• Reverse the bit order of each byte.
• Flip the bits of each byte.
• Sum all the bytes including the checksum byte.
• The sum should be 0, modulo 256 decimal.

When I use this checksum method with your data, every row of your data gives the same sum of decimal 250 (or hex FA or binary 11111010) instead of 0.

Instead, if I remove the step that flips all the bits, then the resulting method works with your data:

• Reverse the bit order of each byte.
• Sum all the bytes including the checksum byte.
• The sum should be 0, modulo 256 decimal.
• Awesome, I've confirmed this, thanks for your help. I had looked through many of the brands on IRremoteESP8266, but obviously missed the Midea! Thanks again! Commented Sep 11, 2023 at 21:41