From 8d1322984c8c3be6049d63d3368c4c7c34aca5b2 Mon Sep 17 00:00:00 2001 From: gururise Date: Wed, 8 Apr 2020 10:11:37 -0700 Subject: [PATCH 01/22] Add PMS5003 RX and TX gpio pints to tasmota_template.h --- tasmota/tasmota_template.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index e21260741..5ad118377 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -93,7 +93,8 @@ enum UserSelectablePins { GPIO_SPI_CS, // SPI Chip Select GPIO_SPI_DC, // SPI Data Direction GPIO_BACKLIGHT, // Display backlight control - GPIO_PMS5003, // Plantower PMS5003 Serial interface + GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface + GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface GPIO_SBR_TX, // Serial Bridge Serial interface GPIO_SBR_RX, // Serial Bridge Serial interface @@ -259,7 +260,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_PZEM0XX_TX "|" D_SENSOR_PZEM004_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_RX "|" + D_SENSOR_PMS5003_TX "|" D_SENSOR_PMS5003_RX "|" 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 "|" @@ -580,7 +581,8 @@ const uint8_t kGpioNiceList[] PROGMEM = { GPIO_HPMA_RX, // Honeywell HPMA115S0 Serial interface #endif #ifdef USE_PMS5003 - GPIO_PMS5003, // Plantower PMS5003 Serial interface + GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface + GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface #endif #if defined(USE_TX20_WIND_SENSOR) || defined(USE_TX23_WIND_SENSOR) GPIO_TX2X_TXD_BLACK, // TX20/TX23 Transmission Pin From ffd533815032f4b8e7f960ed6b22c1806a6b0e4d Mon Sep 17 00:00:00 2001 From: gururise Date: Wed, 8 Apr 2020 10:22:32 -0700 Subject: [PATCH 02/22] PMS5003 RX TX pin handling in PmsInit --- tasmota/xsns_18_pms5003.ino | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 0909921dc..2f02ff454 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -140,13 +140,26 @@ void PmsSecond(void) // Every second void PmsInit(void) { pms_type = 0; - if (pin[GPIO_PMS5003] < 99) { - PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003], -1, 1); + if ((pin[GPIO_PMS5003_RX] < 99) && (pin[GPIO_PMS5003_TX] < 99)) + { + PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], pin[GPIO_PMS5003_TX], 1); if (PmsSerial->begin(9600)) { if (PmsSerial->hardwareSerial()) { ClaimSerial(); } pms_type = 1; } } + else if ((pin[GPIO_PMS5003_RX] < 99)) + { + PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], -1, 1); + if (PmsSerial->begin(9600)) + { + if (PmsSerial->hardwareSerial()) + { + ClaimSerial(); + } + pms_type = 1; + } + } } #ifdef USE_WEBSERVER From a1f1065be89a39ceb0f9b2014be1e7fd3efc16b6 Mon Sep 17 00:00:00 2001 From: gururise Date: Wed, 8 Apr 2020 10:25:40 -0700 Subject: [PATCH 03/22] Add PMS5003 commands --- tasmota/xsns_18_pms5003.ino | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 2f02ff454..3e12bb1d0 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -37,6 +37,23 @@ TasmotaSerial *PmsSerial; uint8_t pms_type = 1; uint8_t pms_valid = 0; +enum PmsCommands +{ + CMD_MODE_ACTIVE, + CMD_SLEEP, + CMD_WAKEUP, + CMD_MODE_PASSIVE, + CMD_READ_DATA +}; + +const uint8_t kPmsCommands[][7] PROGMEM = { + // 0 1 2 3 4 5 6 + {0x42, 0x4D, 0xE1, 0x00, 0x01, 0x01, 0x71}, // pms_set_active_mode + {0x42, 0x4D, 0xE4, 0x00, 0x00, 0x01, 0x73}, // pms_sleep + {0x42, 0x4D, 0xE4, 0x00, 0x01, 0x01, 0x74}, // pms_wake + {0x42, 0x4D, 0xE1, 0x00, 0x00, 0x01, 0x70}, // pms_set_passive_mode + {0x42, 0x4D, 0xE2, 0x00, 0x00, 0x01, 0x71}}; // pms_passive_mode_read + struct pmsX003data { uint16_t framelen; uint16_t pm10_standard, pm25_standard, pm100_standard; @@ -52,6 +69,13 @@ struct pmsX003data { /*********************************************************************************************/ +size_t PmsSendCmd(uint8_t command_id) +{ + return MhzSerial->write(kPmsCommands[command_id], sizeof(kPmsCommands[command_id])); +} + +/*********************************************************************************************/ + bool PmsReadData(void) { if (! PmsSerial->available()) { From b7e7fbdc15b734a5dc854151235e38722401d4fc Mon Sep 17 00:00:00 2001 From: gururise Date: Wed, 8 Apr 2020 10:27:49 -0700 Subject: [PATCH 04/22] define WARMUP_PERIOD for sensor warmup --- tasmota/xsns_18_pms5003.ino | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 3e12bb1d0..d8bd5dc17 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -32,6 +32,10 @@ #include +#ifndef WARMUP_PERIOD +#define WARMUP_PERIOD 30 // Turn on PMSX003 XX-seconds before read in passive mode +#endif + TasmotaSerial *PmsSerial; uint8_t pms_type = 1; From 2a08a0e9e6fbb566a5086fec17a997d41b6a7ea6 Mon Sep 17 00:00:00 2001 From: gururise Date: Wed, 8 Apr 2020 10:29:54 -0700 Subject: [PATCH 05/22] PMS5003 allow config for continuous or interval readings --- tasmota/xsns_18_pms5003.ino | 89 ++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index d8bd5dc17..209d43380 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -40,6 +40,12 @@ TasmotaSerial *PmsSerial; uint8_t pms_type = 1; uint8_t pms_valid = 0; +uint16_t pms_time = 0; +uint8_t wake_mode = 1; +uint8_t pms_ready = 1; + +const char ACTIVE_MODE[] = "Active Mode"; +const char PASSIVE_MODE[] = "Passive Mode"; enum PmsCommands { @@ -150,15 +156,82 @@ bool PmsReadData(void) return true; } +/*********************************************************************************************\ + * Command Sensor15 + * + * 0 - Active Mode + * 1 .. 255 - Passive Mode (read sensor every x minutes) +\*********************************************************************************************/ + +bool PmsCommandSensor(void) +{ + if (XdrvMailbox.payload == 0) + { + // Set Active Mode + Settings.novasds_startingoffset = 0; + wake_mode = 1; + pms_ready = 1; + PmsSendCmd(CMD_MODE_ACTIVE); + } + else if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 256)) + { + // Set Passive Mode + Settings.novasds_startingoffset = XdrvMailbox.payload; + PmsSendCmd(CMD_MODE_PASSIVE); + PmsSendCmd(CMD_SLEEP); + wake_mode = 0; + pms_ready = 0; + } + + Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.novasds_startingoffset); + + return true; +} + /*********************************************************************************************/ void PmsSecond(void) // Every second { - if (PmsReadData()) { - pms_valid = 10; - } else { - if (pms_valid) { - pms_valid--; + if (Settings.novasds_startingoffset > 0) + { + // Passive Mode + pms_time++; + if ((((uint16_t)Settings.novasds_startingoffset) * 60 - pms_time <= WARMUP_PERIOD) && !wake_mode) + { + wake_mode = 1; + PmsSendCmd(CMD_WAKEUP); + } + if (pms_time >= ((uint16_t)Settings.novasds_startingoffset) * 60) + { + PmsSendCmd(CMD_READ_DATA); + pms_ready = 1; + pms_time = 0; + } + } + + if (pms_ready) + { + if (PmsReadData()) + { + pms_valid = 10; + if (Settings.novasds_startingoffset > 0) + { + PmsSendCmd(CMD_SLEEP); + wake_mode = 0; + pms_ready = 0; + } + } + else + { + if (pms_valid) + { + pms_valid--; + if (Settings.novasds_startingoffset > 0) + { + PmsSendCmd(CMD_READ_DATA); + pms_ready = 1; + } + } } } } @@ -271,6 +344,12 @@ bool Xsns18(uint8_t function) case FUNC_EVERY_SECOND: PmsSecond(); break; + case FUNC_COMMAND_SENSOR: + if (XSNS_18 == XdrvMailbox.index) + { + result = PmsCommandSensor(); + } + break; case FUNC_JSON_APPEND: PmsShow(1); break; From 51909679d4ba7a097d6d5921b4f73f1917f8cb3d Mon Sep 17 00:00:00 2001 From: gururise Date: Wed, 8 Apr 2020 10:47:45 -0700 Subject: [PATCH 06/22] Update language files for PMS5003 RX and TX --- tasmota/language/bg-BG.h | 3 ++- tasmota/language/cs-CZ.h | 3 ++- tasmota/language/de-DE.h | 3 ++- tasmota/language/el-GR.h | 3 ++- tasmota/language/en-GB.h | 3 ++- tasmota/language/es-ES.h | 3 ++- tasmota/language/fr-FR.h | 3 ++- tasmota/language/he-HE.h | 3 ++- tasmota/language/hu-HU.h | 3 ++- tasmota/language/it-IT.h | 3 ++- tasmota/language/ko-KO.h | 3 ++- tasmota/language/nl-NL.h | 3 ++- tasmota/language/pl-PL.h | 3 ++- tasmota/language/pt-BR.h | 3 ++- tasmota/language/pt-PT.h | 3 ++- tasmota/language/ro-RO.h | 3 ++- tasmota/language/ru-RU.h | 3 ++- tasmota/language/sk-SK.h | 3 ++- tasmota/language/sv-SE.h | 3 ++- tasmota/language/tr-TR.h | 3 ++- tasmota/language/uk-UA.h | 3 ++- tasmota/language/zh-CN.h | 3 ++- tasmota/language/zh-TW.h | 3 ++- 23 files changed, 46 insertions(+), 23 deletions(-) diff --git a/tasmota/language/bg-BG.h b/tasmota/language/bg-BG.h index d4cb21b90..33bce1cc2 100644 --- a/tasmota/language/bg-BG.h +++ b/tasmota/language/bg-BG.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Подсветка" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/cs-CZ.h b/tasmota/language/cs-CZ.h index fb625af7b..fdf0c505c 100644 --- a/tasmota/language/cs-CZ.h +++ b/tasmota/language/cs-CZ.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/de-DE.h b/tasmota/language/de-DE.h index a698297de..db78c327e 100644 --- a/tasmota/language/de-DE.h +++ b/tasmota/language/de-DE.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/el-GR.h b/tasmota/language/el-GR.h index 6e65f2dce..635addd81 100644 --- a/tasmota/language/el-GR.h +++ b/tasmota/language/el-GR.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/en-GB.h b/tasmota/language/en-GB.h index 322757d17..0862c0fbe 100644 --- a/tasmota/language/en-GB.h +++ b/tasmota/language/en-GB.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/es-ES.h b/tasmota/language/es-ES.h index 39f18f29d..213f9dedf 100644 --- a/tasmota/language/es-ES.h +++ b/tasmota/language/es-ES.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/fr-FR.h b/tasmota/language/fr-FR.h index beb6e6b38..0fa74e022 100644 --- a/tasmota/language/fr-FR.h +++ b/tasmota/language/fr-FR.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "RétroÉcl" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 RX" #define D_SENSOR_SDS0X1_TX "SDS0X1 TX" #define D_SENSOR_HPMA_RX "HPMA RX" diff --git a/tasmota/language/he-HE.h b/tasmota/language/he-HE.h index 99e15b7fd..cd56399b6 100644 --- a/tasmota/language/he-HE.h +++ b/tasmota/language/he-HE.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/hu-HU.h b/tasmota/language/hu-HU.h index 34ea7e8a6..5cc945849 100644 --- a/tasmota/language/hu-HU.h +++ b/tasmota/language/hu-HU.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Háttérfény" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/it-IT.h b/tasmota/language/it-IT.h index 151bda319..3e94424b1 100644 --- a/tasmota/language/it-IT.h +++ b/tasmota/language/it-IT.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI - MOSI" #define D_SENSOR_SPI_CLK "SPI - CLK" #define D_SENSOR_BACKLIGHT "Retroilluminazione" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 - RX" #define D_SENSOR_SDS0X1_TX "SDS0X1 - TX" #define D_SENSOR_HPMA_RX "HPMA - RX" diff --git a/tasmota/language/ko-KO.h b/tasmota/language/ko-KO.h index 434ae07e5..e807569d9 100644 --- a/tasmota/language/ko-KO.h +++ b/tasmota/language/ko-KO.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/nl-NL.h b/tasmota/language/nl-NL.h index a129c764e..332ee935c 100644 --- a/tasmota/language/nl-NL.h +++ b/tasmota/language/nl-NL.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/pl-PL.h b/tasmota/language/pl-PL.h index 4c9da5559..ede297ffc 100644 --- a/tasmota/language/pl-PL.h +++ b/tasmota/language/pl-PL.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Podświetlanie" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/pt-BR.h b/tasmota/language/pt-BR.h index 6ce132cb1..d64b134aa 100644 --- a/tasmota/language/pt-BR.h +++ b/tasmota/language/pt-BR.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Luz de fundo" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/pt-PT.h b/tasmota/language/pt-PT.h index f87c0db4c..b4f336e65 100644 --- a/tasmota/language/pt-PT.h +++ b/tasmota/language/pt-PT.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Luz fundo" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/ro-RO.h b/tasmota/language/ro-RO.h index ce9a152e9..355dfd77b 100644 --- a/tasmota/language/ro-RO.h +++ b/tasmota/language/ro-RO.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/ru-RU.h b/tasmota/language/ru-RU.h index d2d0c153f..41e909564 100644 --- a/tasmota/language/ru-RU.h +++ b/tasmota/language/ru-RU.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/sk-SK.h b/tasmota/language/sk-SK.h index d925da9c6..037aeaaa8 100644 --- a/tasmota/language/sk-SK.h +++ b/tasmota/language/sk-SK.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/sv-SE.h b/tasmota/language/sv-SE.h index d6be6cf9b..c52b6eaa2 100644 --- a/tasmota/language/sv-SE.h +++ b/tasmota/language/sv-SE.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/tr-TR.h b/tasmota/language/tr-TR.h index 09ca53017..f7431cc12 100644 --- a/tasmota/language/tr-TR.h +++ b/tasmota/language/tr-TR.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/uk-UA.h b/tasmota/language/uk-UA.h index 4a62825e8..e477b49a7 100644 --- a/tasmota/language/uk-UA.h +++ b/tasmota/language/uk-UA.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "OLED Light" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/zh-CN.h b/tasmota/language/zh-CN.h index cb4221e75..b4b3348a3 100644 --- a/tasmota/language/zh-CN.h +++ b/tasmota/language/zh-CN.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" diff --git a/tasmota/language/zh-TW.h b/tasmota/language/zh-TW.h index 6738d4208..17267128f 100644 --- a/tasmota/language/zh-TW.h +++ b/tasmota/language/zh-TW.h @@ -567,7 +567,8 @@ #define D_SENSOR_SPI_MOSI "SPI MOSI" #define D_SENSOR_SPI_CLK "SPI CLK" #define D_SENSOR_BACKLIGHT "Backlight" -#define D_SENSOR_PMS5003 "PMS5003" +#define D_SENSOR_PMS5003_TX "PMS5003 Tx" +#define D_SENSOR_PMS5003_RX "PMS5003 Rx" #define D_SENSOR_SDS0X1_RX "SDS0X1 Rx" #define D_SENSOR_SDS0X1_TX "SDS0X1 Tx" #define D_SENSOR_HPMA_RX "HPMA Rx" From ad673bec6c2aa12b3ea5ffb02400f5d683e20a51 Mon Sep 17 00:00:00 2001 From: gururise Date: Wed, 8 Apr 2020 11:41:10 -0700 Subject: [PATCH 07/22] send commands using correct serial object --- tasmota/xsns_18_pms5003.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 209d43380..8d526bfb6 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -81,7 +81,7 @@ struct pmsX003data { size_t PmsSendCmd(uint8_t command_id) { - return MhzSerial->write(kPmsCommands[command_id], sizeof(kPmsCommands[command_id])); + return PmsSerial->write(kPmsCommands[command_id], sizeof(kPmsCommands[command_id])); } /*********************************************************************************************/ @@ -172,6 +172,7 @@ bool PmsCommandSensor(void) wake_mode = 1; pms_ready = 1; PmsSendCmd(CMD_MODE_ACTIVE); + PmsSendCmd(CMD_WAKEUP); } else if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 256)) { From 9516f339d6d6ac46e079818fe45439afa61500dd Mon Sep 17 00:00:00 2001 From: gururise Date: Wed, 8 Apr 2020 12:36:44 -0700 Subject: [PATCH 08/22] PMS5003 use active mode if TX pin not connected --- tasmota/xsns_18_pms5003.ino | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 8d526bfb6..39d60dbab 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -183,6 +183,12 @@ bool PmsCommandSensor(void) wake_mode = 0; pms_ready = 0; } + + if (pin[GPIO_PMS5003_TX] >= 99) + { + // setting interval not supported if TX pin not connected + Settings.novasds_startingoffset = 0; + } Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.novasds_startingoffset); From 873d0092e59c75ffd858888cd0da5f9cf28f0a75 Mon Sep 17 00:00:00 2001 From: gururise Date: Fri, 10 Apr 2020 23:22:27 -0700 Subject: [PATCH 09/22] settings value changed to uint16 and now in seconds --- tasmota/xsns_18_pms5003.ino | 61 +++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 39d60dbab..5629bf793 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -36,6 +36,10 @@ #define WARMUP_PERIOD 30 // Turn on PMSX003 XX-seconds before read in passive mode #endif +#ifndef MIN_INTERVAL_PERIOD +#define MIN_INTERVAL_PERIOD 60 // minimum interval period in seconds required for passive mode +#endif + TasmotaSerial *PmsSerial; uint8_t pms_type = 1; @@ -157,40 +161,43 @@ bool PmsReadData(void) } /*********************************************************************************************\ - * Command Sensor15 + * Command Sensor18 (currently using mcp230xx_int_timer variable - should change) * - * 0 - Active Mode - * 1 .. 255 - Passive Mode (read sensor every x minutes) + * Warmup time for sensor is 30 seconds, therfore setting interval time to less than 60 + * seconds doesn't really make sense. + * + * 0 - 59 - Active Mode (continuous sensor readings) + * 60 .. 65535 - Passive Mode (read sensor every x seconds) \*********************************************************************************************/ bool PmsCommandSensor(void) { - if (XdrvMailbox.payload == 0) + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) { - // Set Active Mode - Settings.novasds_startingoffset = 0; - wake_mode = 1; - pms_ready = 1; - PmsSendCmd(CMD_MODE_ACTIVE); - PmsSendCmd(CMD_WAKEUP); - } - else if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 256)) - { - // Set Passive Mode - Settings.novasds_startingoffset = XdrvMailbox.payload; - PmsSendCmd(CMD_MODE_PASSIVE); - PmsSendCmd(CMD_SLEEP); - wake_mode = 0; - pms_ready = 0; + if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) { + // Set Active Mode if interval is less than 60 seconds + Settings.mcp230xx_int_timer = 0; + wake_mode = 1; + pms_ready = 1; + PmsSendCmd(CMD_MODE_ACTIVE); + PmsSendCmd(CMD_WAKEUP); + } else { + // Set Passive Mode and schedule read once per interval time + Settings.mcp230xx_int_timer = XdrvMailbox.payload; + PmsSendCmd(CMD_MODE_PASSIVE); + PmsSendCmd(CMD_SLEEP); + wake_mode = 0; + pms_ready = 0; + } } if (pin[GPIO_PMS5003_TX] >= 99) { // setting interval not supported if TX pin not connected - Settings.novasds_startingoffset = 0; + Settings.mcp230xx_int_timer = 0; } - Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.novasds_startingoffset); + Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.mcp230xx_int_timer); return true; } @@ -199,17 +206,19 @@ bool PmsCommandSensor(void) void PmsSecond(void) // Every second { - if (Settings.novasds_startingoffset > 0) + if (Settings.mcp230xx_int_timer >= MIN_INTERVAL_PERIOD) { // Passive Mode pms_time++; - if ((((uint16_t)Settings.novasds_startingoffset) * 60 - pms_time <= WARMUP_PERIOD) && !wake_mode) + if ((Settings.mcp230xx_int_timer - pms_time <= WARMUP_PERIOD) && !wake_mode) { + // wakeup sensor WARMUP_PERIOD before read interval wake_mode = 1; PmsSendCmd(CMD_WAKEUP); } - if (pms_time >= ((uint16_t)Settings.novasds_startingoffset) * 60) + if (pms_time >= Settings.mcp230xx_int_timer) { + // sensor is awake and warmed up, set up for reading PmsSendCmd(CMD_READ_DATA); pms_ready = 1; pms_time = 0; @@ -221,7 +230,7 @@ void PmsSecond(void) // Every second if (PmsReadData()) { pms_valid = 10; - if (Settings.novasds_startingoffset > 0) + if (Settings.mcp230xx_int_timer >= MIN_INTERVAL_PERIOD) { PmsSendCmd(CMD_SLEEP); wake_mode = 0; @@ -233,7 +242,7 @@ void PmsSecond(void) // Every second if (pms_valid) { pms_valid--; - if (Settings.novasds_startingoffset > 0) + if (Settings.mcp230xx_int_timer >= MIN_INTERVAL_PERIOD) { PmsSendCmd(CMD_READ_DATA); pms_ready = 1; From 55f4c53e9b8c37137677796bcd61fd88e6e3272c Mon Sep 17 00:00:00 2001 From: blakadder Date: Sat, 11 Apr 2020 18:31:06 +0200 Subject: [PATCH 10/22] remove deprecated function --- tasmota/xsns_27_apds9960.ino | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tasmota/xsns_27_apds9960.ino b/tasmota/xsns_27_apds9960.ino index c426d535a..cdb390c73 100644 --- a/tasmota/xsns_27_apds9960.ino +++ b/tasmota/xsns_27_apds9960.ino @@ -39,18 +39,18 @@ #define XSNS_27 27 #define XI2C_21 21 // See I2CDEVICES.md -#if defined(USE_SHT) || defined(USE_VEML6070) || defined(USE_TSL2561) - #warning **** Turned off conflicting drivers SHT and VEML6070 **** - #ifdef USE_SHT - #undef USE_SHT // SHT-Driver blocks gesture sensor - #endif - #ifdef USE_VEML6070 - #undef USE_VEML6070 // address conflict on the I2C-bus - #endif - #ifdef USE_TSL2561 - #undef USE_TSL2561 // possible address conflict on the I2C-bus - #endif -#endif +// #if defined(USE_SHT) || defined(USE_VEML6070) || defined(USE_TSL2561) +// #warning **** Turned off conflicting drivers SHT and VEML6070 **** +// #ifdef USE_SHT +// #undef USE_SHT // SHT-Driver blocks gesture sensor +// #endif +// #ifdef USE_VEML6070 +// #undef USE_VEML6070 // address conflict on the I2C-bus +// #endif +// #ifdef USE_TSL2561 +// #undef USE_TSL2561 // possible address conflict on the I2C-bus +// #endif +// #endif #define APDS9960_I2C_ADDR 0x39 From 9addde235ae0b7d826fd4cf035d7e21a9a541503 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 11 Apr 2020 18:50:46 +0200 Subject: [PATCH 11/22] Add Zigbee command ``ZbConfig`` and configuration in Settings --- tasmota/CHANGELOG.md | 1 + tasmota/i18n.h | 2 + tasmota/my_user_config.h | 1 - tasmota/settings.ino | 1 + tasmota/xdrv_23_zigbee_7_statemachine.ino | 66 ++++++++++++++--- tasmota/xdrv_23_zigbee_9_impl.ino | 88 ++++++++++++++++++++++- 6 files changed, 149 insertions(+), 10 deletions(-) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 6806dba77..5f8c6339c 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -25,6 +25,7 @@ - Add support for an iAQ sensor (#8107) - Add support for Seven Segment display using HT16K33 (#8116) - Add support for AS3935 Lightning Sensor by device111 (#8130) +- Add Zigbee command ``ZbConfig`` and configuration in Settings ### 8.2.0.2 20200328 diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 706482caa..4e1b4098f 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -522,6 +522,8 @@ #define D_CMND_ZIGBEE_LIGHT "Light" #define D_JSON_ZIGBEE_LIGHT "Light" #define D_CMND_ZIGBEE_RESTORE "Restore" +#define D_CMND_ZIGBEE_CONFIG "Config" + #define D_JSON_ZIGBEE_CONFIG "Config" // Commands xdrv_25_A4988_Stepper.ino #define D_CMND_MOTOR "MOTOR" diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 660b0aabf..9b03a6a4c 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -627,7 +627,6 @@ #define USE_ZIGBEE_CHANNEL 11 // Zigbee Channel (11-26) #define USE_ZIGBEE_PRECFGKEY_L 0x0F0D0B0907050301L // note: changing requires to re-pair all devices #define USE_ZIGBEE_PRECFGKEY_H 0x0D0C0A0806040200L // note: changing requires to re-pair all devices - #define USE_ZIGBEE_PERMIT_JOIN false // don't allow joining by default #define USE_ZIGBEE_COALESCE_ATTR_TIMER 350 // timer to coalesce attribute values (in ms) // -- Other sensors/drivers ----------------------- diff --git a/tasmota/settings.ino b/tasmota/settings.ino index a1fc36fea..8d27b4db9 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -1332,6 +1332,7 @@ void SettingsDelta(void) } if (Settings.version < 0x08020003) { SettingsUpdateText(SET_TEMPLATE_NAME, Settings.user_template_name); + Settings.zb_channel = 0; // set channel to zero to force reinit of zigbee parameters } #endif // ESP8266 diff --git a/tasmota/xdrv_23_zigbee_7_statemachine.ino b/tasmota/xdrv_23_zigbee_7_statemachine.ino index fc93e8a8d..a73c47c80 100644 --- a/tasmota/xdrv_23_zigbee_7_statemachine.ino +++ b/tasmota/xdrv_23_zigbee_7_statemachine.ino @@ -148,6 +148,9 @@ SBuffer *zigbee_buffer = nullptr; #define Z_B7(a) (uint8_t)( ((a) >> 56) & 0xFF ) // Macro to define message to send and receive #define ZBM(n, x...) const uint8_t n[] PROGMEM = { x }; +// For commands that need to be changed with configuration, ZBR stores in RAM, and ZBW write new values +#define ZBR(n, x...) uint8_t n[] = { x }; // same but in RAM to be modified +#define ZBW(n, x...) { const uint8_t n##t[] = { x }; memcpy(n, n##t, sizeof(n)); } // re-write content in RAM #define USE_ZIGBEE_CHANNEL_MASK (1 << (USE_ZIGBEE_CHANNEL)) @@ -165,24 +168,24 @@ ZBM(ZBR_ZNPHC, Z_SRSP | Z_SYS, SYS_OSAL_NV_READ, Z_SUCCESS, 0x01 /* len */, 0x55 // If not set, the response is 61-08-02-00 = Z_SRSP | Z_SYS, SYS_OSAL_NV_READ, Z_INVALIDPARAMETER, 0x00 /* len */ ZBM(ZBS_PAN, Z_SREQ | Z_SAPI, SAPI_READ_CONFIGURATION, CONF_PANID ) // 260483 -ZBM(ZBR_PAN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_PANID, 0x02 /* len */, +ZBR(ZBR_PAN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_PANID, 0x02 /* len */, Z_B0(USE_ZIGBEE_PANID), Z_B1(USE_ZIGBEE_PANID) ) // 6604008302xxxx ZBM(ZBS_EXTPAN, Z_SREQ | Z_SAPI, SAPI_READ_CONFIGURATION, CONF_EXTENDED_PAN_ID ) // 26042D -ZBM(ZBR_EXTPAN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_EXTENDED_PAN_ID, +ZBR(ZBR_EXTPAN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_EXTENDED_PAN_ID, 0x08 /* len */, Z_B0(USE_ZIGBEE_EXTPANID), Z_B1(USE_ZIGBEE_EXTPANID), Z_B2(USE_ZIGBEE_EXTPANID), Z_B3(USE_ZIGBEE_EXTPANID), Z_B4(USE_ZIGBEE_EXTPANID), Z_B5(USE_ZIGBEE_EXTPANID), Z_B6(USE_ZIGBEE_EXTPANID), Z_B7(USE_ZIGBEE_EXTPANID), ) // 6604002D08xxxxxxxxxxxxxxxx ZBM(ZBS_CHANN, Z_SREQ | Z_SAPI, SAPI_READ_CONFIGURATION, CONF_CHANLIST ) // 260484 -ZBM(ZBR_CHANN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_CHANLIST, +ZBR(ZBR_CHANN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_CHANLIST, 0x04 /* len */, Z_B0(USE_ZIGBEE_CHANNEL_MASK), Z_B1(USE_ZIGBEE_CHANNEL_MASK), Z_B2(USE_ZIGBEE_CHANNEL_MASK), Z_B3(USE_ZIGBEE_CHANNEL_MASK), ) // 6604008404xxxxxxxx ZBM(ZBS_PFGK, Z_SREQ | Z_SAPI, SAPI_READ_CONFIGURATION, CONF_PRECFGKEY ) // 260462 -ZBM(ZBR_PFGK, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_PRECFGKEY, +ZBR(ZBR_PFGK, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_PRECFGKEY, 0x10 /* len */, Z_B0(USE_ZIGBEE_PRECFGKEY_L), Z_B1(USE_ZIGBEE_PRECFGKEY_L), Z_B2(USE_ZIGBEE_PRECFGKEY_L), Z_B3(USE_ZIGBEE_PRECFGKEY_L), Z_B4(USE_ZIGBEE_PRECFGKEY_L), Z_B5(USE_ZIGBEE_PRECFGKEY_L), Z_B6(USE_ZIGBEE_PRECFGKEY_L), Z_B7(USE_ZIGBEE_PRECFGKEY_L), @@ -203,20 +206,20 @@ ZBM(ZBR_WNV_OK, Z_SRSP | Z_SYS, SYS_OSAL_NV_WRITE, Z_SUCCESS ) // 610900 - NV // Factory reset ZBM(ZBS_FACTRES, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_STARTUP_OPTION, 0x01 /* len */, 0x02 ) // 2605030102 // Write PAN ID -ZBM(ZBS_W_PAN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_PANID, 0x02 /* len */, Z_B0(USE_ZIGBEE_PANID), Z_B1(USE_ZIGBEE_PANID) ) // 26058302xxxx +ZBR(ZBS_W_PAN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_PANID, 0x02 /* len */, Z_B0(USE_ZIGBEE_PANID), Z_B1(USE_ZIGBEE_PANID) ) // 26058302xxxx // Write EXT PAN ID -ZBM(ZBS_W_EXTPAN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_EXTENDED_PAN_ID, 0x08 /* len */, +ZBR(ZBS_W_EXTPAN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_EXTENDED_PAN_ID, 0x08 /* len */, Z_B0(USE_ZIGBEE_EXTPANID), Z_B1(USE_ZIGBEE_EXTPANID), Z_B2(USE_ZIGBEE_EXTPANID), Z_B3(USE_ZIGBEE_EXTPANID), Z_B4(USE_ZIGBEE_EXTPANID), Z_B5(USE_ZIGBEE_EXTPANID), Z_B6(USE_ZIGBEE_EXTPANID), Z_B7(USE_ZIGBEE_EXTPANID) ) // 26052D086263151D004B1200 // Write Channel ID -ZBM(ZBS_W_CHANN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_CHANLIST, 0x04 /* len */, +ZBR(ZBS_W_CHANN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_CHANLIST, 0x04 /* len */, Z_B0(USE_ZIGBEE_CHANNEL_MASK), Z_B1(USE_ZIGBEE_CHANNEL_MASK), Z_B2(USE_ZIGBEE_CHANNEL_MASK), Z_B3(USE_ZIGBEE_CHANNEL_MASK), /*0x00, 0x08, 0x00, 0x00*/ ) // 26058404xxxxxxxx // Write Logical Type = 00 = coordinator ZBM(ZBS_W_LOGTYP, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_LOGICAL_TYPE, 0x01 /* len */, 0x00 ) // 2605870100 // Write precfgkey -ZBM(ZBS_W_PFGK, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_PRECFGKEY, +ZBR(ZBS_W_PFGK, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_PRECFGKEY, 0x10 /* len */, Z_B0(USE_ZIGBEE_PRECFGKEY_L), Z_B1(USE_ZIGBEE_PRECFGKEY_L), Z_B2(USE_ZIGBEE_PRECFGKEY_L), Z_B3(USE_ZIGBEE_PRECFGKEY_L), Z_B4(USE_ZIGBEE_PRECFGKEY_L), Z_B5(USE_ZIGBEE_PRECFGKEY_L), Z_B6(USE_ZIGBEE_PRECFGKEY_L), Z_B7(USE_ZIGBEE_PRECFGKEY_L), @@ -301,6 +304,53 @@ ZBM(ZBS_PERMITJOINREQ_CLOSE, Z_SREQ | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_REQ, 0x02 /* A ZBM(ZBR_PERMITJOINREQ, Z_SRSP | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_REQ, Z_SUCCESS) // 653600 ZBM(ZBR_PERMITJOIN_AREQ_RSP, Z_AREQ | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_RSP, 0x00, 0x00 /* srcAddr*/, Z_SUCCESS ) // 45B6000000 +// Update the relevant commands with Settings +void Z_UpdateConfig(uint8_t zb_channel, uint16_t zb_pan_id, uint64_t zb_ext_panid, uint64_t zb_precfgkey_l, uint64_t zb_precfgkey_h) { + uint32_t zb_channel_mask = (1 << zb_channel); + + ZBW(ZBR_PAN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_PANID, 0x02 /* len */, + Z_B0(zb_pan_id), Z_B1(zb_pan_id) ) // 6604008302xxxx + + ZBW(ZBR_EXTPAN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_EXTENDED_PAN_ID, + 0x08 /* len */, + Z_B0(zb_ext_panid), Z_B1(zb_ext_panid), Z_B2(zb_ext_panid), Z_B3(zb_ext_panid), + Z_B4(zb_ext_panid), Z_B5(zb_ext_panid), Z_B6(zb_ext_panid), Z_B7(zb_ext_panid), + ) // 6604002D08xxxxxxxxxxxxxxxx + + ZBW(ZBR_CHANN, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_CHANLIST, + 0x04 /* len */, + Z_B0(zb_channel_mask), Z_B1(zb_channel_mask), Z_B2(zb_channel_mask), Z_B3(zb_channel_mask), + ) // 6604008404xxxxxxxx + + ZBW(ZBR_PFGK, Z_SRSP | Z_SAPI, SAPI_READ_CONFIGURATION, Z_SUCCESS, CONF_PRECFGKEY, + 0x10 /* len */, + Z_B0(zb_precfgkey_l), Z_B1(zb_precfgkey_l), Z_B2(zb_precfgkey_l), Z_B3(zb_precfgkey_l), + Z_B4(zb_precfgkey_l), Z_B5(zb_precfgkey_l), Z_B6(zb_precfgkey_l), Z_B7(zb_precfgkey_l), + Z_B0(zb_precfgkey_h), Z_B1(zb_precfgkey_h), Z_B2(zb_precfgkey_h), Z_B3(zb_precfgkey_h), + Z_B4(zb_precfgkey_h), Z_B5(zb_precfgkey_h), Z_B6(zb_precfgkey_h), Z_B7(zb_precfgkey_h), + /*0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, + 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0D*/ ) // 660400621001030507090B0D0F00020406080A0C0D + + ZBW(ZBS_W_PAN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_PANID, 0x02 /* len */, Z_B0(zb_pan_id), Z_B1(zb_pan_id) ) // 26058302xxxx + // Write EXT PAN ID + ZBW(ZBS_W_EXTPAN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_EXTENDED_PAN_ID, 0x08 /* len */, + Z_B0(zb_ext_panid), Z_B1(zb_ext_panid), Z_B2(zb_ext_panid), Z_B3(zb_ext_panid), + Z_B4(zb_ext_panid), Z_B5(zb_ext_panid), Z_B6(zb_ext_panid), Z_B7(zb_ext_panid) + ) // 26052D086263151D004B1200 + // Write Channel ID + ZBW(ZBS_W_CHANN, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_CHANLIST, 0x04 /* len */, + Z_B0(zb_channel_mask), Z_B1(zb_channel_mask), Z_B2(zb_channel_mask), Z_B3(zb_channel_mask), + /*0x00, 0x08, 0x00, 0x00*/ ) // 26058404xxxxxxxx + // Write precfgkey + ZBW(ZBS_W_PFGK, Z_SREQ | Z_SAPI, SAPI_WRITE_CONFIGURATION, CONF_PRECFGKEY, + 0x10 /* len */, + Z_B0(zb_precfgkey_l), Z_B1(zb_precfgkey_l), Z_B2(zb_precfgkey_l), Z_B3(zb_precfgkey_l), + Z_B4(zb_precfgkey_l), Z_B5(zb_precfgkey_l), Z_B6(zb_precfgkey_l), Z_B7(zb_precfgkey_l), + Z_B0(zb_precfgkey_h), Z_B1(zb_precfgkey_h), Z_B2(zb_precfgkey_h), Z_B3(zb_precfgkey_h), + Z_B4(zb_precfgkey_h), Z_B5(zb_precfgkey_h), Z_B6(zb_precfgkey_h), Z_B7(zb_precfgkey_h), + ) // 2605621001030507090B0D0F00020406080A0C0D +} + const char kCheckingDeviceConfiguration[] PROGMEM = D_LOG_ZIGBEE "checking device configuration"; const char kConfigured[] PROGMEM = "Configured, starting coordinator"; const char kStarted[] PROGMEM = "Started"; diff --git a/tasmota/xdrv_23_zigbee_9_impl.ino b/tasmota/xdrv_23_zigbee_9_impl.ino index 163580255..845babc2d 100644 --- a/tasmota/xdrv_23_zigbee_9_impl.ino +++ b/tasmota/xdrv_23_zigbee_9_impl.ino @@ -35,7 +35,8 @@ const char kZbCommands[] PROGMEM = D_PRFX_ZB "|" // prefix D_CMND_ZIGBEE_PROBE "|" D_CMND_ZIGBEE_READ "|" D_CMND_ZIGBEEZNPRECEIVE "|" D_CMND_ZIGBEE_FORGET "|" D_CMND_ZIGBEE_SAVE "|" D_CMND_ZIGBEE_NAME "|" D_CMND_ZIGBEE_BIND "|" D_CMND_ZIGBEE_UNBIND "|" D_CMND_ZIGBEE_PING "|" D_CMND_ZIGBEE_MODELID "|" - D_CMND_ZIGBEE_LIGHT "|" D_CMND_ZIGBEE_RESTORE "|" D_CMND_ZIGBEE_BIND_STATE + D_CMND_ZIGBEE_LIGHT "|" D_CMND_ZIGBEE_RESTORE "|" D_CMND_ZIGBEE_BIND_STATE "|" + D_CMND_ZIGBEE_CONFIG ; void (* const ZigbeeCommand[])(void) PROGMEM = { @@ -45,6 +46,7 @@ void (* const ZigbeeCommand[])(void) PROGMEM = { &CmndZbForget, &CmndZbSave, &CmndZbName, &CmndZbBind, &CmndZbUnbind, &CmndZbPing, &CmndZbModelId, &CmndZbLight, &CmndZbRestore, &CmndZbBindState, + &CmndZbConfig, }; // @@ -145,6 +147,19 @@ void ZigbeeInputLoop(void) // Initialize internal structures void ZigbeeInit(void) { + // Check if settings if Flash are set + if (0 == Settings.zb_channel) { + AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Initializing Zigbee parameters from defaults")); + Settings.zb_ext_panid = USE_ZIGBEE_EXTPANID; + Settings.zb_precfgkey_l = USE_ZIGBEE_PRECFGKEY_L; + Settings.zb_precfgkey_h = USE_ZIGBEE_PRECFGKEY_H; + Settings.zb_pan_id = USE_ZIGBEE_PANID; + Settings.zb_channel = USE_ZIGBEE_CHANNEL; + Settings.zb_free_byte = 0; + } + // update commands with the current settings + Z_UpdateConfig(Settings.zb_channel, Settings.zb_pan_id, Settings.zb_ext_panid, Settings.zb_precfgkey_l, Settings.zb_precfgkey_h); + // AddLog_P2(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem1 = %d"), ESP.getFreeHeap()); zigbee.active = false; if ((pin[GPIO_ZIGBEE_RX] < 99) && (pin[GPIO_ZIGBEE_TX] < 99)) { @@ -1007,6 +1022,77 @@ void CmndZbStatus(void) { } } +// +// Command `ZbConfig` +// +void CmndZbConfig(void) { + // ZbConfig + // ZbConfig {"Channel":11,"PanID":"0x1A63","ExtPanID":"0xCCCCCCCCCCCCCCCC","KeyL":"0x0F0D0B0907050301L","KeyH":"0x0D0C0A0806040200L"} + uint8_t zb_channel = Settings.zb_channel; + uint16_t zb_pan_id = Settings.zb_pan_id; + uint64_t zb_ext_panid = Settings.zb_ext_panid; + uint64_t zb_precfgkey_l = Settings.zb_precfgkey_l; + uint64_t zb_precfgkey_h = Settings.zb_precfgkey_h; + + // if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; } + RemoveAllSpaces(XdrvMailbox.data); + if (strlen(XdrvMailbox.data) > 0) { + DynamicJsonBuffer jsonBuf; + const JsonObject &json = jsonBuf.parseObject((const char*) XdrvMailbox.data); + if (!json.success()) { ResponseCmndChar_P(PSTR(D_JSON_INVALID_JSON)); return; } + + // Channel + const JsonVariant &val_channel = getCaseInsensitive(json, PSTR("Channel")); + if (nullptr != &val_channel) { zb_channel = strToUInt(val_channel); } + // PanID + const JsonVariant &val_pan_id = getCaseInsensitive(json, PSTR("PanID")); + if (nullptr != &val_pan_id) { zb_pan_id = strToUInt(val_pan_id); } + // ExtPanID + const JsonVariant &val_ext_pan_id = getCaseInsensitive(json, PSTR("ExtPanID")); + if (nullptr != &val_ext_pan_id) { zb_ext_panid = strtoull(val_ext_pan_id.as(), nullptr, 0); } + // KeyL + const JsonVariant &val_key_l = getCaseInsensitive(json, PSTR("KeyL")); + if (nullptr != &val_key_l) { zb_precfgkey_l = strtoull(val_key_l.as(), nullptr, 0); } + // KeyH + const JsonVariant &val_key_h = getCaseInsensitive(json, PSTR("KeyH")); + if (nullptr != &val_key_h) { zb_precfgkey_h = strtoull(val_key_h.as(), nullptr, 0); } + + // Check if a parameter was changed after all + if ( (zb_channel != Settings.zb_channel) || + (zb_pan_id != Settings.zb_pan_id) || + (zb_ext_panid != Settings.zb_ext_panid) || + (zb_precfgkey_l != Settings.zb_precfgkey_l) || + (zb_precfgkey_h != Settings.zb_precfgkey_h) ) { + Settings.zb_channel = zb_channel; + Settings.zb_pan_id = zb_pan_id; + Settings.zb_ext_panid = zb_ext_panid; + Settings.zb_precfgkey_l = zb_precfgkey_l; + Settings.zb_precfgkey_h = zb_precfgkey_h; + restart_flag = 2; // save and reboot + } + } + + // display the current or new configuration + char hex_ext_panid[20] = "0x"; + Uint64toHex(zb_ext_panid, &hex_ext_panid[2], 64); + char hex_precfgkey_l[20] = "0x"; + Uint64toHex(zb_precfgkey_l, &hex_precfgkey_l[2], 64); + char hex_precfgkey_h[20] = "0x"; + Uint64toHex(zb_precfgkey_h, &hex_precfgkey_h[2], 64); + + // {"ZbConfig":{"Channel":11,"PanID":"0x1A63","ExtPanID":"0xCCCCCCCCCCCCCCCC","KeyL":"0x0F0D0B0907050301L","KeyH":"0x0D0C0A0806040200L"}} + Response_P(PSTR("{\"" D_PRFX_ZB D_JSON_ZIGBEE_CONFIG "\":{" + "\"Channel\":%d" + ",\"PanID\":\"0x%04X\"" + ",\"ExtPanID\":\"%s\"" + ",\"KeyL\":\"%s\"" + ",\"KeyH\":\"%s\"" + "}}"), + zb_channel, zb_pan_id, + hex_ext_panid, + hex_precfgkey_l, hex_precfgkey_h); +} + /*********************************************************************************************\ * Interface \*********************************************************************************************/ From 57b28112b0e4fbe3adad91855bd9582c036aef32 Mon Sep 17 00:00:00 2001 From: gururise Date: Sat, 11 Apr 2020 09:55:15 -0700 Subject: [PATCH 12/22] move new GPIO TX to end of enum to avoid breaking gpio numbering --- tasmota/tasmota_template.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 83db4bace..164b5e758 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -93,7 +93,6 @@ enum UserSelectablePins { GPIO_SPI_CS, // SPI Chip Select GPIO_SPI_DC, // SPI Data Direction GPIO_BACKLIGHT, // Display backlight control - GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface GPIO_SBR_TX, // Serial Bridge Serial interface @@ -228,6 +227,7 @@ enum UserSelectablePins { GPIO_HRXL_RX, // Data from MaxBotix HRXL sonar range sensor GPIO_ELECTRIQ_MOODL_TX, // ElectriQ iQ-wifiMOODL Serial TX GPIO_AS3935, + GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface GPIO_SENSOR_END }; // Programmer selectable GPIO functionality From a3abdbfef2b9396e567ced2f257501f919af4117 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 11 Apr 2020 19:01:39 +0200 Subject: [PATCH 13/22] Ensure zb_channel is in 11..26 range --- tasmota/xdrv_23_zigbee_9_impl.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasmota/xdrv_23_zigbee_9_impl.ino b/tasmota/xdrv_23_zigbee_9_impl.ino index 845babc2d..86c63eb5b 100644 --- a/tasmota/xdrv_23_zigbee_9_impl.ino +++ b/tasmota/xdrv_23_zigbee_9_impl.ino @@ -1044,6 +1044,8 @@ void CmndZbConfig(void) { // Channel const JsonVariant &val_channel = getCaseInsensitive(json, PSTR("Channel")); if (nullptr != &val_channel) { zb_channel = strToUInt(val_channel); } + if (zb_channel < 11) { zb_channel = 11; } + if (zb_channel > 26) { zb_channel = 26; } // PanID const JsonVariant &val_pan_id = getCaseInsensitive(json, PSTR("PanID")); if (nullptr != &val_pan_id) { zb_pan_id = strToUInt(val_pan_id); } From 54f7cf475d7ea4f0493a58ea8f543d4a2e24b5c8 Mon Sep 17 00:00:00 2001 From: gururise Date: Sat, 11 Apr 2020 10:37:12 -0700 Subject: [PATCH 14/22] create new setting pms_wake_interval for PMS sensor interval time --- tasmota/settings.h | 3 ++- tasmota/xsns_18_pms5003.ino | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index ae4d2eaf9..a9b6d0bc6 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -505,8 +505,9 @@ struct PACKED SYSCFG { uint16_t zb_pan_id; // F30 uint8_t zb_channel; // F32 uint8_t zb_free_byte; // F33 + uint16_t pms_wake_interval; - uint8_t free_f18[132]; // F34 + uint8_t free_f18[130]; // F34 uint16_t pulse_counter_debounce_low; // FB8 uint16_t pulse_counter_debounce_high; // FBA diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 5629bf793..2ad18ba35 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -161,7 +161,7 @@ bool PmsReadData(void) } /*********************************************************************************************\ - * Command Sensor18 (currently using mcp230xx_int_timer variable - should change) + * Command Sensor18 * * Warmup time for sensor is 30 seconds, therfore setting interval time to less than 60 * seconds doesn't really make sense. @@ -176,14 +176,14 @@ bool PmsCommandSensor(void) { if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) { // Set Active Mode if interval is less than 60 seconds - Settings.mcp230xx_int_timer = 0; + Settings.pms_wake_interval = 0; wake_mode = 1; pms_ready = 1; PmsSendCmd(CMD_MODE_ACTIVE); PmsSendCmd(CMD_WAKEUP); } else { // Set Passive Mode and schedule read once per interval time - Settings.mcp230xx_int_timer = XdrvMailbox.payload; + Settings.pms_wake_interval = XdrvMailbox.payload; PmsSendCmd(CMD_MODE_PASSIVE); PmsSendCmd(CMD_SLEEP); wake_mode = 0; @@ -194,10 +194,10 @@ bool PmsCommandSensor(void) if (pin[GPIO_PMS5003_TX] >= 99) { // setting interval not supported if TX pin not connected - Settings.mcp230xx_int_timer = 0; + Settings.pms_wake_interval = 0; } - Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.mcp230xx_int_timer); + Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.pms_wake_interval); return true; } @@ -206,17 +206,17 @@ bool PmsCommandSensor(void) void PmsSecond(void) // Every second { - if (Settings.mcp230xx_int_timer >= MIN_INTERVAL_PERIOD) + if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) { // Passive Mode pms_time++; - if ((Settings.mcp230xx_int_timer - pms_time <= WARMUP_PERIOD) && !wake_mode) + if ((Settings.pms_wake_interval - pms_time <= WARMUP_PERIOD) && !wake_mode) { // wakeup sensor WARMUP_PERIOD before read interval wake_mode = 1; PmsSendCmd(CMD_WAKEUP); } - if (pms_time >= Settings.mcp230xx_int_timer) + if (pms_time >= Settings.pms_wake_interval) { // sensor is awake and warmed up, set up for reading PmsSendCmd(CMD_READ_DATA); @@ -230,7 +230,7 @@ void PmsSecond(void) // Every second if (PmsReadData()) { pms_valid = 10; - if (Settings.mcp230xx_int_timer >= MIN_INTERVAL_PERIOD) + if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) { PmsSendCmd(CMD_SLEEP); wake_mode = 0; @@ -242,7 +242,7 @@ void PmsSecond(void) // Every second if (pms_valid) { pms_valid--; - if (Settings.mcp230xx_int_timer >= MIN_INTERVAL_PERIOD) + if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) { PmsSendCmd(CMD_READ_DATA); pms_ready = 1; From 86455df73b885f3e96afd0ac5af98af971259bd6 Mon Sep 17 00:00:00 2001 From: gururise Date: Sat, 11 Apr 2020 12:02:09 -0700 Subject: [PATCH 15/22] move PMS5003_TX to end of kSensorNames[] array to avoid breaking gpio numbering --- tasmota/tasmota_template.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 164b5e758..ffb520013 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -261,7 +261,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_PZEM0XX_TX "|" D_SENSOR_PZEM004_RX "|" D_SENSOR_SAIR_TX "|" D_SENSOR_SAIR_RX "|" D_SENSOR_SPI_CS "|" D_SENSOR_SPI_DC "|" D_SENSOR_BACKLIGHT "|" - D_SENSOR_PMS5003_TX "|" D_SENSOR_PMS5003_RX "|" D_SENSOR_SDS0X1_RX "|" + D_SENSOR_PMS5003_RX "|" 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 "|" @@ -315,7 +315,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_CC1101_GDO0 "|" D_SENSOR_CC1101_GDO2 "|" D_SENSOR_HRXL_RX "|" D_SENSOR_ELECTRIQ_MOODL "|" - D_SENSOR_AS3935 + D_SENSOR_AS3935 "|" D_SENSOR_PMS5003_TX ; const char kSensorNamesFixed[] PROGMEM = From 7feb463ffe172fbdab9e00c57844db44baa7d9aa Mon Sep 17 00:00:00 2001 From: to-scho Date: Sun, 12 Apr 2020 10:36:24 +0200 Subject: [PATCH 16/22] Added 'toggle' to valid ShutterPosition arguments like up, down, open, close doc already updated --- tasmota/xdrv_27_shutter.ino | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tasmota/xdrv_27_shutter.ino b/tasmota/xdrv_27_shutter.ino index c91b8604d..f94464cad 100644 --- a/tasmota/xdrv_27_shutter.ino +++ b/tasmota/xdrv_27_shutter.ino @@ -845,6 +845,10 @@ void CmndShutterPosition(void) CmndShutterClose(); return; } + if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_TOGGLE)) { + CmndShutterToggle(); + return; + } if (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOP) || ((Shutter.direction[index]) && (!strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOPOPEN) || !strcasecmp(XdrvMailbox.data,D_CMND_SHUTTER_STOPCLOSE)))) { XdrvMailbox.payload = -99; CmndShutterStop(); From 7651b447fb47486a233190dff81a2a9a94baf40f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 12 Apr 2020 11:26:33 +0200 Subject: [PATCH 17/22] Fix SI1145 compile warning Fix SI1145 compile warning (#8141) --- tasmota/support.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 2a794d545..f6ee1b059 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1778,7 +1778,7 @@ void AddLogSerial(uint32_t loglevel) AddLogBuffer(loglevel, (uint8_t*)serial_in_buffer, serial_in_byte_counter); } -void AddLogMissed(char *sensor, uint32_t misses) +void AddLogMissed(const char *sensor, uint32_t misses) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SNS: %s missed %d"), sensor, SENSOR_MAX_MISS - misses); } From 2b19e24b995776647812c1544adb361a02f7202d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 12 Apr 2020 11:29:24 +0200 Subject: [PATCH 18/22] Update ESP32 MQTT_MAX_PACKET_SIZE --- platformio_override_esp32.ini | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platformio_override_esp32.ini b/platformio_override_esp32.ini index d2f6ae536..47338bd60 100644 --- a/platformio_override_esp32.ini +++ b/platformio_override_esp32.ini @@ -70,7 +70,7 @@ build_flags = ${common.build_flags} -DMY_LANGUAGE=nl-NL [common32] platform = espressif32@1.12.0 -platform_packages = +platform_packages = board = wemos_d1_mini32 board_build.ldscript = esp32_out.ld board_build.flash_mode = ${common.board_build.flash_mode} @@ -82,9 +82,9 @@ upload_resetmethod = ${common.upload_resetmethod} upload_speed = 921600 extra_scripts = ${common.extra_scripts} -build_flags = +build_flags = -D BUFFER_LENGTH=128 - -D MQTT_MAX_PACKET_SIZE=1000 + -D MQTT_MAX_PACKET_SIZE=1200 -D uint32=uint32_t -D uint16=uint16_t -D uint8=uint8_t @@ -95,10 +95,10 @@ build_flags = -D memcmp_P=memcmp ; -D USE_CONFIG_OVERRIDE -lib_extra_dirs = +lib_extra_dirs = libesp32 -lib_ignore = +lib_ignore = ESP MQTT TasmotaMqtt ILI9488 From bd8213cfd431ce0097bcc07d6a87b22834153e34 Mon Sep 17 00:00:00 2001 From: Staars Date: Sun, 12 Apr 2020 12:14:30 +0200 Subject: [PATCH 19/22] update xsns_62_MI_HM10.ino --- tasmota/xsns_62_MI_HM10.ino | 203 ++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 116 deletions(-) diff --git a/tasmota/xsns_62_MI_HM10.ino b/tasmota/xsns_62_MI_HM10.ino index 581a32096..b19ba6ff0 100644 --- a/tasmota/xsns_62_MI_HM10.ino +++ b/tasmota/xsns_62_MI_HM10.ino @@ -20,6 +20,8 @@ -------------------------------------------------------------------------------------------- Version yyyymmdd Action Description -------------------------------------------------------------------------------------------- + 0.9.3.1 20200412 added - clean ups, code shrink, battery bugfix + --- 0.9.3.0 20200322 added - multi page web view, command HM10PAGE, polling for MJ_HT_V1, more stable readings, internal refactoring --- @@ -211,10 +213,10 @@ enum HM10_awaitData: uint8_t { #define TASK_HM10_FEEDBACK 9 // get device response #define TASK_HM10_DISCONN 10 // disconnect #define TASK_HM10_SUB_L3 11 // subscribe to service handle 37 -#define TASK_HM10_READ_HT 12 // read from handle 36 -> Hum & Temp + #define TASK_HM10_SCAN9 13 // longest discovery scan possible #define TASK_HM10_UN_L3 14 // unsubscribe service handle 37 -#define TASK_HM10_DELAY_SUB_LY 15 // start reading from subscription delayed + #define TASK_HM10_READ_BT_L3 16 // read from handle 3A -> Battery #define TASK_HM10_SUB_L2 17 // subscribe to service handle 3C #define TASK_HM10_UN_L2 18 // unsubscribe service handle 3C @@ -227,7 +229,7 @@ enum HM10_awaitData: uint8_t { #define TASK_HM10_SUB_HT_CGD1 25 // subscribe to service handle 4b #define TASK_HM10_UN_HT_CGD1 26 // unsubscribe service handle 4b #define TASK_HM10_READ_B_CGD1 27 // read service handle 11 -#define TASK_HM10_DELAY_SUB_CGD1 28 // start reading from subscription delayed + #define TASK_HM10_READ_B_MJ 29 // read service handle 18 #define TASK_HM10_SUB_HT_MJ 30 // subscribe to service handle 0f @@ -356,14 +358,14 @@ uint32_t MIBLEgetSensorSlot(uint8_t (&_serial)[6], uint16_t _type){ DEBUG_SENSOR_LOG(PSTR("%s: vector size %u"),D_CMND_HM10, MIBLEsensors.size()); for(uint32_t i=0; i3) return; // probably false alarm from a damaged packet + if(memcmp(_beacon.Mac,MIBLEsensors[_slot].serial,sizeof(_beacon.Mac))!=0){ + if (MIBLEsensors[_slot].showedUp>3) return; // probably false alarm from a damaged packet AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: remove garbage sensor"),D_CMND_HM10); - DEBUG_SENSOR_LOG(PSTR("%s i: %x %x %x %x %x %x"),D_CMND_HM10, MIBLEsensors.at(_slot).serial[5], MIBLEsensors.at(_slot).serial[4],MIBLEsensors.at(_slot).serial[3],MIBLEsensors.at(_slot).serial[2],MIBLEsensors.at(_slot).serial[1],MIBLEsensors.at(_slot).serial[0]); + DEBUG_SENSOR_LOG(PSTR("%s i: %x %x %x %x %x %x"),D_CMND_HM10, MIBLEsensors[_slot].serial[5], MIBLEsensors[_slot].serial[4],MIBLEsensors[_slot].serial[3],MIBLEsensors[_slot].serial[2],MIBLEsensors[_slot].serial[1],MIBLEsensors[_slot].serial[0]); DEBUG_SENSOR_LOG(PSTR("%s n: %x %x %x %x %x %x"),D_CMND_HM10, _beacon.Mac[5], _beacon.Mac[4], _beacon.Mac[3],_beacon.Mac[2],_beacon.Mac[1],_beacon.Mac[0]); MIBLEsensors.erase(MIBLEsensors.begin()+_slot); return; } - if (MIBLEsensors.at(_slot).showedUp<4) MIBLEsensors.at(_slot).showedUp++; + if (MIBLEsensors[_slot].showedUp<4) MIBLEsensors[_slot].showedUp++; DEBUG_SENSOR_LOG(PSTR("MiBeacon type:%02x: %02x %02x %02x %02x %02x %02x %02x %02x"),_beacon.type, (uint8_t)_buf[0],(uint8_t)_buf[1],(uint8_t)_buf[2],(uint8_t)_buf[3],(uint8_t)_buf[4],(uint8_t)_buf[5],(uint8_t)_buf[6],(uint8_t)_buf[7]); DEBUG_SENSOR_LOG(PSTR(" type:%02x: %02x %02x %02x %02x %02x %02x %02x %02x"),_beacon.type, (uint8_t)_buf[8],(uint8_t)_buf[9],(uint8_t)_buf[10],(uint8_t)_buf[11],(uint8_t)_buf[12],(uint8_t)_buf[13],(uint8_t)_buf[14],(uint8_t)_buf[15]); - if(MIBLEsensors.at(_slot).type==4 || MIBLEsensors.at(_slot).type==6){ - DEBUG_SENSOR_LOG(PSTR("LYWSD03 and CGD1 no support for MiBeacon, type %u"),MIBLEsensors.at(_slot).type); + if(MIBLEsensors[_slot].type==4 || MIBLEsensors[_slot].type==6){ + DEBUG_SENSOR_LOG(PSTR("LYWSD03 and CGD1 no support for MiBeacon, type %u"),MIBLEsensors[_slot].type); return; } - DEBUG_SENSOR_LOG(PSTR("%s at slot %u"), kHM10SlaveType[MIBLEsensors.at(_slot).type-1],_slot); + DEBUG_SENSOR_LOG(PSTR("%s at slot %u"), kHM10SlaveType[MIBLEsensors[_slot].type-1],_slot); switch(_beacon.type){ case 0x04: _tempFloat=(float)(_beacon.temp)/10.0f; if(_tempFloat<60){ - MIBLEsensors.at(_slot).temp=_tempFloat; + MIBLEsensors[_slot].temp=_tempFloat; DEBUG_SENSOR_LOG(PSTR("Mode 4: temp updated")); } DEBUG_SENSOR_LOG(PSTR("Mode 4: U16: %u Temp"), _beacon.temp ); @@ -460,19 +462,19 @@ void HM10parseMiBeacon(char * _buf, uint32_t _slot){ case 0x06: _tempFloat=(float)(_beacon.hum)/10.0f; if(_tempFloat<101){ - MIBLEsensors.at(_slot).hum=_tempFloat; + MIBLEsensors[_slot].hum=_tempFloat; DEBUG_SENSOR_LOG(PSTR("Mode 6: hum updated")); } DEBUG_SENSOR_LOG(PSTR("Mode 6: U16: %u Hum"), _beacon.hum); break; case 0x07: - MIBLEsensors.at(_slot).lux=_beacon.lux & 0x00ffffff; + MIBLEsensors[_slot].lux=_beacon.lux & 0x00ffffff; DEBUG_SENSOR_LOG(PSTR("Mode 7: U24: %u Lux"), _beacon.lux & 0x00ffffff); break; case 0x08: _tempFloat =(float)_beacon.moist; if(_tempFloat<100){ - MIBLEsensors.at(_slot).moisture=_tempFloat; + MIBLEsensors[_slot].moisture=_tempFloat; DEBUG_SENSOR_LOG(PSTR("Mode 8: moisture updated")); } DEBUG_SENSOR_LOG(PSTR("Mode 8: U8: %u Moisture"), _beacon.moist); @@ -480,14 +482,14 @@ void HM10parseMiBeacon(char * _buf, uint32_t _slot){ case 0x09: _tempFloat=(float)(_beacon.fert); if(_tempFloat<65535){ // ??? - MIBLEsensors.at(_slot).fertility=_tempFloat; + MIBLEsensors[_slot].fertility=_tempFloat; DEBUG_SENSOR_LOG(PSTR("Mode 9: fertility updated")); } DEBUG_SENSOR_LOG(PSTR("Mode 9: U16: %u Fertility"), _beacon.fert); break; case 0x0a: if(_beacon.bat<101){ - MIBLEsensors.at(_slot).bat = _beacon.bat; + MIBLEsensors[_slot].bat = _beacon.bat; DEBUG_SENSOR_LOG(PSTR("Mode a: bat updated")); } DEBUG_SENSOR_LOG(PSTR("Mode a: U8: %u %%"), _beacon.bat); @@ -495,12 +497,12 @@ void HM10parseMiBeacon(char * _buf, uint32_t _slot){ case 0x0d: _tempFloat=(float)(_beacon.HT.temp)/10.0f; if(_tempFloat<60){ - MIBLEsensors.at(_slot).temp = _tempFloat; + MIBLEsensors[_slot].temp = _tempFloat; DEBUG_SENSOR_LOG(PSTR("Mode d: temp updated")); } _tempFloat=(float)(_beacon.HT.hum)/10.0f; if(_tempFloat<100){ - MIBLEsensors.at(_slot).hum = _tempFloat; + MIBLEsensors[_slot].hum = _tempFloat; DEBUG_SENSOR_LOG(PSTR("Mode d: hum updated")); } DEBUG_SENSOR_LOG(PSTR("Mode d: U16: %x Temp U16: %x Hum"), _beacon.HT.temp, _beacon.HT.hum); @@ -553,7 +555,7 @@ void HM10ParseResponse(char *buf, uint16_t bufsize) { void HM10readHT_LY(char *_buf){ DEBUG_SENSOR_LOG(PSTR("%s: raw data: %x%x%x%x%x%x%x"),D_CMND_HM10,_buf[0],_buf[1],_buf[2],_buf[3],_buf[4],_buf[5],_buf[6]); - if(_buf[0]==0x4f && _buf[1]==0x4b && _buf[2]==0x2b) return; // "OK+" + if(_buf[0]==0x4f && _buf[1]==0x4b) return; // "OK" if(_buf[0] != 0 && _buf[1] != 0){ memcpy(&LYWSD0x_HT,(void *)_buf,3); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: T * 100: %u, H: %u"),D_CMND_HM10,LYWSD0x_HT.temp,LYWSD0x_HT.hum); @@ -563,14 +565,14 @@ void HM10readHT_LY(char *_buf){ static float _tempFloat; _tempFloat=(float)(LYWSD0x_HT.temp)/100.0f; if(_tempFloat<60){ - MIBLEsensors.at(_slot).temp=_tempFloat; + MIBLEsensors[_slot].temp=_tempFloat; HM10.mode.awaiting = none; HM10.current_task_delay = 0; - MIBLEsensors.at(_slot).showedUp=255; // this sensor is real + MIBLEsensors[_slot].showedUp=255; // this sensor is real } _tempFloat=(float)LYWSD0x_HT.hum; if(_tempFloat<100){ - MIBLEsensors.at(_slot).hum = _tempFloat; + MIBLEsensors[_slot].hum = _tempFloat; DEBUG_SENSOR_LOG(PSTR("LYWSD0x: hum updated")); } } @@ -578,7 +580,7 @@ void HM10readHT_LY(char *_buf){ void HM10readHT_CGD1(char *_buf){ DEBUG_SENSOR_LOG(PSTR("%s: raw data: %x%x%x%x%x%x%x"),D_CMND_HM10,_buf[0],_buf[1],_buf[2],_buf[3],_buf[4],_buf[5],_buf[6]); - if(_buf[0]==0x4f && _buf[1]==0x4b && _buf[2]==0x2b) return; // "OK+" + if(_buf[0]==0x4f && _buf[1]==0x4b) return; // "OK" if(_buf[0] == 0){ if(_buf[1]==0 && _buf[2]==0 && _buf[3]==0 && _buf[4]==0) return; memcpy(&CGD1_HT,(void *)_buf,5); @@ -589,14 +591,14 @@ void HM10readHT_CGD1(char *_buf){ static float _tempFloat; _tempFloat=(float)(CGD1_HT.temp)/100.0f; if(_tempFloat<60){ - MIBLEsensors.at(_slot).temp=_tempFloat; + MIBLEsensors[_slot].temp=_tempFloat; HM10.mode.awaiting = none; HM10.current_task_delay = 0; - MIBLEsensors.at(_slot).showedUp=255; // this sensor is real + MIBLEsensors[_slot].showedUp=255; // this sensor is real } _tempFloat=(float)CGD1_HT.hum/100.0f; if(_tempFloat<100){ - MIBLEsensors.at(_slot).hum = _tempFloat; + MIBLEsensors[_slot].hum = _tempFloat; DEBUG_SENSOR_LOG(PSTR("CGD1: hum updated")); } } @@ -616,21 +618,21 @@ void HM10readHT_MJ_HT_V1(char *_buf){ static float _tempFloat; _tempFloat=(float)_temp/10.0f; if(_tempFloat<60){ - MIBLEsensors.at(_slot).temp=_tempFloat; + MIBLEsensors[_slot].temp=_tempFloat; HM10.mode.awaiting = none; HM10.current_task_delay = 0; - MIBLEsensors.at(_slot).showedUp=255; // this sensor is real + MIBLEsensors[_slot].showedUp=255; // this sensor is real } _tempFloat=(float)_hum/10.0f; if(_tempFloat<100){ - MIBLEsensors.at(_slot).hum = _tempFloat; + MIBLEsensors[_slot].hum = _tempFloat; DEBUG_SENSOR_LOG(PSTR("MJ_HT_V1: hum updated")); } } void HM10readTLMF(char *_buf){ DEBUG_SENSOR_LOG(PSTR("%s: raw data: %x%x%x%x%x%x%x"),D_CMND_HM10,_buf[0],_buf[1],_buf[2],_buf[3],_buf[4],_buf[5],_buf[6]); - if(_buf[0]==0x4f && _buf[1]==0x4b && _buf[2]==0x2b) return; // "OK+" + if(_buf[0]==0x4f && _buf[1]==0x4b) return; // "OK" if(_buf[0] != 0 || _buf[1] != 0){ // this will lose 0.0 degree, but it is not possible to measure a successful reading memcpy(&Flora_TLMF,(void *)_buf,10); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: T * 10: %u, L: %u, M: %u, F: %u"),D_CMND_HM10,Flora_TLMF.temp,Flora_TLMF.lux,Flora_TLMF.moist,Flora_TLMF.fert); @@ -640,16 +642,16 @@ void HM10readTLMF(char *_buf){ static float _tempFloat; _tempFloat=(float)(Flora_TLMF.temp)/10.0f; if(_tempFloat<60){ - MIBLEsensors.at(_slot).temp=_tempFloat; - MIBLEsensors.at(_slot).showedUp=255; // this sensor is real + MIBLEsensors[_slot].temp=_tempFloat; + MIBLEsensors[_slot].showedUp=255; // this sensor is real } - MIBLEsensors.at(_slot).lux = Flora_TLMF.lux; + MIBLEsensors[_slot].lux = Flora_TLMF.lux; _tempFloat=(float)Flora_TLMF.moist; if(_tempFloat<100){ - MIBLEsensors.at(_slot).moisture = _tempFloat; + MIBLEsensors[_slot].moisture = _tempFloat; } - MIBLEsensors.at(_slot).fertility = (float)Flora_TLMF.fert; + MIBLEsensors[_slot].fertility = (float)Flora_TLMF.fert; HM10.mode.awaiting = none; HM10.current_task_delay = 0; @@ -658,14 +660,14 @@ void HM10readTLMF(char *_buf){ bool HM10readBat(char *_buf){ DEBUG_SENSOR_LOG(PSTR("%s: raw data: %x%x%x%x%x%x%x"),D_CMND_HM10,_buf[0],_buf[1],_buf[2],_buf[3],_buf[4],_buf[5],_buf[6]); - if(_buf[0]==0x4f && _buf[1]==0x4b && _buf[2]==0x2b) return false; // "OK+" + if(_buf[0]==0x4f && _buf[1]==0x4b) return false; // "OK" if(_buf[0] != 0){ AddLog_P2(LOG_LEVEL_DEBUG,PSTR("%s: Battery: %u"),D_CMND_HM10,_buf[0]); uint32_t _slot = HM10.state.sensor; DEBUG_SENSOR_LOG(PSTR("MIBLE: Sensor slot: %u"), _slot); if(_buf[0]<101){ - MIBLEsensors.at(_slot).bat=_buf[0]; - MIBLEsensors.at(_slot).showedUp=255; // this sensor is real + MIBLEsensors[_slot].bat=_buf[0]; + MIBLEsensors[_slot].showedUp=255; // this sensor is real return true; } } @@ -780,7 +782,7 @@ void HM10_TaskEvery100ms(){ break; case TASK_HM10_CONN: char _con[20]; - sprintf_P(_con,"AT+CON%02x%02x%02x%02x%02x%02x",MIBLEsensors.at(HM10.state.sensor).serial[0],MIBLEsensors.at(HM10.state.sensor).serial[1],MIBLEsensors.at(HM10.state.sensor).serial[2],MIBLEsensors.at(HM10.state.sensor).serial[3],MIBLEsensors.at(HM10.state.sensor).serial[4],MIBLEsensors.at(HM10.state.sensor).serial[5]); + sprintf_P(_con,"AT+CON%02x%02x%02x%02x%02x%02x",MIBLEsensors[HM10.state.sensor].serial[0],MIBLEsensors[HM10.state.sensor].serial[1],MIBLEsensors[HM10.state.sensor].serial[2],MIBLEsensors[HM10.state.sensor].serial[3],MIBLEsensors[HM10.state.sensor].serial[4],MIBLEsensors[HM10.state.sensor].serial[5]); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: connect %s"),D_CMND_HM10, _con); HM10.current_task_delay = 2; // set task delay HM10_TaskReplaceInSlot(TASK_HM10_FEEDBACK,i); @@ -806,7 +808,8 @@ void HM10_TaskEvery100ms(){ case TASK_HM10_SUB_L3: AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: subscribe"),D_CMND_HM10); HM10.current_task_delay = 25; // set task delay - HM10_TaskReplaceInSlot(TASK_HM10_DELAY_SUB_LY,i); + HM10_TaskReplaceInSlot(TASK_HM10_FEEDBACK,i); + HM10.mode.awaiting = tempHumLY; runningTaskLoop = false; HM10Serial->write("AT+NOTIFY_ON0037"); break; @@ -821,7 +824,8 @@ void HM10_TaskEvery100ms(){ case TASK_HM10_SUB_L2: AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: subscribe"),D_CMND_HM10); HM10.current_task_delay = 25; // set task delay - HM10_TaskReplaceInSlot(TASK_HM10_DELAY_SUB_LY,i); + HM10.mode.awaiting = tempHumLY; + HM10_TaskReplaceInSlot(TASK_HM10_FEEDBACK,i); runningTaskLoop = false; HM10Serial->write("AT+NOTIFY_ON003C"); break; @@ -844,14 +848,6 @@ void HM10_TaskEvery100ms(){ HM10Serial->write(Rtc.time_timezone / 60); AddLog_P2(LOG_LEVEL_DEBUG,PSTR("%s Time-string: %x%x%x%x%x"),D_CMND_HM10, HM10.timebuf[0],HM10.timebuf[1],HM10.timebuf[2],HM10.timebuf[3],(Rtc.time_timezone /60)); break; - case TASK_HM10_READ_HT: - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: read handle 0036"),D_CMND_HM10); - HM10.current_task_delay = 0; // set task delay - HM10_TaskReplaceInSlot(TASK_HM10_FEEDBACK,i); - runningTaskLoop = false; - HM10Serial->write("AT+READDATA0036?"); - HM10.mode.awaiting = tempHumLY; - break; case TASK_HM10_READ_BT_L3: AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: read handle 003A"),D_CMND_HM10); HM10.current_task_delay = 2; // set task delay @@ -905,9 +901,9 @@ void HM10_TaskEvery100ms(){ case TASK_HM10_SUB_HT_CGD1: AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: subscribe 4b"),D_CMND_HM10); HM10.current_task_delay = 5; // set task delay - HM10_TaskReplaceInSlot(TASK_HM10_DELAY_SUB_CGD1,i); + HM10_TaskReplaceInSlot(TASK_HM10_FEEDBACK,i); runningTaskLoop = false; - HM10.mode.awaiting = none; + HM10.mode.awaiting = tempHumCGD1; HM10Serial->write("AT+NOTIFY_ON004b"); break; case TASK_HM10_UN_HT_CGD1: @@ -938,7 +934,6 @@ void HM10_TaskEvery100ms(){ HM10.current_task_delay = 10; // set task delay HM10_TaskReplaceInSlot(TASK_HM10_FEEDBACK,i); runningTaskLoop = false; - HM10.mode.awaiting = none; HM10Serial->write("AT+NOTIFY_ON000F"); HM10.mode.awaiting = tempHumMJ; break; @@ -949,22 +944,6 @@ void HM10_TaskEvery100ms(){ HM10_TASK_LIST[i][0] = TASK_HM10_DONE; // no feedback for reset runningTaskLoop = false; break; - case TASK_HM10_DELAY_SUB_LY: - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: start reading"),D_CMND_HM10); - HM10SerialHandleFeedback(); - HM10.current_task_delay = HM10_TASK_LIST[i+1][1];; // set task delay - HM10_TASK_LIST[i][0] = TASK_HM10_DONE; // no feedback for reset - HM10.mode.awaiting = tempHumLY; - runningTaskLoop = false; - break; - case TASK_HM10_DELAY_SUB_CGD1: - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: start reading"),D_CMND_HM10); - HM10SerialHandleFeedback(); - HM10.current_task_delay = HM10_TASK_LIST[i+1][1];; // set task delay - HM10_TASK_LIST[i][0] = TASK_HM10_DONE; // no feedback for reset - HM10.mode.awaiting = tempHumCGD1; - runningTaskLoop = false; - break; case TASK_HM10_STATUS_EVENT: AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: show status"),D_CMND_HM10); HM10StatusInfo(); @@ -1037,11 +1016,11 @@ void HM10EverySecond(bool restart){ HM10.state.sensor = _nextSensorSlot; _nextSensorSlot++; HM10.mode.pending_task = 1; - switch(MIBLEsensors.at(HM10.state.sensor).type){ + switch(MIBLEsensors[HM10.state.sensor].type){ case FLORA: HM10_Read_Flora(); break; - case MJ_HT_V1: + case MJ_HT_V1: case CGG1: HM10_Read_MJ_HT_V1(); break; case LYWSD02: @@ -1125,7 +1104,7 @@ bool HM10Cmd(void) { case CMND_HM10_TIME: if (XdrvMailbox.data_len > 0) { if(MIBLEsensors.size()>XdrvMailbox.payload){ - if(MIBLEsensors.at(XdrvMailbox.payload).type == LYWSD02){ + if(MIBLEsensors[XdrvMailbox.payload].type == LYWSD02){ HM10.state.sensor = XdrvMailbox.payload; HM10_Time_LYWSD02(); } @@ -1173,7 +1152,7 @@ bool HM10Cmd(void) { const char HTTP_HM10[] PROGMEM = "{s}HM10 V%u{m}%u%s / %u{e}"; const char HTTP_HM10_SERIAL[] PROGMEM = "{s}%s %s{m}%02x:%02x:%02x:%02x:%02x:%02x%{e}"; const char HTTP_BATTERY[] PROGMEM = "{s}%s" " Battery" "{m}%u%%{e}"; -const char HTTP_HM10_FLORA_DATA[] PROGMEM = "{s}%s" " Fertility" "{m}%sus/cm{e}"; +const char HTTP_HM10_FLORA_DATA[] PROGMEM = "{s}%s" " Fertility" "{m}%uus/cm{e}"; const char HTTP_HM10_HL[] PROGMEM = "{s}
{m}
{e}"; void HM10Show(bool json) @@ -1181,41 +1160,35 @@ void HM10Show(bool json) if (json) { for (uint32_t i = 0; i < MIBLEsensors.size(); i++) { char slave[33]; - sprintf_P(slave,"%s-%02x%02x%02x",kHM10SlaveType[MIBLEsensors.at(i).type-1],MIBLEsensors.at(i).serial[3],MIBLEsensors.at(i).serial[4],MIBLEsensors.at(i).serial[5]); + sprintf_P(slave,"%s-%02x%02x%02x",kHM10SlaveType[MIBLEsensors[i].type-1],MIBLEsensors[i].serial[3],MIBLEsensors[i].serial[4],MIBLEsensors[i].serial[5]); ResponseAppend_P(PSTR(",\"%s\":{"),slave); - if (MIBLEsensors.at(i).type==FLORA){ - if(!isnan(MIBLEsensors.at(i).temp)){ // this is the error code -> no temperature + if (MIBLEsensors[i].type==FLORA){ + if(!isnan(MIBLEsensors[i].temp)){ // this is the error code -> no temperature char temperature[FLOATSZ]; // all sensors have temperature - dtostrfd(MIBLEsensors.at(i).temp, Settings.flag2.temperature_resolution, temperature); + dtostrfd(MIBLEsensors[i].temp, Settings.flag2.temperature_resolution, temperature); ResponseAppend_P(PSTR("\"" D_JSON_TEMPERATURE "\":%s"), temperature); } else { ResponseAppend_P(PSTR("}")); continue; } - char lux[FLOATSZ]; - char moisture[FLOATSZ]; - char fertility[FLOATSZ]; - dtostrfd((float)MIBLEsensors.at(i).lux, 0, lux); - dtostrfd(MIBLEsensors.at(i).moisture, 0, moisture); - dtostrfd(MIBLEsensors.at(i).fertility, 0, fertility); - if(MIBLEsensors.at(i).lux!=0x0ffffff){ // this is the error code -> no temperature - ResponseAppend_P(PSTR(",\"" D_JSON_ILLUMINANCE "\":%s"), lux); + if(MIBLEsensors[i].lux!=0x0ffffff){ // this is the error code -> no lux + ResponseAppend_P(PSTR(",\"" D_JSON_ILLUMINANCE "\":%u"), MIBLEsensors[i].lux); } - if(!isnan(MIBLEsensors.at(i).moisture)){ // this is the error code -> no moisture - ResponseAppend_P(PSTR(",\"" D_JSON_MOISTURE "\":%s"), moisture); + if(!isnan(MIBLEsensors[i].moisture)){ + ResponseAppend_P(PSTR(",\"" D_JSON_MOISTURE "\":%d"), MIBLEsensors[i].moisture); } - if(!isnan(MIBLEsensors.at(i).fertility)){ // this is the error code -> no fertility - ResponseAppend_P(PSTR(",\"Fertility\":%s"), fertility); + if(!isnan(MIBLEsensors[i].fertility)){ + ResponseAppend_P(PSTR(",\"Fertility\":%d"), MIBLEsensors[i].fertility); } } - if (MIBLEsensors.at(i).type>FLORA){ - if(!isnan(MIBLEsensors.at(i).hum) && !isnan(MIBLEsensors.at(i).temp)){ // this is the error code -> no humidity nor temp - ResponseAppendTHD(MIBLEsensors.at(i).temp, MIBLEsensors.at(i).hum); + if (MIBLEsensors[i].type>FLORA){ + if(!isnan(MIBLEsensors[i].hum) && !isnan(MIBLEsensors[i].temp)){ + ResponseAppendTHD(MIBLEsensors[i].temp, MIBLEsensors[i].hum); } } - if(MIBLEsensors.at(i).bat!=0x00){ // this is the error code -> no battery - ResponseAppend_P(PSTR(",\"Battery\":%u"), MIBLEsensors.at(i).bat); + if(MIBLEsensors[i].bat!=0x00){ // this is the error code -> no battery + ResponseAppend_P(PSTR(",\"Battery\":%u"), MIBLEsensors[i].bat); } ResponseAppend_P(PSTR("}")); } @@ -1237,32 +1210,30 @@ void HM10Show(bool json) WSContentSend_PD(HTTP_HM10, HM10.firmware, i+1,stemp,MIBLEsensors.size()); for (i; i no valid value - WSContentSend_PD(HTTP_SNS_ILLUMINANCE, kHM10SlaveType[MIBLEsensors.at(i).type-1], MIBLEsensors.at(i).lux); + if(MIBLEsensors[i].lux!=0x00ffffff){ // this is the error code -> no valid value + WSContentSend_PD(HTTP_SNS_ILLUMINANCE, kHM10SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].lux); } - if(!isnan(MIBLEsensors.at(i).moisture)){ // this is the error code -> no valid value - WSContentSend_PD(HTTP_SNS_MOISTURE, kHM10SlaveType[MIBLEsensors.at(i).type-1], MIBLEsensors.at(i).moisture); + if(!isnan(MIBLEsensors[i].moisture)){ + WSContentSend_PD(HTTP_SNS_MOISTURE, kHM10SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].moisture); } - if(!isnan(MIBLEsensors.at(i).fertility)){ // this is the error code -> no valid value - char fertility[FLOATSZ]; - dtostrfd(MIBLEsensors.at(i).fertility, 0, fertility); - WSContentSend_PD(HTTP_HM10_FLORA_DATA, kHM10SlaveType[MIBLEsensors.at(i).type-1], fertility); + if(!isnan(MIBLEsensors[i].fertility)){ + WSContentSend_PD(HTTP_HM10_FLORA_DATA, kHM10SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].fertility); } } - if (MIBLEsensors.at(i).type>FLORA){ // everything "above" Flora - if(!isnan(MIBLEsensors.at(i).hum) && !isnan(MIBLEsensors.at(i).temp)){ - WSContentSend_THD(kHM10SlaveType[MIBLEsensors.at(i).type-1], MIBLEsensors.at(i).temp, MIBLEsensors.at(i).hum); + if (MIBLEsensors[i].type>FLORA){ // everything "above" Flora + if(!isnan(MIBLEsensors[i].hum) && !isnan(MIBLEsensors[i].temp)){ + WSContentSend_THD(kHM10SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].temp, MIBLEsensors[i].hum); } } - if(MIBLEsensors.at(i).bat!=0x00){ - WSContentSend_PD(HTTP_BATTERY, kHM10SlaveType[MIBLEsensors.at(i).type-1], MIBLEsensors.at(i).bat); + if(MIBLEsensors[i].bat!=0x00){ + WSContentSend_PD(HTTP_BATTERY, kHM10SlaveType[MIBLEsensors[i].type-1], MIBLEsensors[i].bat); } } _counter++; From 0c24651ed0cdee4a1433eddb2c65451312b9de14 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 12 Apr 2020 12:35:58 +0200 Subject: [PATCH 20/22] Add interval to PMS5003 sensor Add interval to PMS5003 sensor to extend lifetime (#8128) --- RELEASENOTES.md | 2 + tasmota/CHANGELOG.md | 3 +- tasmota/settings.h | 12 ++-- tasmota/tasmota_template.h | 10 +-- tasmota/xsns_18_pms5003.ino | 120 ++++++++++++++---------------------- 5 files changed, 62 insertions(+), 85 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 053b8bfd4..4686a392d 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -66,6 +66,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add Zigbee command ``ZbRestore`` to restore device configuration dumped with ``ZbStatus 2`` - Add Zigbee command ``ZbUnbind`` - Add Zigbee command ``ZbBindState`` and ``manuf``attribute +- Add Zigbee command ``ZbConfig`` and configuration in Settings - Add commands ``CounterDebounceLow`` and ``CounterDebounceHigh`` to control debouncing (#8021) - Add commands ``NrfPage``, ``NrfIgnore``, ``NrfScan`` and ``NrfBeacon`` to NRF24 Bluetooth driver (#8075) - Add command ``SetOption41 `` to force sending gratuitous ARP every seconds @@ -86,3 +87,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add console command history (#7483, #8015) - Add quick wifi reconnect using saved AP parameters when ``SetOption56 0`` (#3189) - Add more accuracy to GPS NTP server (#8088) +- Add interval to PMS5003 sensor to extend lifetime (#8128) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 5f8c6339c..3af55f17e 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -10,6 +10,7 @@ - Fix Zigbee crash with Occupancy sensor (#8089) - Add support for longer template names - Add Zigbee command ``ZbBindState`` and ``manuf``attribute +- Add Zigbee command ``ZbConfig`` and configuration in Settings - Add commands ``CounterDebounceLow`` and ``CounterDebounceHigh`` to control debouncing (#8021) - Add commands ``NrfPage``, ``NrfIgnore``, ``NrfScan`` and ``NrfBeacon`` to NRF24 Bluetooth driver (#8075) - Add command ``SetOption90 1`` to disable non-json MQTT messages (#8044) @@ -25,7 +26,7 @@ - Add support for an iAQ sensor (#8107) - Add support for Seven Segment display using HT16K33 (#8116) - Add support for AS3935 Lightning Sensor by device111 (#8130) -- Add Zigbee command ``ZbConfig`` and configuration in Settings +- Add interval to PMS5003 sensor to extend lifetime (#8128) ### 8.2.0.2 20200328 diff --git a/tasmota/settings.h b/tasmota/settings.h index a9b6d0bc6..0014cac60 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -213,9 +213,9 @@ typedef union { typedef union { uint8_t data; - struct { + struct { uint8_t nf_autotune : 1; // Autotune the NF Noise Level - uint8_t dist_autotune : 1; // Autotune Disturber on/off + uint8_t dist_autotune : 1; // Autotune Disturber on/off uint8_t nf_autotune_both : 1; // Autotune over both Areas: INDOORS/OUDOORS uint8_t mqtt_only_Light_Event : 1; // mqtt only if lightning Irq uint8_t spare4 : 1; @@ -227,9 +227,9 @@ typedef union { typedef union { uint16_t data; - struct { + struct { uint16_t nf_autotune_time : 4; // NF Noise Autotune Time - uint16_t dist_autotune_time : 4; // Disturber Autotune Time + uint16_t dist_autotune_time : 4; // Disturber Autotune Time uint16_t nf_autotune_min : 4; // Min Stages uint16_t spare3 : 4; }; @@ -505,9 +505,9 @@ struct PACKED SYSCFG { uint16_t zb_pan_id; // F30 uint8_t zb_channel; // F32 uint8_t zb_free_byte; // F33 - uint16_t pms_wake_interval; + uint16_t pms_wake_interval; // F34 - uint8_t free_f18[130]; // F34 + uint8_t free_f36[130]; // F36 uint16_t pulse_counter_debounce_low; // FB8 uint16_t pulse_counter_debounce_high; // FBA diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index ffb520013..6ab153508 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -93,7 +93,7 @@ enum UserSelectablePins { GPIO_SPI_CS, // SPI Chip Select GPIO_SPI_DC, // SPI Data Direction GPIO_BACKLIGHT, // Display backlight control - GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface + GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface GPIO_SBR_TX, // Serial Bridge Serial interface GPIO_SBR_RX, // Serial Bridge Serial interface @@ -579,12 +579,12 @@ const uint8_t kGpioNiceList[] PROGMEM = { GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface #endif #ifdef USE_HPMA - GPIO_HPMA_TX, // Honeywell HPMA115S0 Serial interface - GPIO_HPMA_RX, // Honeywell HPMA115S0 Serial interface + GPIO_HPMA_TX, // Honeywell HPMA115S0 Serial interface + GPIO_HPMA_RX, // Honeywell HPMA115S0 Serial interface #endif #ifdef USE_PMS5003 - GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface - GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface + GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface + GPIO_PMS5003_RX, // Plantower PMS5003 Serial interface #endif #if defined(USE_TX20_WIND_SENSOR) || defined(USE_TX23_WIND_SENSOR) GPIO_TX2X_TXD_BLACK, // TX20/TX23 Transmission Pin diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 2ad18ba35..022216a4a 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -33,7 +33,7 @@ #include #ifndef WARMUP_PERIOD -#define WARMUP_PERIOD 30 // Turn on PMSX003 XX-seconds before read in passive mode +#define WARMUP_PERIOD 30 // Turn on PMSX003 XX-seconds before read in passive mode #endif #ifndef MIN_INTERVAL_PERIOD @@ -42,14 +42,13 @@ TasmotaSerial *PmsSerial; -uint8_t pms_type = 1; -uint8_t pms_valid = 0; -uint16_t pms_time = 0; -uint8_t wake_mode = 1; -uint8_t pms_ready = 1; - -const char ACTIVE_MODE[] = "Active Mode"; -const char PASSIVE_MODE[] = "Passive Mode"; +struct PMS5003 { + uint16_t time = 0; + uint8_t type = 1; + uint8_t valid = 0; + uint8_t wake_mode = 1; + uint8_t ready = 1; +} Pms; enum PmsCommands { @@ -155,7 +154,7 @@ bool PmsReadData(void) #else memcpy((void *)&pms_data, (void *)buffer_u16, 30); #endif // PMS_MODEL_PMS3003 - pms_valid = 10; + Pms.valid = 10; return true; } @@ -164,21 +163,20 @@ bool PmsReadData(void) * Command Sensor18 * * Warmup time for sensor is 30 seconds, therfore setting interval time to less than 60 - * seconds doesn't really make sense. - * + * seconds doesn't really make sense. + * * 0 - 59 - Active Mode (continuous sensor readings) * 60 .. 65535 - Passive Mode (read sensor every x seconds) \*********************************************************************************************/ bool PmsCommandSensor(void) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) - { + if ((pin[GPIO_PMS5003_TX] < 99) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) { if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) { // Set Active Mode if interval is less than 60 seconds Settings.pms_wake_interval = 0; - wake_mode = 1; - pms_ready = 1; + Pms.wake_mode = 1; + Pms.ready = 1; PmsSendCmd(CMD_MODE_ACTIVE); PmsSendCmd(CMD_WAKEUP); } else { @@ -186,16 +184,10 @@ bool PmsCommandSensor(void) Settings.pms_wake_interval = XdrvMailbox.payload; PmsSendCmd(CMD_MODE_PASSIVE); PmsSendCmd(CMD_SLEEP); - wake_mode = 0; - pms_ready = 0; + Pms.wake_mode = 0; + Pms.ready = 0; } } - - if (pin[GPIO_PMS5003_TX] >= 99) - { - // setting interval not supported if TX pin not connected - Settings.pms_wake_interval = 0; - } Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.pms_wake_interval); @@ -206,46 +198,36 @@ bool PmsCommandSensor(void) void PmsSecond(void) // Every second { - if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) - { + if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) { // Passive Mode - pms_time++; - if ((Settings.pms_wake_interval - pms_time <= WARMUP_PERIOD) && !wake_mode) - { + Pms.time++; + if ((Settings.pms_wake_interval - Pms.time <= WARMUP_PERIOD) && !Pms.wake_mode) { // wakeup sensor WARMUP_PERIOD before read interval - wake_mode = 1; + Pms.wake_mode = 1; PmsSendCmd(CMD_WAKEUP); } - if (pms_time >= Settings.pms_wake_interval) - { + if (Pms.time >= Settings.pms_wake_interval) { // sensor is awake and warmed up, set up for reading PmsSendCmd(CMD_READ_DATA); - pms_ready = 1; - pms_time = 0; + Pms.ready = 1; + Pms.time = 0; } - } + } - if (pms_ready) - { - if (PmsReadData()) - { - pms_valid = 10; - if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) - { + if (Pms.ready) { + if (PmsReadData()) { + Pms.valid = 10; + if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) { PmsSendCmd(CMD_SLEEP); - wake_mode = 0; - pms_ready = 0; + Pms.wake_mode = 0; + Pms.ready = 0; } - } - else - { - if (pms_valid) - { - pms_valid--; - if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) - { + } else { + if (Pms.valid) { + Pms.valid--; + if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) { PmsSendCmd(CMD_READ_DATA); - pms_ready = 1; + Pms.ready = 1; } } } @@ -256,25 +238,18 @@ void PmsSecond(void) // Every second void PmsInit(void) { - pms_type = 0; - if ((pin[GPIO_PMS5003_RX] < 99) && (pin[GPIO_PMS5003_TX] < 99)) - { - PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], pin[GPIO_PMS5003_TX], 1); + Pms.type = 0; + if (pin[GPIO_PMS5003_RX] < 99) { + PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], (pin[GPIO_PMS5003_TX] < 99) ? pin[GPIO_PMS5003_TX] : -1, 1); if (PmsSerial->begin(9600)) { if (PmsSerial->hardwareSerial()) { ClaimSerial(); } - pms_type = 1; - } - } - else if ((pin[GPIO_PMS5003_RX] < 99)) - { - PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], -1, 1); - if (PmsSerial->begin(9600)) - { - if (PmsSerial->hardwareSerial()) - { - ClaimSerial(); + + if (99 == pin[GPIO_PMS5003_TX]) { // setting interval not supported if TX pin not connected + Settings.pms_wake_interval = 0; + Pms.ready = 1; } - pms_type = 1; + + Pms.type = 1; } } } @@ -307,7 +282,7 @@ const char HTTP_PMS5003_SNS[] PROGMEM = void PmsShow(bool json) { - if (pms_valid) { + if (Pms.valid) { if (json) { #ifdef PMS_MODEL_PMS3003 ResponseAppend_P(PSTR(",\"PMS3003\":{\"CF1\":%d,\"CF2.5\":%d,\"CF10\":%d,\"PM1\":%d,\"PM2.5\":%d,\"PM10\":%d}"), @@ -352,7 +327,7 @@ bool Xsns18(uint8_t function) { bool result = false; - if (pms_type) { + if (Pms.type) { switch (function) { case FUNC_INIT: PmsInit(); @@ -361,8 +336,7 @@ bool Xsns18(uint8_t function) PmsSecond(); break; case FUNC_COMMAND_SENSOR: - if (XSNS_18 == XdrvMailbox.index) - { + if (XSNS_18 == XdrvMailbox.index) { result = PmsCommandSensor(); } break; From b79660726420bdbafd8c375f449464ff49b4c5ae Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Sun, 12 Apr 2020 13:22:23 +0200 Subject: [PATCH 21/22] update for esp32 --- lib/Xlatb_RA8876-gemu-1.0/RA8876.cpp | 6 +++++- tasmota/xdrv_10_scripter.ino | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Xlatb_RA8876-gemu-1.0/RA8876.cpp b/lib/Xlatb_RA8876-gemu-1.0/RA8876.cpp index a3c73f3fb..850b2bb8a 100644 --- a/lib/Xlatb_RA8876-gemu-1.0/RA8876.cpp +++ b/lib/Xlatb_RA8876-gemu-1.0/RA8876.cpp @@ -66,9 +66,13 @@ RA8876::RA8876(int8_t cs,int8_t mosi,int8_t miso,int8_t sclk,int8_t bp) : Render //#define RA8876_CS_LOW digitalWrite(m_csPin, LOW) //#define RA8876_CS_HIGH digitalWrite(m_csPin, HIGH) +#ifdef ESP8266 #define RA8876_CS_LOW GPOC=(1<. */ + #ifdef USE_SCRIPT #ifndef USE_RULES /*********************************************************************************************\ @@ -60,6 +61,10 @@ keywords if then else endif, or, and are better readable for beginners (others m #define SCRIPT_MAXPERM (PMEM_SIZE)-4/sizeof(float) #define MAX_SCRIPT_SIZE MAX_RULE_SIZE*MAX_RULE_SETS + +uint32_t EncodeLightId(uint8_t relay_id); +uint32_t DecodeLightId(uint32_t hue_id); + // offsets epoch readings by 1.1.2019 00:00:00 to fit into float with second resolution #define EPOCH_OFFSET 1546300800 @@ -2028,6 +2033,7 @@ char *getop(char *lp, uint8_t *operand) { } +#ifdef ESP8266 #if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) // All version before core 2.4.2 // https://github.com/esp8266/Arduino/issues/2557 @@ -2050,6 +2056,12 @@ uint16_t GetStack(void) { return (4 * (sp - g_pcont->stack)); } #endif +#else +uint16_t GetStack(void) { + register uint8_t *sp asm("a1"); + return (sp - pxTaskGetStackStart(NULL)); +} +#endif char *GetStringResult(char *lp,uint8_t lastop,char *cp,JsonObject *jo) { uint8_t operand=0; From 42d82fdc979a46ade3784f5a8cc37ba564f95a4b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 12 Apr 2020 14:54:06 +0200 Subject: [PATCH 22/22] Fix PMS5003 input range --- RELEASENOTES.md | 2 +- tasmota/CHANGELOG.md | 2 +- tasmota/xsns_18_pms5003.ino | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 4686a392d..640064399 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -74,6 +74,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add command ``SetOption91 1`` to enable fading at startup / power on - Add command ``Sensor10 0/1/2`` to control BH1750 resolution - 0 = High (default), 1 = High2, 2 = Low (#8016) - Add command ``Sensor10 31..254`` to control BH1750 measurement time which defaults to 69 (#8016) +- Add command ``Sensor18 0..32000`` to control PMS5003 sensor interval to extend lifetime by Gene Ruebsamen (#8128) - Add command ``DevGroupName`` to specify up to four Device Group Names (#8087) - Add command ``DevGroupSend`` to send an update to a Device Group (#8093) - Add command ``Ping`` (#7176) @@ -87,4 +88,3 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add console command history (#7483, #8015) - Add quick wifi reconnect using saved AP parameters when ``SetOption56 0`` (#3189) - Add more accuracy to GPS NTP server (#8088) -- Add interval to PMS5003 sensor to extend lifetime (#8128) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 3af55f17e..0bc6a5c85 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -16,6 +16,7 @@ - Add command ``SetOption90 1`` to disable non-json MQTT messages (#8044) - Add command ``Sensor10 0/1/2`` to control BH1750 resolution - 0 = High (default), 1 = High2, 2 = Low (#8016) - Add command ``Sensor10 31..254`` to control BH1750 measurement time which defaults to 69 (#8016) +- Add command ``Sensor18 0..32000`` to control PMS5003 sensor interval to extend lifetime by Gene Ruebsamen (#8128) - Add command ``SetOption91 1`` to enable fading at startup / power on - Add command ``SetOption41 `` to force sending gratuitous ARP every seconds - Add command ``DevGroupName`` to specify up to four Device Group Names (#8087) @@ -26,7 +27,6 @@ - Add support for an iAQ sensor (#8107) - Add support for Seven Segment display using HT16K33 (#8116) - Add support for AS3935 Lightning Sensor by device111 (#8130) -- Add interval to PMS5003 sensor to extend lifetime (#8128) ### 8.2.0.2 20200328 diff --git a/tasmota/xsns_18_pms5003.ino b/tasmota/xsns_18_pms5003.ino index 022216a4a..525012f5a 100644 --- a/tasmota/xsns_18_pms5003.ino +++ b/tasmota/xsns_18_pms5003.ino @@ -171,7 +171,7 @@ bool PmsReadData(void) bool PmsCommandSensor(void) { - if ((pin[GPIO_PMS5003_TX] < 99) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) { + if ((pin[GPIO_PMS5003_TX] < 99) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32001)) { if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) { // Set Active Mode if interval is less than 60 seconds Settings.pms_wake_interval = 0;