fmartinou / teleinfo2mqtt

Publish teleinfo to mqtt topics
https://fmartinou.github.io/teleinfo2mqtt
MIT License
64 stars 17 forks source link

Checksum calculation & verification #84

Open tdenolle opened 4 months ago

tdenolle commented 4 months ago

@fmartinou Build/Tests OK mais il y a l'erreur suivante dans TravisCI
"$ docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself."

ggrandou commented 3 months ago

ce patch ne peut pas marcher tel quel:

une implementation rapide qui fonctionne en mode standard (testée chez moi avec un circuit mal adapté au mode standard, generant plein d'erreurs de reception):

const checksum = dataStr.charCodeAt(dataStr.length - 2);
const checksumData = dataStr.substring(0, dataStr.length - 2);
const calculatedChecksum = this.calculateChecksum(checksumData);
if (calculatedChecksum !== checksum) {
    return;
}

calculateChecksum(strData) {
    let checksum = 0;
    for (let i = 0; i < strData.length; i += 1) {
        checksum += strData.charCodeAt(i);
    }
    checksum = (checksum & 63) + 32;
    return checksum;
}