RobTillaart / MTP40F

Arduino library for MTP40F CO2 sensor.
MIT License
4 stars 1 forks source link

Add CRC check to request. #4

Closed DaveDavenport closed 8 months ago

DaveDavenport commented 8 months ago

my editor auto-indented everything, sorry.

But this was the small addition to get crc check.

  if (responseLength > 2) {
    uint16_t expected_crc =
        _buffer[responseLength - 2] << 8 | _buffer[responseLength - 1];
    uint16_t calc_crc = CRC(_buffer, responseLength - 2);
    return calc_crc == expected_crc;
  }

quickly checked on esp32c3

RobTillaart commented 8 months ago

Thanks for this PR, Will look into it asap,

RobTillaart commented 8 months ago

my editor auto-indented everything, sorry. Things happen, good you added the real diff separately.

The CRC is still in the todo so I will merge this PR and create a new release today.