mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-16 23:36:34 +00:00
Correct handling of passive response of Winsen ZH03X Particle sensor in xsns_18_pms5003.ino (#23651)
* Update xsns_18_pms5003.ino * Update xsns_18_pms5003.ino
This commit is contained in:
parent
d3e2bb6906
commit
3b207db27c
@ -205,28 +205,26 @@ bool ZH03ReadDataPassive() // process the passive mode response of the ZH03x sen
|
|||||||
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, 9);
|
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, 9);
|
||||||
|
|
||||||
uint8_t sum = 0;
|
uint8_t sum = 0;
|
||||||
for (uint32_t i = 1; i < 7; i++) {
|
for (uint32_t i = 1; i < 8; i++) {
|
||||||
sum += buffer[i];
|
sum += buffer[i];
|
||||||
}
|
}
|
||||||
sum=(~sum)+1;
|
sum=~(sum)+1;
|
||||||
if (sum != buffer[8]) {
|
if (sum != buffer[8]) {
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("ZH03x: " D_CHECKSUM_FAILURE));
|
AddLog(LOG_LEVEL_DEBUG, PSTR("ZH03x: " D_CHECKSUM_FAILURE));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t buffer_u16[12];
|
pms_data.pm10_standard = buffer[6]*256+buffer[7];
|
||||||
for (uint32_t i = 1; i < 4; i++) {
|
pms_data.pm10_env = pms_data.pm10_standard; // Direct and Environment values identical
|
||||||
buffer_u16[i] = buffer[i*2 + 1];
|
pms_data.pm25_standard = buffer[2]*256+buffer[3];
|
||||||
buffer_u16[i] += (buffer[i*2] << 8);
|
pms_data.pm25_env = pms_data.pm25_standard; // Direct and Environment values identical
|
||||||
buffer_u16[i+3] = buffer[i*2 + 1]; // Direct and Environment values identical
|
pms_data.pm100_standard = buffer[4]*256+buffer[5];
|
||||||
buffer_u16[i+3] += (buffer[i*2] << 8); // Direct and Environment values identical
|
pms_data.pm100_env = pms_data.pm100_standard; // Direct and Environment values identical
|
||||||
buffer_u16[0] = 20; // set dummy framelength
|
pms_data.framelen = 20; // set dummy framelength
|
||||||
buffer_u16[11] = buffer[8]; // copy checksum
|
pms_data.checksum = buffer[8]; // copy checksum
|
||||||
}
|
|
||||||
|
|
||||||
memcpy((void *)&pms_data, (void *)buffer_u16, 22);
|
|
||||||
|
|
||||||
Pms.valid = 10;
|
Pms.valid = Settings->pms_wake_interval*2;
|
||||||
|
|
||||||
if (!Pms.discovery_triggered) {
|
if (!Pms.discovery_triggered) {
|
||||||
TasmotaGlobal.discovery_counter = 1; // Force discovery
|
TasmotaGlobal.discovery_counter = 1; // Force discovery
|
||||||
|
Loading…
x
Reference in New Issue
Block a user