From 970f4652f5dd11c96b91a9dd35c63dcd710d01e2 Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Thu, 8 Apr 2021 18:00:14 +0100 Subject: [PATCH 1/8] Update to iBeacon to use only MAC to recognise different beacons - this brings it into line with common use. A further update would be nice to display major & minor in the web ui, not included here. --- tasmota/xsns_52_esp32_ibeacon_ble.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasmota/xsns_52_esp32_ibeacon_ble.ino b/tasmota/xsns_52_esp32_ibeacon_ble.ino index 432455924..4ead16697 100644 --- a/tasmota/xsns_52_esp32_ibeacon_ble.ino +++ b/tasmota/xsns_52_esp32_ibeacon_ble.ino @@ -337,7 +337,7 @@ uint32_t ibeacon_add(struct IBEACON *ib) { if (!strncmp(ib->MAC,"FFFF",4) || strncmp(ib->FACID,"00000000",8)) { for (uint32_t cnt=0;cntUID,PSTR("00000000000000000000000000000000"),32)) { +// if (!strncmp_P(ib->UID,PSTR("00000000000000000000000000000000"),32)) { if (!strncmp(ibeacons[cnt].MAC,ib->MAC,12)) { // exists strncpy(ibeacons[cnt].NAME,ib->NAME,sizeof(ibeacons[cnt].NAME)); @@ -350,7 +350,7 @@ uint32_t ibeacon_add(struct IBEACON *ib) { ibeacons[cnt].count++; return 2; } - } else { +/* } else { if (!strncmp(ibeacons[cnt].UID,ib->UID,32)) { // exists strncpy(ibeacons[cnt].NAME,ib->NAME,sizeof(ibeacons[cnt].NAME)); @@ -363,7 +363,7 @@ uint32_t ibeacon_add(struct IBEACON *ib) { ibeacons[cnt].count++; return 2; } - } + }*/ } } for (uint32_t cnt=0;cnt Date: Thu, 8 Apr 2021 19:08:15 +0100 Subject: [PATCH 2/8] remove endian-swap on major & minor for iBeacon - in theroy to match HM10 implementation? --- tasmota/xsns_52_esp32_ibeacon_ble.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasmota/xsns_52_esp32_ibeacon_ble.ino b/tasmota/xsns_52_esp32_ibeacon_ble.ino index 4ead16697..464eefe88 100644 --- a/tasmota/xsns_52_esp32_ibeacon_ble.ino +++ b/tasmota/xsns_52_esp32_ibeacon_ble.ino @@ -233,8 +233,10 @@ int advertismentCallback(BLE_ESP32::ble_advertisment_t *pStruct) memcpy(UUID,oBeacon.getProximityUUID().getNative()->u128.value,16); ESP32BLE_ReverseStr(UUID,16); - uint16_t Major = ENDIAN_CHANGE_U16(oBeacon.getMajor()); - uint16_t Minor = ENDIAN_CHANGE_U16(oBeacon.getMinor()); +// uint16_t Major = ENDIAN_CHANGE_U16(oBeacon.getMajor()); +// uint16_t Minor = ENDIAN_CHANGE_U16(oBeacon.getMinor()); + uint16_t Major = oBeacon.getMajor(); + uint16_t Minor = oBeacon.getMinor(); uint8_t PWR = oBeacon.getSignalPower(); DumpHex((const unsigned char*)&UUID,16,ib.UID); From e9e0d3536871d22a9a69eb8644f5dd47adb700f4 Mon Sep 17 00:00:00 2001 From: Barbudor Date: Thu, 8 Apr 2021 22:59:44 +0200 Subject: [PATCH 3/8] command EnergyConfig --- tasmota/xdrv_03_energy.ino | 14 +++++++++++--- tasmota/xnrg_20_dummy.ino | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tasmota/xdrv_03_energy.ino b/tasmota/xdrv_03_energy.ino index c88995590..f09233069 100644 --- a/tasmota/xdrv_03_energy.ino +++ b/tasmota/xdrv_03_energy.ino @@ -43,7 +43,7 @@ enum EnergyCommands { CMND_POWERCAL, CMND_VOLTAGECAL, CMND_CURRENTCAL, CMND_FREQUENCYCAL, - CMND_POWERSET, CMND_VOLTAGESET, CMND_CURRENTSET, CMND_FREQUENCYSET, CMND_MODULEADDRESS }; + CMND_POWERSET, CMND_VOLTAGESET, CMND_CURRENTSET, CMND_FREQUENCYSET, CMND_MODULEADDRESS, CMND_NRGCONFIG }; const char kEnergyCommands[] PROGMEM = "|" // No prefix D_CMND_POWERCAL "|" D_CMND_VOLTAGECAL "|" D_CMND_CURRENTCAL "|" D_CMND_FREQUENCYCAL "|" @@ -56,7 +56,7 @@ const char kEnergyCommands[] PROGMEM = "|" // No prefix D_CMND_SAFEPOWER "|" D_CMND_SAFEPOWERHOLD "|" D_CMND_SAFEPOWERWINDOW "|" #endif // USE_ENERGY_POWER_LIMIT #endif // USE_ENERGY_MARGIN_DETECTION - D_CMND_ENERGYRESET "|" D_CMND_TARIFF ; + D_CMND_ENERGYRESET "|" D_CMND_TARIFF "|EnergyConfig"; void (* const EnergyCommand[])(void) PROGMEM = { &CmndPowerCal, &CmndVoltageCal, &CmndCurrentCal, &CmndFrequencyCal, @@ -69,7 +69,7 @@ void (* const EnergyCommand[])(void) PROGMEM = { &CmndSafePower, &CmndSafePowerHold, &CmndSafePowerWindow, #endif // USE_ENERGY_POWER_LIMIT #endif // USE_ENERGY_MARGIN_DETECTION - &CmndEnergyReset, &CmndTariff }; + &CmndEnergyReset, &CmndTariff, &CmndEnergyConfig }; const char kEnergyPhases[] PROGMEM = "|%s / %s|%s / %s / %s||[%s,%s]|[%s,%s,%s]"; @@ -761,6 +761,14 @@ void CmndModuleAddress(void) { } } +void CmndEnergyConfig(void) { + AddLog_P(LOG_LEVEL_DEBUG, PSTR("NRG: xdrv_03 index:%d"), XdrvMailbox.index); + Energy.command_code = CMND_NRGCONFIG; + if (XnrgCall(FUNC_COMMAND)) { + ResponseCmndDone(); + } +} + #ifdef USE_ENERGY_MARGIN_DETECTION void CmndPowerDelta(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= ENERGY_MAX_PHASES)) { diff --git a/tasmota/xnrg_20_dummy.ino b/tasmota/xnrg_20_dummy.ino index 07b4a22ec..059a4ab1f 100644 --- a/tasmota/xnrg_20_dummy.ino +++ b/tasmota/xnrg_20_dummy.ino @@ -99,6 +99,9 @@ bool NrgDummyCommand(void) { } } } + else if (CMND_NRGCONFIG == Energy.command_code) { + AddLog_P(LOG_LEVEL_DEBUG, PSTR("NRG: Config payload:%d, data:'%s'"), XdrvMailbox.payload, XdrvMailbox.data ? XdrvMailbox.data : "null" ); + } else serviced = false; // Unknown command return serviced; From 740e4392ef9228127de9d8c78628e16bdc3bff91 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 9 Apr 2021 09:49:33 +0200 Subject: [PATCH 4/8] Add command EnergyConfig for future use --- tasmota/i18n.h | 1 + tasmota/xdrv_03_energy.ino | 13 ++++++------- tasmota/xnrg_20_dummy.ino | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 0fdcb4473..9799fbe90 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -421,6 +421,7 @@ #define D_CMND_VOLTAGESET "VoltageSet" #define D_CMND_CURRENTSET "CurrentSet" #define D_CMND_FREQUENCYSET "FrequencySet" +#define D_CMND_ENERGYCONFIG "EnergyConfig" #define D_CMND_MAXPOWER "MaxPower" #define D_CMND_MAXPOWERHOLD "MaxPowerHold" #define D_CMND_MAXPOWERWINDOW "MaxPowerWindow" diff --git a/tasmota/xdrv_03_energy.ino b/tasmota/xdrv_03_energy.ino index f09233069..d15e873cd 100644 --- a/tasmota/xdrv_03_energy.ino +++ b/tasmota/xdrv_03_energy.ino @@ -43,11 +43,11 @@ enum EnergyCommands { CMND_POWERCAL, CMND_VOLTAGECAL, CMND_CURRENTCAL, CMND_FREQUENCYCAL, - CMND_POWERSET, CMND_VOLTAGESET, CMND_CURRENTSET, CMND_FREQUENCYSET, CMND_MODULEADDRESS, CMND_NRGCONFIG }; + CMND_POWERSET, CMND_VOLTAGESET, CMND_CURRENTSET, CMND_FREQUENCYSET, CMND_MODULEADDRESS, CMND_ENERGYCONFIG }; const char kEnergyCommands[] PROGMEM = "|" // No prefix D_CMND_POWERCAL "|" D_CMND_VOLTAGECAL "|" D_CMND_CURRENTCAL "|" D_CMND_FREQUENCYCAL "|" - D_CMND_POWERSET "|" D_CMND_VOLTAGESET "|" D_CMND_CURRENTSET "|" D_CMND_FREQUENCYSET "|" D_CMND_MODULEADDRESS "|" + D_CMND_POWERSET "|" D_CMND_VOLTAGESET "|" D_CMND_CURRENTSET "|" D_CMND_FREQUENCYSET "|" D_CMND_MODULEADDRESS "|" D_CMND_ENERGYCONFIG "|" #ifdef USE_ENERGY_MARGIN_DETECTION D_CMND_POWERDELTA "|" D_CMND_POWERLOW "|" D_CMND_POWERHIGH "|" D_CMND_VOLTAGELOW "|" D_CMND_VOLTAGEHIGH "|" D_CMND_CURRENTLOW "|" D_CMND_CURRENTHIGH "|" #ifdef USE_ENERGY_POWER_LIMIT @@ -56,11 +56,11 @@ const char kEnergyCommands[] PROGMEM = "|" // No prefix D_CMND_SAFEPOWER "|" D_CMND_SAFEPOWERHOLD "|" D_CMND_SAFEPOWERWINDOW "|" #endif // USE_ENERGY_POWER_LIMIT #endif // USE_ENERGY_MARGIN_DETECTION - D_CMND_ENERGYRESET "|" D_CMND_TARIFF "|EnergyConfig"; + D_CMND_ENERGYRESET "|" D_CMND_TARIFF; void (* const EnergyCommand[])(void) PROGMEM = { &CmndPowerCal, &CmndVoltageCal, &CmndCurrentCal, &CmndFrequencyCal, - &CmndPowerSet, &CmndVoltageSet, &CmndCurrentSet, &CmndFrequencySet, &CmndModuleAddress, + &CmndPowerSet, &CmndVoltageSet, &CmndCurrentSet, &CmndFrequencySet, &CmndModuleAddress, &CmndEnergyConfig, #ifdef USE_ENERGY_MARGIN_DETECTION &CmndPowerDelta, &CmndPowerLow, &CmndPowerHigh, &CmndVoltageLow, &CmndVoltageHigh, &CmndCurrentLow, &CmndCurrentHigh, #ifdef USE_ENERGY_POWER_LIMIT @@ -69,7 +69,7 @@ void (* const EnergyCommand[])(void) PROGMEM = { &CmndSafePower, &CmndSafePowerHold, &CmndSafePowerWindow, #endif // USE_ENERGY_POWER_LIMIT #endif // USE_ENERGY_MARGIN_DETECTION - &CmndEnergyReset, &CmndTariff, &CmndEnergyConfig }; + &CmndEnergyReset, &CmndTariff}; const char kEnergyPhases[] PROGMEM = "|%s / %s|%s / %s / %s||[%s,%s]|[%s,%s,%s]"; @@ -762,8 +762,7 @@ void CmndModuleAddress(void) { } void CmndEnergyConfig(void) { - AddLog_P(LOG_LEVEL_DEBUG, PSTR("NRG: xdrv_03 index:%d"), XdrvMailbox.index); - Energy.command_code = CMND_NRGCONFIG; + Energy.command_code = CMND_ENERGYCONFIG; if (XnrgCall(FUNC_COMMAND)) { ResponseCmndDone(); } diff --git a/tasmota/xnrg_20_dummy.ino b/tasmota/xnrg_20_dummy.ino index 059a4ab1f..0c70d6998 100644 --- a/tasmota/xnrg_20_dummy.ino +++ b/tasmota/xnrg_20_dummy.ino @@ -99,8 +99,9 @@ bool NrgDummyCommand(void) { } } } - else if (CMND_NRGCONFIG == Energy.command_code) { - AddLog_P(LOG_LEVEL_DEBUG, PSTR("NRG: Config payload:%d, data:'%s'"), XdrvMailbox.payload, XdrvMailbox.data ? XdrvMailbox.data : "null" ); + else if (CMND_ENERGYCONFIG == Energy.command_code) { + AddLog_P(LOG_LEVEL_DEBUG, PSTR("NRG: Config index %d, payload %d, data '%s'"), + XdrvMailbox.index, XdrvMailbox.payload, XdrvMailbox.data ? XdrvMailbox.data : "null" ); } else serviced = false; // Unknown command From 0650744ac27108931a070918f08173d71ddfd68d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 9 Apr 2021 10:04:37 +0200 Subject: [PATCH 5/8] Remove overtemp detection on external energy monitoring devices Removed overtemp detection on external energy monitoring devices (#11628) --- CHANGELOG.md | 1 + RELEASENOTES.md | 1 + tasmota/xdrv_03_energy.ino | 3 ++- tasmota/xnrg_01_hlw8012.ino | 3 ++- tasmota/xnrg_02_cse7766.ino | 3 ++- tasmota/xnrg_04_mcp39f501.ino | 1 + tasmota/xnrg_07_ade7953.ino | 1 + tasmota/xnrg_14_bl0940.ino | 1 + tasmota/xnrg_19_cse7761.ino | 1 + tasmota/xnrg_20_dummy.ino | 2 ++ 10 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5020417d5..543d6f1f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ All notable changes to this project will be documented in this file. - Limit number of relay/button columns in GUI to 8 (#11546) - ADC range result from int to float using command ``FreqRes`` for decimal resolution selection (#11545) - Teleinfo, if raw mode selected also return telemety values in SENSOR data +- Removed overtemp detection on external energy monitoring devices (#11628) ### Fixed - HC-SR04 on ESP32 release serial interface if not used (#11507) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 4a490aa04..713e7fb19 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -115,6 +115,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota - DeepSleep announcement topic [#11223](https://github.com/arendst/Tasmota/issues/11223) - Limit number of relay/button columns in GUI to 8 [#11546](https://github.com/arendst/Tasmota/issues/11546) - ADC range result from int to float using command ``FreqRes`` for decimal resolution selection [#11545](https://github.com/arendst/Tasmota/issues/11545) +- Removed overtemp detection on external energy monitoring devices [#11628](https://github.com/arendst/Tasmota/issues/11628) ### Fixed - PN532 on ESP32 Serial flush both Tx and Rx buffers [#10910](https://github.com/arendst/Tasmota/issues/10910) diff --git a/tasmota/xdrv_03_energy.ino b/tasmota/xdrv_03_energy.ino index d15e873cd..9351ceb9b 100644 --- a/tasmota/xdrv_03_energy.ino +++ b/tasmota/xdrv_03_energy.ino @@ -102,6 +102,7 @@ struct ENERGY { uint8_t phase_count; // Number of phases active bool voltage_common; // Use single voltage bool frequency_common; // Use single frequency + bool use_overtemp; // Use global temperature as overtemp trigger on internal energy monitor hardware bool kWhtoday_offset_init; bool voltage_available; // Enable if voltage is measured @@ -501,7 +502,7 @@ void EnergyMqttShow(void) void EnergyEverySecond(void) { // Overtemp check - if (TasmotaGlobal.global_update) { + if (Energy.use_overtemp && TasmotaGlobal.global_update) { if (TasmotaGlobal.power && !isnan(TasmotaGlobal.temperature_celsius) && (TasmotaGlobal.temperature_celsius > (float)Settings.param[P_OVER_TEMP])) { // SetOption42 Device overtemp, turn off relays AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Temperature %1_f"), &TasmotaGlobal.temperature_celsius); diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index 4f83c8e19..0c04e0e80 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -269,7 +269,8 @@ void HlwDrvInit(void) Energy.current_available = false; Energy.voltage_available = false; } - + Energy.use_overtemp = true; // Use global temperature for overtemp detection + TasmotaGlobal.energy_driver = XNRG_01; } } diff --git a/tasmota/xnrg_02_cse7766.ino b/tasmota/xnrg_02_cse7766.ino index 24c7fcc09..e925d9b6b 100644 --- a/tasmota/xnrg_02_cse7766.ino +++ b/tasmota/xnrg_02_cse7766.ino @@ -221,7 +221,7 @@ void CseSnsInit(void) { // Software serial init needs to be done here as earlier (serial) interrupts may lead to Exceptions // CseSerial = new TasmotaSerial(Pin(GPIO_CSE7766_RX), Pin(GPIO_CSE7766_TX), 1); CseSerial = new TasmotaSerial(Pin(GPIO_CSE7766_RX), -1, 1); - if (CseSerial->begin(4800, 2)) { // Fake Software Serial 8E1 by using two stop bits + if (CseSerial->begin(4800, SERIAL_8E1)) { if (CseSerial->hardwareSerial()) { SetSerial(4800, TS_SERIAL_8E1); ClaimSerial(); @@ -230,6 +230,7 @@ void CseSnsInit(void) { Settings.param[P_CSE7766_INVALID_POWER] = CSE_MAX_INVALID_POWER; // SetOption39 1..255 } Cse.power_invalid = Settings.param[P_CSE7766_INVALID_POWER]; + Energy.use_overtemp = true; // Use global temperature for overtemp detection } else { TasmotaGlobal.energy_driver = ENERGY_NONE; } diff --git a/tasmota/xnrg_04_mcp39f501.ino b/tasmota/xnrg_04_mcp39f501.ino index d71402dfa..395f66852 100644 --- a/tasmota/xnrg_04_mcp39f501.ino +++ b/tasmota/xnrg_04_mcp39f501.ino @@ -573,6 +573,7 @@ void McpSnsInit(void) mcp_buffer = (char*)(malloc(MCP_BUFFER_SIZE)); } DigitalWrite(GPIO_MCP39F5_RST, 0, 1); // MCP enable + Energy.use_overtemp = true; // Use global temperature for overtemp detection } else { TasmotaGlobal.energy_driver = ENERGY_NONE; } diff --git a/tasmota/xnrg_07_ade7953.ino b/tasmota/xnrg_07_ade7953.ino index f2c5802a2..5da3ec952 100644 --- a/tasmota/xnrg_07_ade7953.ino +++ b/tasmota/xnrg_07_ade7953.ino @@ -215,6 +215,7 @@ void Ade7953DrvInit(void) Energy.phase_count = 2; // Handle two channels as two phases Energy.voltage_common = true; // Use common voltage Energy.frequency_common = true; // Use common frequency + Energy.use_overtemp = true; // Use global temperature for overtemp detection TasmotaGlobal.energy_driver = XNRG_07; } } diff --git a/tasmota/xnrg_14_bl0940.ino b/tasmota/xnrg_14_bl0940.ino index 81a9d4791..00a69c323 100644 --- a/tasmota/xnrg_14_bl0940.ino +++ b/tasmota/xnrg_14_bl0940.ino @@ -219,6 +219,7 @@ void Bl0940SnsInit(void) { Settings.energy_current_calibration = BL0940_IREF; Settings.energy_power_calibration = BL0940_PREF; } + Energy.use_overtemp = true; // Use global temperature for overtemp detection for (uint32_t i = 0; i < 5; i++) { for (uint32_t j = 0; j < 6; j++) { diff --git a/tasmota/xnrg_19_cse7761.ino b/tasmota/xnrg_19_cse7761.ino index a644c48f4..478d5db62 100644 --- a/tasmota/xnrg_19_cse7761.ino +++ b/tasmota/xnrg_19_cse7761.ino @@ -600,6 +600,7 @@ void Cse7761DrvInit(void) { #ifdef CSE7761_FREQUENCY Energy.frequency_common = true; // Use common frequency #endif + Energy.use_overtemp = true; // Use global temperature for overtemp detection TasmotaGlobal.energy_driver = XNRG_19; } } diff --git a/tasmota/xnrg_20_dummy.ino b/tasmota/xnrg_20_dummy.ino index 0c70d6998..f1bac903b 100644 --- a/tasmota/xnrg_20_dummy.ino +++ b/tasmota/xnrg_20_dummy.ino @@ -33,6 +33,7 @@ #define NRG_DUMMY_U_COMMON true // Phase voltage = false, Common voltage = true #define NRG_DUMMY_F_COMMON true // Phase frequency = false, Common frequency = true #define NRG_DUMMY_DC false // AC = false, DC = true; +#define NRG_DUMMY_OVERTEMP true // Use global temperature for overtemp detection #define NRG_DUMMY_UREF 24000 // Voltage 240.00 V (= P / I) #define NRG_DUMMY_IREF 41666 // Current 0.417 A (= P / U) @@ -121,6 +122,7 @@ void NrgDummyDrvInit(void) { Energy.voltage_common = NRG_DUMMY_U_COMMON; // Phase voltage = false, Common voltage = true Energy.frequency_common = NRG_DUMMY_F_COMMON; // Phase frequency = false, Common frequency = true Energy.type_dc = NRG_DUMMY_DC; // AC = false, DC = true; + Energy.use_overtemp = NRG_DUMMY_OVERTEMP; // Use global temperature for overtemp detection TasmotaGlobal.energy_driver = XNRG_20; } From b8f2c97fbef35f04ac9a0f37aa0d4564e1d3c2f8 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 9 Apr 2021 12:18:26 +0200 Subject: [PATCH 6/8] Refactor GUI save settings (prt3) --- tasmota/xdrv_01_webserver.ino | 16 +++++------ tasmota/xdrv_07_domoticz.ino | 51 ++++++++++++++++------------------- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index b409b25b2..e61df582f 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1505,16 +1505,16 @@ uint16_t WebGetGpioArg(uint32_t i) { void TemplateSaveSettings(void) { char tmp[TOPSZ]; // WebGetArg NAME and GPIO/BASE/FLAG byte value - char svalue[300]; // Template command string + char command[300]; // Template command string WebGetArg(PSTR("s1"), tmp, sizeof(tmp)); // NAME - snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp); + snprintf_P(command, sizeof(command), PSTR(D_CMND_TEMPLATE " {\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), tmp); uint32_t j = 0; for (uint32_t i = 0; i < nitems(Settings.user_template.gp.io); i++) { if (6 == i) { j = 9; } if (8 == i) { j = 12; } - snprintf_P(svalue, sizeof(svalue), PSTR("%s%s%d"), svalue, (i>0)?",":"", WebGetGpioArg(j)); + snprintf_P(command, sizeof(command), PSTR("%s%s%d"), command, (i>0)?",":"", WebGetGpioArg(j)); j++; } @@ -1528,8 +1528,8 @@ void TemplateSaveSettings(void) { WebGetArg(PSTR("g99"), tmp, sizeof(tmp)); // BASE uint32_t base = atoi(tmp) +1; - snprintf_P(svalue, sizeof(svalue), PSTR("%s],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), svalue, flag, base); - ExecuteWebCommand(svalue); + snprintf_P(command, sizeof(command), PSTR("%s],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), command, flag, base); + ExecuteWebCommand(command); } /*-------------------------------------------------------------------------------------------*/ @@ -1878,7 +1878,7 @@ void LoggingSaveSettings(void) { char tmp7[CMDSZ]; WebGetArg(PSTR("lt"), tmp7, sizeof(tmp7)); // Teleperiod char command[200]; - snprintf_P(command, sizeof(command),PSTR(D_CMND_BACKLOG "0 " D_CMND_SERIALLOG " %s;" D_CMND_WEBLOG " %s;" D_CMND_MQTTLOG " %s;" D_CMND_SYSLOG " %s;" D_CMND_LOGHOST " %s;" D_CMND_LOGPORT " %s;" D_CMND_TELEPERIOD " %s"), + snprintf_P(command, sizeof(command), PSTR(D_CMND_BACKLOG "0 " D_CMND_SERIALLOG " %s;" D_CMND_WEBLOG " %s;" D_CMND_MQTTLOG " %s;" D_CMND_SYSLOG " %s;" D_CMND_LOGHOST " %s;" D_CMND_LOGPORT " %s;" D_CMND_TELEPERIOD " %s"), (!strlen(tmp1)) ? STR(SERIAL_LOG_LEVEL) : tmp1, (!strlen(tmp2)) ? STR(WEB_LOG_LEVEL) : tmp2, (!strlen(tmp3)) ? STR(MQTT_LOG_LEVEL) : tmp3, @@ -1958,8 +1958,8 @@ void OtherSaveSettings(void) { WebGetArg(PSTR("dn"), tmp1, sizeof(tmp1)); // Device name char tmp2[100]; WebGetArg(PSTR("wp"), tmp2, sizeof(tmp2)); // Web password - char command[600]; - snprintf_P(command, sizeof(command),PSTR(D_CMND_BACKLOG "0 " D_CMND_WEBPASSWORD "2 %s;" D_CMND_SO "3 %d;" D_CMND_DEVICENAME " %s"), + char command[500]; + snprintf_P(command, sizeof(command), PSTR(D_CMND_BACKLOG "0 " D_CMND_WEBPASSWORD "2 %s;" D_CMND_SO "3 %d;" D_CMND_DEVICENAME " %s"), (!strlen(tmp2)) ? "\"" : (strlen(tmp2) < 5) ? "" : tmp2, Webserver->hasArg(F("b1")), // SetOption3 - Enable MQTT (!strlen(tmp1)) ? "\"" : tmp1); diff --git a/tasmota/xdrv_07_domoticz.ino b/tasmota/xdrv_07_domoticz.ino index 5542288dd..f2289aa68 100644 --- a/tasmota/xdrv_07_domoticz.ino +++ b/tasmota/xdrv_07_domoticz.ino @@ -602,36 +602,31 @@ void HandleDomoticzConfiguration(void) { } void DomoticzSaveSettings(void) { - char stemp[20]; - char ssensor_indices[6 * MAX_DOMOTICZ_SNS_IDX]; - char tmp[100]; - - for (uint32_t i = 0; i < MAX_DOMOTICZ_IDX; i++) { - snprintf_P(stemp, sizeof(stemp), PSTR("r%d"), i); - WebGetArg(stemp, tmp, sizeof(tmp)); - Settings.domoticz_relay_idx[i] = (!strlen(tmp)) ? 0 : atoi(tmp); - snprintf_P(stemp, sizeof(stemp), PSTR("k%d"), i); - WebGetArg(stemp, tmp, sizeof(tmp)); - Settings.domoticz_key_idx[i] = (!strlen(tmp)) ? 0 : atoi(tmp); - snprintf_P(stemp, sizeof(stemp), PSTR("s%d"), i); - WebGetArg(stemp, tmp, sizeof(tmp)); - Settings.domoticz_switch_idx[i] = (!strlen(tmp)) ? 0 : atoi(tmp); + char tmp1[CMDSZ]; + WebGetArg(PSTR("ut"), tmp1, sizeof(tmp1)); + char command[500]; + snprintf_P(command, sizeof(command), PSTR(D_CMND_BACKLOG "0 " D_PRFX_DOMOTICZ D_CMND_UPDATETIMER " %s"), + (!strlen(tmp1)) ? STR(DOMOTICZ_UPDATE_TIMER) : tmp1); + char arg_idx[8]; + char tmp2[CMDSZ]; + char tmp3[CMDSZ]; + for (uint32_t i = 1; i <= MAX_DOMOTICZ_IDX; i++) { + snprintf_P(arg_idx, sizeof(arg_idx), PSTR("r%d"), i -1); + WebGetArg(arg_idx, tmp1, sizeof(tmp1)); + arg_idx[0] = 'k'; + WebGetArg(arg_idx, tmp2, sizeof(tmp2)); + arg_idx[0] = 's'; + WebGetArg(arg_idx, tmp3, sizeof(tmp3)); + snprintf_P(command, sizeof(command),PSTR("%s;" D_PRFX_DOMOTICZ D_CMND_IDX "%d %s;" D_PRFX_DOMOTICZ D_CMND_KEYIDX "%d %s;" D_PRFX_DOMOTICZ D_CMND_SWITCHIDX "%d %s"), + command, i, (!strlen(tmp1)) ? "0" : tmp1, i, (!strlen(tmp2)) ? "0" : tmp2, i, (!strlen(tmp3)) ? "0" : tmp3); } - ssensor_indices[0] = '\0'; - for (uint32_t i = 0; i < DZ_MAX_SENSORS; i++) { - snprintf_P(stemp, sizeof(stemp), PSTR("l%d"), i); - WebGetArg(stemp, tmp, sizeof(tmp)); - Settings.domoticz_sensor_idx[i] = (!strlen(tmp)) ? 0 : atoi(tmp); - snprintf_P(ssensor_indices, sizeof(ssensor_indices), PSTR("%s%s%d"), ssensor_indices, (strlen(ssensor_indices)) ? "," : "", Settings.domoticz_sensor_idx[i]); + for (uint32_t i = 1; i <= DZ_MAX_SENSORS; i++) { + snprintf_P(arg_idx, sizeof(arg_idx), PSTR("l%d"), i -1); + WebGetArg(arg_idx, tmp1, sizeof(tmp1)); + snprintf_P(command, sizeof(command),PSTR("%s;" D_PRFX_DOMOTICZ D_CMND_SENSORIDX "%d %s"), + command, i, (!strlen(tmp1)) ? "0" : tmp1); } - WebGetArg(PSTR("ut"), tmp, sizeof(tmp)); - Settings.domoticz_update_timer = (!strlen(tmp)) ? DOMOTICZ_UPDATE_TIMER : atoi(tmp); - - AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_DOMOTICZ D_CMND_IDX " %d,%d,%d,%d, " D_CMND_KEYIDX " %d,%d,%d,%d, " D_CMND_SWITCHIDX " %d,%d,%d,%d, " D_CMND_SENSORIDX " %s, " D_CMND_UPDATETIMER " %d"), - Settings.domoticz_relay_idx[0], Settings.domoticz_relay_idx[1], Settings.domoticz_relay_idx[2], Settings.domoticz_relay_idx[3], - Settings.domoticz_key_idx[0], Settings.domoticz_key_idx[1], Settings.domoticz_key_idx[2], Settings.domoticz_key_idx[3], - Settings.domoticz_switch_idx[0], Settings.domoticz_switch_idx[1], Settings.domoticz_switch_idx[2], Settings.domoticz_switch_idx[3], - ssensor_indices, Settings.domoticz_update_timer); + ExecuteWebCommand(command); // Note: beware of max number of commands in backlog currently 30 (MAX_BACKLOG) } #endif // USE_WEBSERVER From dd7cecc064193f02a66843d0607ede52c463ea9b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 9 Apr 2021 12:49:57 +0200 Subject: [PATCH 7/8] Fix backlog nodelay when sleep is active --- tasmota/support_command.ino | 4 ++++ tasmota/tasmota.ino | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index b0f4d7b2d..b81a86b10 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -323,7 +323,11 @@ void CmndBacklog(void) { if (XdrvMailbox.data_len) { if (0 == XdrvMailbox.index) { + if (!TasmotaGlobal.backlog_nodelay) { + TasmotaGlobal.backlog_sleep = TasmotaGlobal.sleep; + } TasmotaGlobal.backlog_nodelay = true; + TasmotaGlobal.sleep = 0; } #ifdef SUPPORT_IF_STATEMENT diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 38aa5a8ef..94bda17b7 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -170,6 +170,7 @@ struct { uint8_t latching_relay_pulse; // Latching relay pulse timer uint8_t active_device; // Active device in ExecuteCommandPower uint8_t sleep; // Current copy of Settings.sleep + uint8_t backlog_sleep; // Copy of sleep uint8_t leds_present; // Max number of LED supported uint8_t led_inverted; // LED inverted flag (1 = (0 = On, 1 = Off)) uint8_t led_power; // LED power state @@ -404,8 +405,9 @@ void BacklogLoop(void) { } TasmotaGlobal.backlog_mutex = false; } - if (BACKLOG_EMPTY) { + if (BACKLOG_EMPTY && TasmotaGlobal.backlog_nodelay) { TasmotaGlobal.backlog_nodelay = false; + TasmotaGlobal.sleep = TasmotaGlobal.backlog_sleep; } } } From 60de9696d88e813fec21a9b88c4c5bb70251993c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 9 Apr 2021 14:00:09 +0200 Subject: [PATCH 8/8] Refactor backlog nodelay in relation to sleep --- tasmota/support_command.ino | 4 ---- tasmota/tasmota.ino | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index b81a86b10..b0f4d7b2d 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -323,11 +323,7 @@ void CmndBacklog(void) { if (XdrvMailbox.data_len) { if (0 == XdrvMailbox.index) { - if (!TasmotaGlobal.backlog_nodelay) { - TasmotaGlobal.backlog_sleep = TasmotaGlobal.sleep; - } TasmotaGlobal.backlog_nodelay = true; - TasmotaGlobal.sleep = 0; } #ifdef SUPPORT_IF_STATEMENT diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 94bda17b7..b9e94829a 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -170,7 +170,6 @@ struct { uint8_t latching_relay_pulse; // Latching relay pulse timer uint8_t active_device; // Active device in ExecuteCommandPower uint8_t sleep; // Current copy of Settings.sleep - uint8_t backlog_sleep; // Copy of sleep uint8_t leds_present; // Max number of LED supported uint8_t led_inverted; // LED inverted flag (1 = (0 = On, 1 = Off)) uint8_t led_power; // LED power state @@ -405,15 +404,14 @@ void BacklogLoop(void) { } TasmotaGlobal.backlog_mutex = false; } - if (BACKLOG_EMPTY && TasmotaGlobal.backlog_nodelay) { + if (BACKLOG_EMPTY) { TasmotaGlobal.backlog_nodelay = false; - TasmotaGlobal.sleep = TasmotaGlobal.backlog_sleep; } } } void SleepDelay(uint32_t mseconds) { - if (mseconds) { + if (!TasmotaGlobal.backlog_nodelay && mseconds) { uint32_t wait = millis() + mseconds; while (!TimeReached(wait) && !Serial.available()) { // We need to service serial buffer ASAP as otherwise we get uart buffer overrun delay(1);