Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15404

FastCRC with Home Assistant

$
0
0

Hi

I've been building my home automation and being an electronics designer I wanted to make my own zigbee2mqtt devices. For this I'm using ptvo.info firmware which offers two way UART.

The problem is, that the data isn't transmitted correctly from the zigbee module to HA. The error in transmission is a lost byte which is not position dependent, it can be lost in any location of the string. Also, it's not possible to send a quote mark with the \" syntax, as the escape character is always added to the string. Due to this native json parsing is not possible. Or then my skills are not sufficient for this.

I thought to circumvent this by parsing the string with python and adding a CRC checksum to the string. I get the string ok, but the CRC is different than compared with online calculators.

The code is:

    zigbeeOutputString = "123456789";

    // Calculate CRC
    uint8_t crcArray[zigbeeOutputString.length() + 1];
    zigbeeOutputString.getBytes(crcArray, zigbeeOutputString.length() + 1);
    uint16_t crcValue = CRC16.modbus(crcArray, sizeof(crcArray));

  zigbeeOutputString += " ";

    zigbeeOutputString += itoa(crcValue, str, 10);
    zigbee_serial.print(zigbeeOutputString);
    zigbee_serial.print(" ");
    zigbee_serial.print(crcValue, HEX);
    zigbee_serial.write(0x0d);
    zigbee_serial.flush();
    zigbeeOutputString = "";

And the data received (when without errors) in Home Assistant:
"action": "123456789 23031 59F7"

crccalc.com gives 0x4B37 as the CRC when CRC16-MODBUS is selected. I also tried with CCITT and kermit variations of which other online crc calculation sites give same result as the crccalc.com, from which I assume they calculate it correctly. I've tried all FastCRC algorithm variations and none send the right checksum, so I'm making the assumption that my code has bugs in it. I just can't figure out what.

All ides and suggestions are most welcome!

Kind regards, Esa

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 15404

Trending Articles