From 9c04666a17e11dd4bf8c80f289163e97d785e913 Mon Sep 17 00:00:00 2001 From: Johann Weging Date: Sun, 27 May 2018 14:16:51 +0200 Subject: [PATCH 01/15] Add SDS0X1 RX and TX gpio pins to sonoff_template.h --- sonoff/sonoff_template.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index f97c32203..315ce4316 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_ From 91b07f2943c46b1cfee5d3003418d4c74a984053 Mon Sep 17 00:00:00 2001 From: Johann Weging Date: Sun, 27 May 2018 14:19:53 +0200 Subject: [PATCH 02/15] Add SDS0X1 gpio pins to support.ino --- sonoff/support.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sonoff/support.ino b/sonoff/support.ino index 2bc80c5eb..6449912e8 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; } From c41a092c7d45b0be5514e577a111a1a332b1a75a Mon Sep 17 00:00:00 2001 From: Johann Weging Date: Sun, 27 May 2018 14:23:25 +0200 Subject: [PATCH 03/15] SDS0X1 RX TX pin handling in NovaSdsInit --- sonoff/xsns_20_novasds.ino | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sonoff/xsns_20_novasds.ino b/sonoff/xsns_20_novasds.ino index dc5f0ab66..610e07427 100644 --- a/sonoff/xsns_20_novasds.ino +++ b/sonoff/xsns_20_novasds.ino @@ -83,12 +83,14 @@ 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; } + } } @@ -154,4 +156,4 @@ boolean Xsns20(byte function) return result; } -#endif // USE_NOVA_SDS \ No newline at end of file +#endif // USE_NOVA_SDS From 7cefc9b76efa762772fbac412df992174cb42b07 Mon Sep 17 00:00:00 2001 From: Johann Weging Date: Sun, 27 May 2018 14:24:53 +0200 Subject: [PATCH 04/15] SDS0X1 add start and stop functions to idle the sensor --- sonoff/xsns_20_novasds.ino | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sonoff/xsns_20_novasds.ino b/sonoff/xsns_20_novasds.ino index 610e07427..c54297911 100644 --- a/sonoff/xsns_20_novasds.ino +++ b/sonoff/xsns_20_novasds.ino @@ -94,6 +94,26 @@ void NovaSdsInit() } } +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(); + } +} + #ifdef USE_WEBSERVER const char HTTP_SDS0X1_SNS[] PROGMEM = "%s" "{s}SDS0X1 " D_ENVIRONMENTAL_CONCENTRATION " 2.5 " D_UNIT_MICROMETER "{m}%s " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}" From 4a588581d145837dfd006e06ca932ca3dadd0e23 Mon Sep 17 00:00:00 2001 From: Johann Weging Date: Sun, 27 May 2018 14:28:31 +0200 Subject: [PATCH 05/15] Allow NovaSdsReadData to read without publishing data --- sonoff/xsns_20_novasds.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sonoff/xsns_20_novasds.ino b/sonoff/xsns_20_novasds.ino index c54297911..03b4965f8 100644 --- a/sonoff/xsns_20_novasds.ino +++ b/sonoff/xsns_20_novasds.ino @@ -37,7 +37,8 @@ struct sds011data { uint16_t pm25; } novasds_data; -bool NovaSdsReadData() + +bool NovaSdsReadData(bool publish) { if (! NovaSdsSerial->available()) return false; @@ -51,7 +52,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 +62,6 @@ bool NovaSdsReadData() AddLog_P(LOG_LEVEL_DEBUG, PSTR("SDS: " D_CHECKSUM_FAILURE)); return false; } - - novasds_valid = 10; - return true; } From 87e3dcddb9fde27ed5f057dbe8308a77829c0cd8 Mon Sep 17 00:00:00 2001 From: Johann Weging Date: Sun, 27 May 2018 14:29:53 +0200 Subject: [PATCH 06/15] SDS0X1 take one stable reading every 3 minutes --- sonoff/xsns_20_novasds.ino | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/sonoff/xsns_20_novasds.ino b/sonoff/xsns_20_novasds.ino index 03b4965f8..a9dd180b6 100644 --- a/sonoff/xsns_20_novasds.ino +++ b/sonoff/xsns_20_novasds.ino @@ -31,6 +31,10 @@ 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; @@ -69,12 +73,35 @@ bool NovaSdsReadData(bool publish) 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++; } } From f11386cfe7da93bedac801747fb093d8498177a8 Mon Sep 17 00:00:00 2001 From: Johann Weging Date: Sun, 27 May 2018 14:30:40 +0200 Subject: [PATCH 07/15] Update language files for SDS0X1 RX and TX --- sonoff/language/bg-BG.h | 3 ++- sonoff/language/cs-CZ.h | 3 ++- sonoff/language/de-DE.h | 3 ++- sonoff/language/el-GR.h | 3 ++- sonoff/language/en-GB.h | 3 ++- sonoff/language/es-AR.h | 3 ++- sonoff/language/fr-FR.h | 3 ++- sonoff/language/hu-HU.h | 3 ++- sonoff/language/it-IT.h | 3 ++- sonoff/language/nl-NL.h | 3 ++- sonoff/language/pl-PL.h | 3 ++- sonoff/language/pt-BR.h | 3 ++- sonoff/language/pt-PT.h | 3 ++- sonoff/language/ru-RU.h | 3 ++- sonoff/language/zh-CN.h | 3 ++- sonoff/language/zh-TW.h | 3 ++- 16 files changed, 32 insertions(+), 16 deletions(-) diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index 55482d55c..9981f1902 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 9f939534a..6ee0bea8d 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 7d2e7285d..c2fdd0640 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 97eefcd7b..5db01909b 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 9eb8c9d4a..4af5f998e 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 aff7b2665..69737de8c 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 f37d3cfae..a862c54a0 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 4ebeffbf6..879204ace 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 16c11645b..54868fd2d 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 262daee7b..f9a16a720 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 683d43cb3..d3e753946 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 02bdec2e4..6db472624 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 4cf9e0da3..398e32a58 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 3336484e9..5ea49a669 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 1c3ee0bb7..c97929c32 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 e8505010f..9f79ddb89 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" From ff132238077ffd04ac432dcfb0f65c6c49b32eb6 Mon Sep 17 00:00:00 2001 From: Johann Weging Date: Sun, 27 May 2018 14:34:47 +0200 Subject: [PATCH 08/15] SDS0X1 minor code cleanup --- sonoff/xsns_20_novasds.ino | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sonoff/xsns_20_novasds.ino b/sonoff/xsns_20_novasds.ino index a9dd180b6..851326f3f 100644 --- a/sonoff/xsns_20_novasds.ino +++ b/sonoff/xsns_20_novasds.ino @@ -114,7 +114,9 @@ void NovaSdsInit() 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; } @@ -137,8 +139,8 @@ void NovaSdsStop() NovaSdsSerial->flush(); // drain any old data while (NovaSdsSerial->available()) { - NovaSdsSerial->read(); - } + NovaSdsSerial->read(); + } } #ifdef USE_WEBSERVER From b5d7f75647ab656bca132ae8986ad520c30eaf8e Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 8 Sep 2018 08:49:08 +0200 Subject: [PATCH 09/15] Fix setting and getting color temperature for Philips Hue emulation - Improve setting and getting color temperature for Philips Hue emulation - Clamp Philips Hue API values - Turn off white LEDs when setting hue+saturation --- sonoff/xdrv_04_light.ino | 26 ++++++++++++++++---------- sonoff/xplg_wemohue.ino | 33 +++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 209fe467a..93c2c522c 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -557,8 +557,8 @@ void LightState(uint8_t append) if (light_subtype > LST_SINGLE) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_CMND_COLOR "\":\"%s\""), mqtt_data, LightGetColor(0, scolor)); // Add status for HSB - LightGetHsb(&hsb[0],&hsb[1],&hsb[2]); - // Scale these percentages up to the numbers expected byt he client + LightGetHsb(&hsb[0],&hsb[1],&hsb[2], false); + // Scale these percentages up to the numbers expected by the client h = round(hsb[0] * 360); s = round(hsb[1] * 100); b = round(hsb[2] * 100); @@ -911,13 +911,15 @@ void LightHsbToRgb() light_current_color[0] = (uint8_t)(r * 255.0f); light_current_color[1] = (uint8_t)(g * 255.0f); light_current_color[2] = (uint8_t)(b * 255.0f); + light_current_color[3] = 0; + light_current_color[4] = 0; } /********************************************************************************************/ -void LightGetHsb(float *hue, float *sat, float *bri) +void LightGetHsb(float *hue, float *sat, float *bri, bool gotct) { - if (light_subtype > LST_COLDWARM) { + if (light_subtype > LST_COLDWARM && !gotct) { LightRgbToHsb(); *hue = light_hue; *sat = light_saturation; @@ -925,16 +927,19 @@ void LightGetHsb(float *hue, float *sat, float *bri) } else { *hue = 0; *sat = 0; -// *bri = (2.54f * (float)Settings.light_dimmer); *bri = (0.01f * (float)Settings.light_dimmer); } } -void LightSetHsb(float hue, float sat, float bri, uint16_t ct) +void LightSetHsb(float hue, float sat, float bri, uint16_t ct, bool gotct) { if (light_subtype > LST_COLDWARM) { - if ((LST_RGBWC == light_subtype) && (ct > 0)) { - LightSetColorTemp(ct); + if ((LST_RGBWC == light_subtype) && (gotct)) { + uint8_t tmp = (uint8_t)(bri * 100); + Settings.light_dimmer = tmp; + if (ct > 0) { + LightSetColorTemp(ct); + } } else { light_hue = hue; light_saturation = sat; @@ -1114,7 +1119,7 @@ boolean LightCommand() } else { // Command with only 1 parameter, Hue (0360) ? (HSB[0] % 360) : HSB[0] ) /360.0, ( (HSB[1]>100) ? (HSB[1] % 100) : HSB[1] ) /100.0, ( (HSB[2]>100) ? (HSB[2] % 100) : HSB[2] ) /100.0, - 0); + 0, + false); } } else { LightState(0); diff --git a/sonoff/xplg_wemohue.ino b/sonoff/xplg_wemohue.ino index 93912bc76..f0b20ef59 100644 --- a/sonoff/xplg_wemohue.ino +++ b/sonoff/xplg_wemohue.ino @@ -17,6 +17,9 @@ along with this program. If not, see . */ +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) + #if defined(USE_WEBSERVER) && defined(USE_EMULATION) /*********************************************************************************************\ * Belkin WeMo and Philips Hue bridge emulation @@ -462,10 +465,10 @@ const char HUE_LIGHTS_STATUS_JSON[] PROGMEM = "\"hue\":{h}," "\"sat\":{s}," "\"xy\":[0.5, 0.5]," - "\"ct\":500," + "\"ct\":{t}," "\"alert\":\"none\"," "\"effect\":\"none\"," - "\"colormode\":\"hs\"," + "\"colormode\":\"{m}\"," "\"reachable\":true}"; const char HUE_LIGHTS_STATUS_JSON2[] PROGMEM = ",\"type\":\"Extended color light\"," @@ -559,20 +562,26 @@ void HueConfig(String *path) WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response); } +bool g_gotct = false; + void HueLightStatus1(byte device, String *response) { float hue = 0; float sat = 0; float bri = 0; + uint16_t ct = 500; if (light_type) { - LightGetHsb(&hue, &sat, &bri); + LightGetHsb(&hue, &sat, &bri, g_gotct); + ct = LightGetColorTemp(); } *response += FPSTR(HUE_LIGHTS_STATUS_JSON); response->replace("{state}", (power & (1 << (device-1))) ? "true" : "false"); response->replace("{h}", String((uint16_t)(65535.0f * hue))); response->replace("{s}", String((uint8_t)(254.0f * sat))); response->replace("{b}", String((uint8_t)(254.0f * bri))); + response->replace("{t}", String(ct)); + response->replace("{m}", g_gotct?"ct":"hs"); } void HueLightStatus2(byte device, String *response) @@ -678,11 +687,13 @@ void HueLights(String *path) } if (light_type) { - LightGetHsb(&hue, &sat, &bri); + LightGetHsb(&hue, &sat, &bri, g_gotct); } - if (hue_json.containsKey("bri")) { + if (hue_json.containsKey("bri")) { // Brightness is a scale from 1 (the minimum the light is capable of) to 254 (the maximum). Note: a brightness of 1 is not off. tmp = hue_json["bri"]; + tmp = max(tmp, 1); + tmp = min(tmp, 254); bri = (float)tmp / 254.0f; if (resp) { response += ","; @@ -694,7 +705,7 @@ void HueLights(String *path) resp = true; change = true; } - if (hue_json.containsKey("hue")) { + if (hue_json.containsKey("hue")) { // The hue value is a wrapping value between 0 and 65535. Both 0 and 65535 are red, 25500 is green and 46920 is blue. tmp = hue_json["hue"]; hue = (float)tmp / 65535.0f; if (resp) { @@ -704,11 +715,14 @@ void HueLights(String *path) response.replace("{id", String(device)); response.replace("{cm", "hue"); response.replace("{re", String(tmp)); + g_gotct = false; resp = true; change = true; } - if (hue_json.containsKey("sat")) { + if (hue_json.containsKey("sat")) { // Saturation of the light. 254 is the most saturated (colored) and 0 is the least saturated (white). tmp = hue_json["sat"]; + tmp = max(tmp, 0); + tmp = min(tmp, 254); sat = (float)tmp / 254.0f; if (resp) { response += ","; @@ -717,6 +731,8 @@ void HueLights(String *path) response.replace("{id", String(device)); response.replace("{cm", "sat"); response.replace("{re", String(tmp)); + g_gotct = false; + resp = true; change = true; } if (hue_json.containsKey("ct")) { // Color temperature 153 (Cold) to 500 (Warm) @@ -728,11 +744,12 @@ void HueLights(String *path) response.replace("{id", String(device)); response.replace("{cm", "ct"); response.replace("{re", String(ct)); + g_gotct = true; change = true; } if (change) { if (light_type) { - LightSetHsb(hue, sat, bri, ct); + LightSetHsb(hue, sat, bri, ct, g_gotct); } change = false; } From 7cd92248196550964de87ada6bf86a2b742b5b3d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 8 Sep 2018 17:18:31 +0200 Subject: [PATCH 10/15] 6.2.1.3 - Change drop down list 6.2.1.3 20180907 * Change web Configure Module GPIO drop down list order for better readability * Fix showing Period Power in energy threshold messages * Fix ButtonRetain to not use default topic for clearing retain messages (#3737) --- sonoff/_changelog.ino | 8 ++- sonoff/sonoff.ino | 2 +- sonoff/sonoff_template.h | 108 ++++++++++++++++++++++++++++++++++- sonoff/sonoff_version.h | 2 +- sonoff/xdrv_01_mqtt.ino | 6 +- sonoff/xdrv_02_webserver.ino | 8 +-- sonoff/xdrv_03_energy.ino | 3 + sonoff/xdrv_10_rules.ino | 2 +- 8 files changed, 125 insertions(+), 14 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 82d12f28e..c62144f8d 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,8 +1,14 @@ -/* 6.2.1.2 20180906 +/* 6.2.1.3 20180907 + * Change web Configure Module GPIO drop down list order for better readability + * Fix showing Period Power in energy threshold messages + * Fix ButtonRetain to not use default topic for clearing retain messages (#3737) + * + * 6.2.1.2 20180906 * Fix KNX PA exception. Regression from 6.2.1 buffer overflow caused by subStr() (#3700, #3710) * Add command SetOption52 to control display of optional time offset from UTC in JSON messages (#3629, #3711) * Add experimental support for PZEM-003,014,016,017 Energy monitoring (#3694) * Add basic support for MP3 player using DFRobot RB-DFR-562 (#3723) + * Fix setting and getting color temperature for Philips Hue emulation (#3733) * * 6.2.1.1 20180905 * Rewrite energy monitoring using energy sensor driver modules diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 6b2e8422b..a1ab907ab 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -134,7 +134,7 @@ int ota_state_flag = 0; // OTA state flag int ota_result = 0; // OTA result int restart_flag = 0; // Sonoff restart flag int wifi_state_flag = WIFI_RESTART; // Wifi state flag -int tele_period = 0; // Tele period timer +int tele_period = 1; // Tele period timer int blinks = 201; // Number of LED blinks uint32_t uptime = 0; // Counting every second until 4294967295 = 130 year uint32_t global_update = 0; // Timestamp of last global temperature and humidity update diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 2ab43286d..23019ff10 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -21,6 +21,8 @@ #define _SONOFF_TEMPLATE_H_ // User selectable GPIO functionality +// ATTENTION: Only add at the end of this list just before GPIO_SENSOR_END +// Then add the same name(s) in a nice location in array kGpioNiceList enum UserSelectablePins { GPIO_NONE, // Not used GPIO_DHT11, // DHT11 @@ -244,7 +246,111 @@ typedef struct MYTMPLT { myio gp; } mytmplt; -const uint8_t kNiceList[MAXMODULE] PROGMEM = { +const uint8_t kGpioNiceList[GPIO_SENSOR_END] PROGMEM = { + GPIO_NONE, // Not used + GPIO_KEY1, // Buttons + GPIO_KEY1_NP, + GPIO_KEY2, + GPIO_KEY2_NP, + GPIO_KEY3, + GPIO_KEY3_NP, + GPIO_KEY4, + GPIO_KEY4_NP, + GPIO_SWT1, // User connected external switches + GPIO_SWT1_NP, + GPIO_SWT2, + GPIO_SWT2_NP, + GPIO_SWT3, + GPIO_SWT3_NP, + GPIO_SWT4, + GPIO_SWT4_NP, + GPIO_SWT5, + GPIO_SWT5_NP, + GPIO_SWT6, + GPIO_SWT6_NP, + GPIO_SWT7, + GPIO_SWT7_NP, + GPIO_SWT8, + GPIO_SWT8_NP, + GPIO_REL1, // Relays + GPIO_REL1_INV, + GPIO_REL2, + GPIO_REL2_INV, + GPIO_REL3, + GPIO_REL3_INV, + GPIO_REL4, + GPIO_REL4_INV, + GPIO_REL5, + GPIO_REL5_INV, + GPIO_REL6, + GPIO_REL6_INV, + GPIO_REL7, + GPIO_REL7_INV, + GPIO_REL8, + GPIO_REL8_INV, + GPIO_LED1, // Leds + GPIO_LED1_INV, + GPIO_LED2, + GPIO_LED2_INV, + GPIO_LED3, + GPIO_LED3_INV, + GPIO_LED4, + GPIO_LED4_INV, + GPIO_PWM1, // RGB Red or C Cold White + GPIO_PWM1_INV, + GPIO_PWM2, // RGB Green or CW Warm White + GPIO_PWM2_INV, + GPIO_PWM3, // RGB Blue + GPIO_PWM3_INV, + GPIO_PWM4, // RGBW (Cold) White + GPIO_PWM4_INV, + GPIO_PWM5, // RGBCW Warm White + GPIO_PWM5_INV, + GPIO_CNTR1, // Counters + GPIO_CNTR1_NP, + GPIO_CNTR2, + GPIO_CNTR2_NP, + GPIO_CNTR3, + GPIO_CNTR3_NP, + GPIO_CNTR4, + GPIO_CNTR4_NP, + GPIO_I2C_SCL, // I2C SCL + GPIO_I2C_SDA, // I2C SDA + GPIO_SPI_CS, // SPI Chip Select + GPIO_SPI_DC, // SPI Data Direction + GPIO_BACKLIGHT, // Display backlight control + GPIO_DHT11, // DHT11 + GPIO_DHT22, // DHT21, DHT22, AM2301, AM2302, AM2321 + GPIO_SI7021, // iTead SI7021 + GPIO_DSB, // Single wire DS18B20 or DS18S20 + GPIO_WS2812, // WS2812 Led string + GPIO_IRSEND, // IR remote + GPIO_IRRECV, // IR receiver + GPIO_SR04_TRIG, // SR04 Trigger pin + GPIO_SR04_ECHO, // SR04 Echo pin + GPIO_TM16CLK, // TM1638 Clock + GPIO_TM16DIO, // TM1638 Data I/O + GPIO_TM16STB, // TM1638 Strobe + GPIO_SBR_TX, // Serial Bridge Serial interface + GPIO_SBR_RX, // Serial Bridge Serial interface + GPIO_MHZ_TXD, // MH-Z19 Serial interface + GPIO_MHZ_RXD, // MH-Z19 Serial interface + GPIO_SAIR_TX, // SenseAir Serial interface + GPIO_SAIR_RX, // SenseAir Serial interface + GPIO_SDS0X1, // Nova Fitness SDS011 Serial interface + GPIO_PZEM_TX, // PZEM004T Serial interface + GPIO_PZEM_RX, // PZEM004T Serial interface + GPIO_PZEM2_TX, // PZEM-003,014,016,017 Serial interface + GPIO_PZEM2_RX, // PZEM-003,014,016,017 Serial interface + GPIO_SDM120_TX, // SDM120 Serial interface + GPIO_SDM120_RX, // SDM120 Serial interface + GPIO_SDM630_TX, // SDM630 Serial interface + GPIO_SDM630_RX, // SDM630 Serial interface + GPIO_PMS5003, // Plantower PMS5003 Serial interface + GPIO_MP3_DFR562 // RB-DFR-562, DFPlayer Mini MP3 Player Serial interface +}; + +const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { SONOFF_BASIC, SONOFF_RF, SONOFF_TH, diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 178e0af68..f068473ab 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x06020102 +#define VERSION 0x06020103 #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/xdrv_01_mqtt.ino b/sonoff/xdrv_01_mqtt.ino index c47728df0..f3f33d693 100644 --- a/sonoff/xdrv_01_mqtt.ino +++ b/sonoff/xdrv_01_mqtt.ino @@ -380,9 +380,7 @@ void MqttConnected() MqttPublishPowerState(i); if (SONOFF_IFAN02 == Settings.module) { break; } // Only report status of light relay } - if (Settings.tele_period) { - tele_period = Settings.tele_period -9; - } + if (Settings.tele_period) { tele_period = Settings.tele_period -9; } // Enable TelePeriod in 9 seconds rules_flag.system_boot = 1; XdrvCall(FUNC_MQTT_INIT); } @@ -718,7 +716,6 @@ bool MqttCommand() } else if (CMND_BUTTONRETAIN == command_code) { if ((payload >= 0) && (payload <= 1)) { - strlcpy(Settings.button_topic, mqtt_topic, sizeof(Settings.button_topic)); if (!payload) { for(i = 1; i <= MAX_KEYS; i++) { SendKey(0, i, 9); // Clear MQTT retain in broker @@ -730,7 +727,6 @@ bool MqttCommand() } else if (CMND_SWITCHRETAIN == command_code) { if ((payload >= 0) && (payload <= 1)) { - strlcpy(Settings.button_topic, mqtt_topic, sizeof(Settings.button_topic)); if (!payload) { for(i = 1; i <= MAX_SWITCHES; i++) { SendKey(1, i, 9); // Clear MQTT retain in broker diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino index 4059459c5..4398a9eb0 100644 --- a/sonoff/xdrv_02_webserver.ino +++ b/sonoff/xdrv_02_webserver.ino @@ -768,7 +768,7 @@ void HandleModuleConfiguration() page.replace(F("{v}"), FPSTR(S_CONFIGURE_MODULE)); page += FPSTR(HTTP_SCRIPT_MODULE1); for (byte i = 0; i < MAXMODULE; i++) { - midx = pgm_read_byte(kNiceList + i); + midx = pgm_read_byte(kModuleNiceList + i); snprintf_P(stemp, sizeof(stemp), kModules[midx].name); snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SCRIPT_MODULE2, midx, midx +1, stemp); page += mqtt_data; @@ -779,10 +779,10 @@ void HandleModuleConfiguration() mytmplt cmodule; memcpy_P(&cmodule, &kModules[Settings.module], sizeof(cmodule)); - for (byte j = 0; j < GPIO_SENSOR_END; j++) { - if (!GetUsedInModule(j, cmodule.gp.io)) { - snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SCRIPT_MODULE2, j, j, GetTextIndexed(stemp, sizeof(stemp), j, kSensorNames)); + midx = pgm_read_byte(kGpioNiceList + j); + if (!GetUsedInModule(midx, cmodule.gp.io)) { + snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SCRIPT_MODULE2, midx, midx, GetTextIndexed(stemp, sizeof(stemp), midx, kSensorNames)); page += mqtt_data; } } diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 081b52d83..ac26a18da 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -304,7 +304,10 @@ void EnergyMqttShow() { // {"Time":"2017-12-16T11:48:55","ENERGY":{"Total":0.212,"Yesterday":0.000,"Today":0.014,"Period":2.0,"Power":22.0,"Factor":1.00,"Voltage":213.6,"Current":0.100}} snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_JSON_TIME "\":\"%s\""), GetDateAndTime(DT_LOCAL).c_str()); + int tele_period_save = tele_period; + tele_period = 2; EnergyShow(1); + tele_period = tele_period_save; snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain); energy_power_delta = 0; diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index df27cb4cd..930bde7d5 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -426,7 +426,7 @@ void RulesEvery100ms() { if (Settings.rule_enabled) { // Any rule enabled mqtt_data[0] = '\0'; - uint16_t tele_period_save = tele_period; + int tele_period_save = tele_period; tele_period = 2; // Do not allow HA updates during next function call XsnsNextCall(FUNC_JSON_APPEND); // ,"INA219":{"Voltage":4.494,"Current":0.020,"Power":0.089} tele_period = tele_period_save; From b96c0d7773477b758ec2ce0818f3b8901b7312d6 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 8 Sep 2018 18:17:36 +0200 Subject: [PATCH 11/15] Fix Novafitnes GPIO selection Fix Novafitnes GPIO selection --- sonoff/sonoff_template.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index fd2806fa9..1ab62ae63 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -94,8 +94,7 @@ enum UserSelectablePins { GPIO_SPI_DC, // SPI Data Direction GPIO_BACKLIGHT, // Display backlight control GPIO_PMS5003, // Plantower PMS5003 Serial interface - GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface - GPIO_SDS0X1_RX, // 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 @@ -126,6 +125,7 @@ enum UserSelectablePins { GPIO_PZEM2_TX, // PZEM-003,014,016,017 Serial interface GPIO_PZEM2_RX, // PZEM-003,014,016,017 Serial interface GPIO_MP3_DFR562, // RB-DFR-562, DFPlayer Mini MP3 Player + GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface GPIO_SENSOR_END }; // Programmer selectable GPIO functionality offset by user selectable GPIOs @@ -167,8 +167,7 @@ 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_TX "|" D_SENSOR_SDS0X1_RX "|" + D_SENSOR_PMS5003 "|" 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 "|" @@ -178,7 +177,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_BUTTON "1n|" D_SENSOR_BUTTON "2n|" D_SENSOR_BUTTON "3n|" D_SENSOR_BUTTON "4n|" D_SENSOR_COUNTER "1n|" D_SENSOR_COUNTER "2n|" D_SENSOR_COUNTER "3n|" D_SENSOR_COUNTER "4n|" D_SENSOR_PZEM_TX "|" D_SENSOR_PZEM_RX "|" - D_SENSOR_DFR562; + D_SENSOR_DFR562 "|" D_SENSOR_SDS0X1_TX; /********************************************************************************************/ @@ -339,7 +338,8 @@ const uint8_t kGpioNiceList[GPIO_SENSOR_END] PROGMEM = { GPIO_MHZ_RXD, // MH-Z19 Serial interface GPIO_SAIR_TX, // SenseAir Serial interface GPIO_SAIR_RX, // SenseAir 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_PZEM_TX, // PZEM004T Serial interface GPIO_PZEM_RX, // PZEM004T Serial interface GPIO_PZEM2_TX, // PZEM-003,014,016,017 Serial interface From 3b029797b6534bdcd8c78be42b9e0b99cf7eed53 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 8 Sep 2018 18:25:06 +0200 Subject: [PATCH 12/15] Add sleep to Nova Fitness SDS01X Add sleep to Nova Fitness SDS01X sensor (#2841, #3724) --- sonoff/_changelog.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index c62144f8d..230a541b7 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -2,6 +2,7 @@ * Change web Configure Module GPIO drop down list order for better readability * Fix showing Period Power in energy threshold messages * Fix ButtonRetain to not use default topic for clearing retain messages (#3737) + * Add sleep to Nova Fitness SDS01X sensor (#2841, #3724) * * 6.2.1.2 20180906 * Fix KNX PA exception. Regression from 6.2.1 buffer overflow caused by subStr() (#3700, #3710) From 56920ad8263c7b50f5811a29b057807af483417a Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 8 Sep 2018 18:33:56 +0200 Subject: [PATCH 13/15] Adjust list box width Adjust GPIO drop down list box width --- sonoff/xdrv_02_webserver.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino index 4398a9eb0..55eb0f41b 100644 --- a/sonoff/xdrv_02_webserver.ino +++ b/sonoff/xdrv_02_webserver.ino @@ -805,7 +805,7 @@ void HandleModuleConfiguration() for (byte i = 0; i < MAX_GPIO_PIN; i++) { if (GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) { snprintf_P(stemp, 3, PINS_WEMOS +i*2); - snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s " D_GPIO "%d %s"), + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s " D_GPIO "%d %s"), (WEMOS==Settings.module)?stemp:"", i, (0==i)? D_SENSOR_BUTTON "1":(1==i)? D_SERIAL_OUT :(3==i)? D_SERIAL_IN :(9==i)? "ESP8285" :(10==i)? "ESP8285" :(12==i)? D_SENSOR_RELAY "1":(13==i)? D_SENSOR_LED "1i":(14==i)? D_SENSOR :"", i, i); page += mqtt_data; } From 4c41ea446154e780610bc1b96ec0f08803893a6b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 9 Sep 2018 14:31:40 +0200 Subject: [PATCH 14/15] Houskeeping --- sonoff/sonoff.ino | 3 --- sonoff/support.ino | 12 ++++++++++++ sonoff/xdrv_02_webserver.ino | 2 +- tools/decode-status.py | 6 +++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index a1ab907ab..52cdb68ba 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -849,10 +849,8 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) else if ((CMND_GPIO == command_code) && (index < MAX_GPIO_PIN)) { mytmplt cmodule; memcpy_P(&cmodule, &kModules[Settings.module], sizeof(cmodule)); -// if ((GPIO_USER == cmodule.gp.io[index]) && (payload >= 0) && (payload < GPIO_SENSOR_END)) { if ((GPIO_USER == ValidGPIO(index, cmodule.gp.io[index])) && (payload >= 0) && (payload < GPIO_SENSOR_END)) { for (byte i = 0; i < MAX_GPIO_PIN; i++) { -// if ((GPIO_USER == cmodule.gp.io[i]) && (Settings.my_gp.io[i] == payload)) { if ((GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) && (Settings.my_gp.io[i] == payload)) { Settings.my_gp.io[i] = 0; } @@ -862,7 +860,6 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len) } snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{")); for (byte i = 0; i < MAX_GPIO_PIN; i++) { -// if (GPIO_USER == cmodule.gp.io[i]) { if (GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) { if (jsflg) snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data); jsflg = 1; diff --git a/sonoff/support.ino b/sonoff/support.ino index 291f2069d..af93fa148 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -936,8 +936,20 @@ void GetFeatures() #ifdef USE_DISPLAY_SH1106 feature_drv2 |= 0x00001000; // xdsp_06_sh1106.ino #endif +#ifdef USE_MP3_PLAYER + feature_drv2 |= 0x00002000; // xdrv_14_mp3.ino +#endif +#ifdef NO_EXTRA_4K_HEAP + feature_drv2 |= 0x00800000; // sonoff_post.h +#endif +#ifdef VTABLES_IN_IRAM + feature_drv2 |= 0x01000000; // platformio.ini +#endif +#ifdef VTABLES_IN_DRAM + feature_drv2 |= 0x02000000; // platformio.ini +#endif #ifdef VTABLES_IN_FLASH feature_drv2 |= 0x04000000; // platformio.ini #endif diff --git a/sonoff/xdrv_02_webserver.ino b/sonoff/xdrv_02_webserver.ino index 55eb0f41b..6cadb952f 100644 --- a/sonoff/xdrv_02_webserver.ino +++ b/sonoff/xdrv_02_webserver.ino @@ -1193,7 +1193,7 @@ void HandleSaveSettings() if (Settings.last_module != new_module) { Settings.my_gp.io[i] = 0; } else { - if (GPIO_USER == cmodule.gp.io[i]) { + if (GPIO_USER == ValidGPIO(i, cmodule.gp.io[i])) { snprintf_P(stemp, sizeof(stemp), PSTR("g%d"), i); WebGetArg(stemp, tmp, sizeof(tmp)); Settings.my_gp.io[i] = (!strlen(tmp)) ? 0 : atoi(tmp); diff --git a/tools/decode-status.py b/tools/decode-status.py index b26be9df0..154b6e719 100644 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -108,10 +108,10 @@ a_features = [[ "USE_CONFIG_OVERRIDE","BE_MINIMAL","USE_SENSORS","USE_CLASSIC", "USE_KNX_NO_EMULATION","USE_DISPLAY_MODES1TO5","USE_DISPLAY_GRAPH","USE_DISPLAY_LCD", "USE_DISPLAY_SSD1306","USE_DISPLAY_MATRIX","USE_DISPLAY_ILI9341","USE_DISPLAY_EPAPER", - "USE_DISPLAY_SH1106","","","", + "USE_DISPLAY_SH1106","USE_MP3_PLAYER","","", "","","","", - "","","","", - "","","VTABLES_IN_FLASH","PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH", + "","","","NO_EXTRA_4K_HEAP", + "VTABLES_IN_IRAM","VTABLES_IN_DRAM","VTABLES_IN_FLASH","PIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH", "PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY","PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH","DEBUG_THEO","USE_DEBUG_DRIVER" ],[ "","USE_ADC_VCC","USE_ENERGY_SENSOR","USE_PZEM004T", From 550c7d256f3d63f24f9b6613bc0e2f5d311fbf89 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 9 Sep 2018 14:58:50 +0200 Subject: [PATCH 15/15] Add option -mtarget-align Add option -mtarget-align to solve linux compiled un-aligned binaries (#3678) --- platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio.ini b/platformio.ini index 4cda52b6f..d333fd187 100644 --- a/platformio.ini +++ b/platformio.ini @@ -61,6 +61,7 @@ build_unflags = -Wall build_flags = -Wl,-Tesp8266.flash.1m0.ld + -mtarget-align ; -DUSE_CONFIG_OVERRIDE ; lwIP 1.4 (Default) ; -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH