Skip to content

Instantly share code, notes, and snippets.

@FLamparski
Created June 5, 2019 11:20
Show Gist options
  • Save FLamparski/c11a2817351ede4b6c3f2f81d0cd99ca to your computer and use it in GitHub Desktop.
Save FLamparski/c11a2817351ede4b6c3f2f81d0cd99ca to your computer and use it in GitHub Desktop.
/**
* Computes the checksum of a SDS011 message.
*
* This checksum is the low 8 bits of the sum of the data bytes.
* The sensor will not react to commands with invalid checksum.
*/
byte sds011_checksum(byte* msg, size_t msg_size) {
int sum = 0;
for (int i = 2; i < msg_size - 2; i++) {
sum += msg[i];
}
return (byte) 0xff & sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment