MarkJB / python-pms7003

Python script to test a Plantower PMS7003 serial laser particulate sensor
MIT License
8 stars 10 forks source link

Regarding wrong calculation. #3

Closed ronakdedhia18 closed 1 year ago

ronakdedhia18 commented 5 years ago

Hi Mark, In the meantime, it looks like your checksum calculation is wrong:

        # Calculate the payload checksum (not including the payload checksum bytes)
        inputChecksum = 0x42 + 0x4d
        for x in range(0, 27):
            inputChecksum = inputChecksum + data[x]

Here, range(0, 27) will only give you the first 27 indexes ([0, 1, ..., 26]). You need the first 28 indexes, as the last 2 are the checksum. Instead you can write the checksum calculation as:

        # Calculate the payload checksum (not including the payload checksum bytes)
        inputChecksum = 0x42 + 0x4d + sum(data[:-2])

Please let me know if i am wrong. Thank you.

Mindavi commented 3 years ago

It seems like this method works. Thanks for the input! I've fixed it locally :).

MarkJB commented 1 year ago

Added the suggested fix in fbbe36a