diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index 55482d55c93c..9981f1902d75 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "Подсветка" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index 9f939534a169..6ee0bea8d5e1 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index 7d2e7285d9e4..c2fdd0640024 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 97eefcd7bb3b..5db01909b39e 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index 9eb8c9d4a8be..4af5f998e08f 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/es-AR.h b/sonoff/language/es-AR.h index aff7b2665a29..69737de8c80c 100644 --- a/sonoff/language/es-AR.h +++ b/sonoff/language/es-AR.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index f37d3cfae36f..a862c54a0744 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "RétroÉcl" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index 4ebeffbf6075..879204ace0d4 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "Háttérvil" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 16c11645be14..54868fd2dc27 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index 262daee7b4c5..f9a16a720c70 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index 683d43cb31d9..d3e753946270 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index 02bdec2e49c1..6db472624cca 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "Luz de fundo" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index 4cf9e0da3892..398e32a58a37 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "Luz negra" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index 3336484e9d64..5ea49a669d8a 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index 1c3ee0bb72bf..c97929c3290d 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index e8505010f818..9f79ddb8932e 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -456,7 +456,8 @@ #define D_SENSOR_SPI_DC "SPI DC" #define D_SENSOR_BACKLIGHT "BkLight" #define D_SENSOR_PMS5003 "PMS5003" -#define D_SENSOR_SDS0X1 "SDS0X1" +#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" +#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_SBR_RX "SerBr Rx" #define D_SENSOR_SBR_TX "SerBr Tx" #define D_SENSOR_SR04_TRIG "SR04 Tri" diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index f97c3220398f..315ce43165c2 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -88,7 +88,8 @@ enum UserSelectablePins { GPIO_SPI_DC, // SPI Data Direction GPIO_BACKLIGHT, // Display backlight control GPIO_PMS5003, // Plantower PMS5003 Serial interface - GPIO_SDS0X1, // Nova Fitness SDS011 Serial interface + GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface + GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface GPIO_SBR_TX, // Serial Bridge Serial interface GPIO_SBR_RX, // Serial Bridge Serial interface GPIO_SR04_TRIG, // SR04 Trigger pin @@ -138,7 +139,8 @@ const char kSensorNames[] PROGMEM = D_SENSOR_PZEM_TX "|" D_SENSOR_PZEM_RX "|" D_SENSOR_SAIR_TX "|" D_SENSOR_SAIR_RX "|" D_SENSOR_SPI_CS "|" D_SENSOR_SPI_DC "|" D_SENSOR_BACKLIGHT "|" - D_SENSOR_PMS5003 "|" D_SENSOR_SDS0X1 "|" + D_SENSOR_PMS5003 "|" + D_SENSOR_SDS0X1_TX "|" D_SENSOR_SDS0X1_RX "|" D_SENSOR_SBR_TX "|" D_SENSOR_SBR_RX "|" D_SENSOR_SR04_TRIG "|" D_SENSOR_SR04_ECHO "|" D_SENSOR_SDM120_TX "|" D_SENSOR_SDM120_RX "|" @@ -912,4 +914,4 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { */ -#endif // _SONOFF_TEMPLATE_H_ \ No newline at end of file +#endif // _SONOFF_TEMPLATE_H_ diff --git a/sonoff/support.ino b/sonoff/support.ino index 2bc80c5eb75b..6449912e8d7a 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -527,7 +527,8 @@ boolean GetUsedInModule(byte val, uint8_t *arr) if (GPIO_PMS5003 == val) { return true; } #endif #ifndef USE_NOVA_SDS - if (GPIO_SDS0X1 == val) { return true; } + if (GPIO_SDS0X1_TX == val) { return true; } + if (GPIO_SDS0X1_RX == val) { return true; } #endif #ifndef USE_SERIAL_BRIDGE if (GPIO_SBR_TX == val) { return true; } diff --git a/sonoff/xsns_20_novasds.ino b/sonoff/xsns_20_novasds.ino index dc5f0ab661a4..851326f3fd35 100644 --- a/sonoff/xsns_20_novasds.ino +++ b/sonoff/xsns_20_novasds.ino @@ -31,13 +31,18 @@ TasmotaSerial *NovaSdsSerial; uint8_t novasds_type = 1; uint8_t novasds_valid = 0; +uint8_t novasds_running = 1; +uint8_t novasds_read_tick = 30; +uint8_t novasds_wakup_tick = 179; +uint8_t novasds_ticker = 0; struct sds011data { uint16_t pm100; uint16_t pm25; } novasds_data; -bool NovaSdsReadData() + +bool NovaSdsReadData(bool publish) { if (! NovaSdsSerial->available()) return false; @@ -51,7 +56,9 @@ bool NovaSdsReadData() NovaSdsSerial->flush(); AddLogSerial(LOG_LEVEL_DEBUG_MORE, d, 8); - + if (!publish){ + return false; + } 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]); @@ -59,9 +66,6 @@ bool NovaSdsReadData() AddLog_P(LOG_LEVEL_DEBUG, PSTR("SDS: " D_CHECKSUM_FAILURE)); return false; } - - novasds_valid = 10; - return true; } @@ -69,12 +73,35 @@ bool NovaSdsReadData() void NovaSdsSecond() // Every second { - if (NovaSdsReadData()) { - novasds_valid = 10; - } else { - if (novasds_valid) { - novasds_valid--; + if (novasds_ticker < novasds_read_tick) { + // wake up the sensor and wait read ticks to stabalize the sensor + if (!novasds_running) { + NovaSdsStart(); + novasds_running = 1; } + + // drain the serial without publishing data + NovaSdsReadData(false); + novasds_ticker++; + + } else if (novasds_ticker == novasds_read_tick) { + + // try to take a single stable reading and sleep the sensor + if (NovaSdsReadData(true)) { + novasds_valid = 1; + NovaSdsStop(); + novasds_running = 0; + novasds_ticker++; + } else { + novasds_valid = 0; + } + + } else if (novasds_ticker >= novasds_wakup_tick) { + // reset the counter + novasds_ticker = 0; + } else { + // sensor is sleeping keep waiting + novasds_ticker++; } } @@ -83,12 +110,36 @@ void NovaSdsSecond() // Every second void NovaSdsInit() { novasds_type = 0; - if (pin[GPIO_SDS0X1] < 99) { - NovaSdsSerial = new TasmotaSerial(pin[GPIO_SDS0X1], -1, 1); + if (pin[GPIO_SDS0X1_RX] < 99 && pin[GPIO_SDS0X1_TX] < 99) { + NovaSdsSerial = new TasmotaSerial(pin[GPIO_SDS0X1_RX], pin[GPIO_SDS0X1_TX], 1); + if (NovaSdsSerial->begin(9600)) { - if (NovaSdsSerial->hardwareSerial()) { ClaimSerial(); } + if (NovaSdsSerial->hardwareSerial()) { + ClaimSerial(); + } novasds_type = 1; } + + } +} + +void NovaSdsStart() +{ + AddLog_P(LOG_LEVEL_DEBUG, "SDS: start"); + const uint8_t novasds_start_cmd[] = {0xAA, 0xB4, 0x06, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x06, 0xAB}; + NovaSdsSerial->write(novasds_start_cmd, sizeof(novasds_start_cmd)); + NovaSdsSerial->flush(); +} + +void NovaSdsStop() +{ + AddLog_P(LOG_LEVEL_DEBUG, "SDS: stop"); + const uint8_t novasds_stop_cmd[] = {0xAA, 0xB4, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x05, 0xAB}; + NovaSdsSerial->write(novasds_stop_cmd, sizeof(novasds_stop_cmd)); + NovaSdsSerial->flush(); + // drain any old data + while (NovaSdsSerial->available()) { + NovaSdsSerial->read(); } } @@ -154,4 +205,4 @@ boolean Xsns20(byte function) return result; } -#endif // USE_NOVA_SDS \ No newline at end of file +#endif // USE_NOVA_SDS