mirror of
https://github.com/arendst/Tasmota.git
synced 2026-10-26 22:11:22 +00:00
Fix SR04 serial checksum for AJ-SR04M (#25147)
The AJ-SR04M sends FF H L SUM with SUM = H + L (header excluded). Accept that form as well as FF + H + L when the header byte is 0xFF. Claude-Session: https://claude.ai/code/session_01Ma8u1on2wkeXraAzZBn2iM Co-authored-by: Pacif13r <22977757+Pacif13r@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 file changed
+3
-1
@@ -88,7 +88,9 @@ uint16_t Sr04TMode2Distance(uint32_t i) {
|
||||
uint8_t crc = buffer[0];
|
||||
crc += buffer[1];
|
||||
crc += buffer[2];
|
||||
if (crc == buffer[3]) { // Check crc sum
|
||||
uint8_t crc_aj = buffer[1] + buffer[2]; // AJ-SR04M excludes the 0xFF header from its sum
|
||||
if ((crc == buffer[3]) || // Check crc sum
|
||||
((0xFF == buffer[0]) && (crc_aj == buffer[3]))) {
|
||||
distance = (buffer[1] << 8) + buffer[2];
|
||||
} else {
|
||||
AddLog(LOG_LEVEL_ERROR, PSTR("SR4-%d: CRC error"), i+1);
|
||||
|
||||
Reference in new issue
Block a user