mirror of https://github.com/arendst/Tasmota.git
Merge pull request #4371 from curzon01/development
Fix NovaSDS sensor checksum failure
This commit is contained in:
commit
61b8586384
|
@ -32,6 +32,9 @@
|
||||||
#ifndef WORKING_PERIOD
|
#ifndef WORKING_PERIOD
|
||||||
#define WORKING_PERIOD 5
|
#define WORKING_PERIOD 5
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef XSNS_20_QUERY_INTERVAL
|
||||||
|
#define XSNS_20_QUERY_INTERVAL 3 // query every 3 seconds
|
||||||
|
#endif
|
||||||
|
|
||||||
TasmotaSerial *NovaSdsSerial;
|
TasmotaSerial *NovaSdsSerial;
|
||||||
|
|
||||||
|
@ -58,15 +61,15 @@ void NovaSdsSetWorkPeriod(void)
|
||||||
novasds_workperiod[4] = WORKING_PERIOD;
|
novasds_workperiod[4] = WORKING_PERIOD;
|
||||||
novasds_workperiod[17] = ((novasds_workperiod[2] + novasds_workperiod[3] + novasds_workperiod[4] + novasds_workperiod[15] + novasds_workperiod[16]) & 0xFF); //checksum
|
novasds_workperiod[17] = ((novasds_workperiod[2] + novasds_workperiod[3] + novasds_workperiod[4] + novasds_workperiod[15] + novasds_workperiod[16]) & 0xFF); //checksum
|
||||||
|
|
||||||
NovaSdsSerial->write(novasds_workperiod, sizeof(novasds_workperiod));
|
|
||||||
NovaSdsSerial->flush();
|
NovaSdsSerial->flush();
|
||||||
|
NovaSdsSerial->write(novasds_workperiod, sizeof(novasds_workperiod));
|
||||||
|
|
||||||
while (NovaSdsSerial->available() > 0) {
|
while (NovaSdsSerial->available() > 0) {
|
||||||
NovaSdsSerial->read();
|
NovaSdsSerial->read();
|
||||||
}
|
}
|
||||||
|
|
||||||
NovaSdsSerial->write(novasds_setquerymode, sizeof(novasds_setquerymode));
|
|
||||||
NovaSdsSerial->flush();
|
NovaSdsSerial->flush();
|
||||||
|
NovaSdsSerial->write(novasds_setquerymode, sizeof(novasds_setquerymode));
|
||||||
|
|
||||||
while (NovaSdsSerial->available() > 0) {
|
while (NovaSdsSerial->available() > 0) {
|
||||||
NovaSdsSerial->read();
|
NovaSdsSerial->read();
|
||||||
|
@ -77,23 +80,16 @@ bool NovaSdsReadData(void)
|
||||||
{
|
{
|
||||||
if (! NovaSdsSerial->available()) return false;
|
if (! NovaSdsSerial->available()) return false;
|
||||||
|
|
||||||
|
byte d[10] = { 0 };
|
||||||
|
NovaSdsSerial->flush();
|
||||||
NovaSdsSerial->write(novasds_querydata, sizeof(novasds_querydata));
|
NovaSdsSerial->write(novasds_querydata, sizeof(novasds_querydata));
|
||||||
NovaSdsSerial->flush();
|
NovaSdsSerial->readBytes(d, 10);
|
||||||
|
|
||||||
while ((NovaSdsSerial->peek() != 0xAA) && NovaSdsSerial->available()) {
|
AddLogSerial(LOG_LEVEL_DEBUG_MORE, d, 10);
|
||||||
NovaSdsSerial->read();
|
|
||||||
}
|
|
||||||
|
|
||||||
byte d[8] = { 0 };
|
if (d[0] == 0xAA && d[9] == 0xAB && (d[8] == ((d[2] + d[3] + d[4] + d[5] + d[6] + d[7]) & 0xFF))) {
|
||||||
NovaSdsSerial->read(); // skip 0xAA
|
novasds_data.pm25 = (d[2] + 256 * d[3]);
|
||||||
NovaSdsSerial->readBytes(d, 8);
|
novasds_data.pm100 = (d[4] + 256 * d[5]);
|
||||||
NovaSdsSerial->flush();
|
|
||||||
|
|
||||||
AddLogSerial(LOG_LEVEL_DEBUG_MORE, d, 8);
|
|
||||||
|
|
||||||
if (d[7] == ((d[1] + d[2] + d[3] + d[4] + d[5] + d[6]) & 0xFF)) {
|
|
||||||
novasds_data.pm25 = (d[1] + 256 * d[2]);
|
|
||||||
novasds_data.pm100 = (d[3] + 256 * d[4]);
|
|
||||||
} else {
|
} else {
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("SDS: " D_CHECKSUM_FAILURE));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR("SDS: " D_CHECKSUM_FAILURE));
|
||||||
return false;
|
return false;
|
||||||
|
@ -110,7 +106,7 @@ void NovaSdsSecond(void) // Every second
|
||||||
if (!novasds_valid) {
|
if (!novasds_valid) {
|
||||||
NovaSdsSetWorkPeriod();
|
NovaSdsSetWorkPeriod();
|
||||||
}
|
}
|
||||||
} else {
|
} else if (0 == (uptime % XSNS_20_QUERY_INTERVAL)) { // Every 5 seconds
|
||||||
if (NovaSdsReadData()) {
|
if (NovaSdsReadData()) {
|
||||||
novasds_valid = 10;
|
novasds_valid = 10;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue