From bed26fd121bb2daef3816faf5395f49a04a7a98c Mon Sep 17 00:00:00 2001 From: Andre Thomas Date: Mon, 30 Sep 2019 17:19:15 +0200 Subject: [PATCH 01/46] MCP230xx - Add 1 and 0 as option for ON and OFF MCP230xx - Add 1 and 0 as option for ON and OFF --- sonoff/xsns_29_mcp230xx.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/xsns_29_mcp230xx.ino b/sonoff/xsns_29_mcp230xx.ino index caefb67e8..9eb98b95a 100644 --- a/sonoff/xsns_29_mcp230xx.ino +++ b/sonoff/xsns_29_mcp230xx.ino @@ -628,11 +628,11 @@ bool MCP230xx_Command(void) { #ifdef USE_MCP230xx_OUTPUT if (Settings.mcp230xx_config[pin].pinmode >= 5) { uint8_t pincmd = Settings.mcp230xx_config[pin].pinmode - 5; - if (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "ON")) { + if ((!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "ON")) || (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "1"))) { MCP230xx_SetOutPin(pin,abs(pincmd-1)); return serviced; } - if (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "OFF")) { + if ((!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "OFF")) || (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "0"))) { MCP230xx_SetOutPin(pin,pincmd); return serviced; } From b38a8bd8eb8ac1f5457764a656bbc0533457fcf9 Mon Sep 17 00:00:00 2001 From: Andre Thomas Date: Mon, 30 Sep 2019 17:26:07 +0200 Subject: [PATCH 02/46] MCP230xx - Add sensor29 pin,1 and sensor29 pin,0 MCP230xx - Add sensor29 pin,1 and sensor29 pin,0 as an alternative to sensor29 pin,ON and sensor29 pin,OFF respectively. --- sonoff/_changelog.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 5b26d35d3..8429ce360 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -5,6 +5,7 @@ * Add initial support for MQTT logging using command MqttLog (#6498) * Add Zigbee more support - collect endpoints and clusters, added ZigbeeDump command * Add initial support for shutters by Stefan Bode (#288) + * Add use case for sensor29 pin,1 and sensor29 pin,0 to substitute ON and OFF respectively with MCP230xx driver * * 6.6.0.13 20190922 * Add command EnergyReset4 x,x to initialize total usage for two tarrifs From d7d03167693df3dbd227a2e74bb11d9c3ca1386f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 30 Sep 2019 19:27:54 +0200 Subject: [PATCH 03/46] Fix open/close to limits Fix open/close to limits (#6516) --- sonoff/sonoff.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 07862a9a5..8f0627b1b 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -315,6 +315,7 @@ void SetLatchingRelay(power_t lpower, uint32_t state) void SetDevicePower(power_t rpower, uint32_t source) { ShowSource(source); + last_source = source; if (POWER_ALL_ALWAYS_ON == Settings.poweronstate) { // All on and stay on power = (1 << devices_present) -1; From dea255db26d03e7b43dec6e9e35c0f746c1736fc Mon Sep 17 00:00:00 2001 From: Andre Thomas Date: Mon, 30 Sep 2019 21:31:23 +0200 Subject: [PATCH 04/46] MCP230xx: Prevent inadvertent pinmode change We've added support for sensor29 pin,0/1 for OFF/ON but the current code would allow the pinmode to be changed without specifying a default state e.g. sensor29 pin,3 would cause the pinmode to be changed to input even if it was previously configured for output (pinmode 5/6) This change prevents these instances by enforcing the configuration rules as outlined in the wiki e.g. sensor29 pin,pinmode,pullup/default state (if used for output) --- sonoff/xsns_29_mcp230xx.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/xsns_29_mcp230xx.ino b/sonoff/xsns_29_mcp230xx.ino index 9eb98b95a..855de1349 100644 --- a/sonoff/xsns_29_mcp230xx.ino +++ b/sonoff/xsns_29_mcp230xx.ino @@ -655,9 +655,9 @@ bool MCP230xx_Command(void) { intmode = atoi(subStr(sub_string, XdrvMailbox.data, ",", 4)); } #ifdef USE_MCP230xx_OUTPUT - if ((pin < mcp230xx_pincount) && (pinmode > 0) && (pinmode < 7) && (pullup < 2)) { + if ((pin < mcp230xx_pincount) && (pinmode > 0) && (pinmode < 7) && (pullup < 2) && (paramcount > 2)) { #else // not use OUTPUT - if ((pin < mcp230xx_pincount) && (pinmode > 0) && (pinmode < 5) && (pullup < 2)) { + if ((pin < mcp230xx_pincount) && (pinmode > 0) && (pinmode < 5) && (pullup < 2) && (paramcount > 2)) { #endif // USE_MCP230xx_OUTPUT Settings.mcp230xx_config[pin].pinmode=pinmode; Settings.mcp230xx_config[pin].pullup=pullup; From 9884cfaf161cd098596dadedb2d8cb881468b4ea Mon Sep 17 00:00:00 2001 From: Andre Thomas Date: Tue, 1 Oct 2019 08:49:40 +0200 Subject: [PATCH 05/46] MCP230xx Add sensor29 pin,2 for toggle --- sonoff/xsns_29_mcp230xx.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xsns_29_mcp230xx.ino b/sonoff/xsns_29_mcp230xx.ino index 855de1349..0e9cc1039 100644 --- a/sonoff/xsns_29_mcp230xx.ino +++ b/sonoff/xsns_29_mcp230xx.ino @@ -636,7 +636,7 @@ bool MCP230xx_Command(void) { MCP230xx_SetOutPin(pin,pincmd); return serviced; } - if (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "T")) { + if ((!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "T")) || (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 2), "2"))) { MCP230xx_SetOutPin(pin,2); return serviced; } From 26fc172df4af8dc6e5dca2336f3077a739da6039 Mon Sep 17 00:00:00 2001 From: Andre Thomas Date: Tue, 1 Oct 2019 08:54:44 +0200 Subject: [PATCH 06/46] Update _changelog.ino --- sonoff/_changelog.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 8429ce360..3f88ba690 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -5,7 +5,7 @@ * Add initial support for MQTT logging using command MqttLog (#6498) * Add Zigbee more support - collect endpoints and clusters, added ZigbeeDump command * Add initial support for shutters by Stefan Bode (#288) - * Add use case for sensor29 pin,1 and sensor29 pin,0 to substitute ON and OFF respectively with MCP230xx driver + * Add command to MCP230xx: sensor29 pin,0/1/2 for OFF/ON/TOGGLE * * 6.6.0.13 20190922 * Add command EnergyReset4 x,x to initialize total usage for two tarrifs From f847763ad17fa4779956bc2be6e263207bdbf734 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 1 Oct 2019 10:49:42 +0200 Subject: [PATCH 07/46] Update xdrv_01_webserver.ino --- sonoff/xdrv_01_webserver.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index c4239e90f..9f8ec9eed 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -1128,7 +1128,7 @@ bool HandleRootStatusRefresh(void) } #ifdef USE_SHUTTER char webindex[5]; // WebGetArg name - for (uint32_t j = 1; j < 5; j++) { + for (uint32_t j = 1; j <= shutters_present; j++) { snprintf_P(webindex, sizeof(webindex), PSTR("u%d"), j); WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent if (strlen(tmp)) { From 92c2196e7304ad76f82d9897507adcb3f897be09 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 1 Oct 2019 16:21:39 +0200 Subject: [PATCH 08/46] Fix possible I2C init errors Fix possible I2C init errors --- sonoff/support.ino | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sonoff/support.ino b/sonoff/support.ino index 0a8b6c42c..8dbbc3316 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1460,8 +1460,8 @@ void I2cScan(char *devs, unsigned int devs_len) void I2cSetActive(uint32_t addr, uint32_t count = 1) { - addr &= 0x7F; - count &= 0x7F; + addr &= 0x7F; // Max I2C address is 127 + count &= 0x7F; // Max 4 x 32 bits available while (count-- && (addr < 128)) { i2c_active[addr / 32] |= (1 << (addr % 32)); addr++; @@ -1471,7 +1471,7 @@ void I2cSetActive(uint32_t addr, uint32_t count = 1) bool I2cActive(uint32_t addr) { - addr &= 0x7F; + addr &= 0x7F; // Max I2C address is 127 if (i2c_active[addr / 32] & (1 << (addr % 32))) { return true; } @@ -1480,16 +1480,12 @@ bool I2cActive(uint32_t addr) bool I2cDevice(uint8_t addr) { + addr &= 0x7F; // Max I2C address is 127 if (I2cActive(addr)) { return false; // If already active report as not present; } - for (uint8_t address = 1; address <= 127; address++) { - Wire.beginTransmission(address); - if (!Wire.endTransmission() && (address == addr)) { - return true; // Report as present; - } - } - return false; + Wire.beginTransmission(addr); + return (0 == Wire.endTransmission()); } #endif // USE_I2C From aa5b5e891e6be031f231079bf927ccc8759b6e7b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 1 Oct 2019 16:33:39 +0200 Subject: [PATCH 09/46] Add initial support for PCF8574 I2C I/O Expander Add initial support for PCF8574 I2C I/O Expander (currently output only) by Stefan Bode --- sonoff/_changelog.ino | 1 + sonoff/settings.h | 8 +- sonoff/sonoff.h | 1 + sonoff/xdrv_27_shutter.ino | 8 +- sonoff/xdrv_28_pcf8574.ino | 248 +++++++++++++++++++++++++++++++++++++ 5 files changed, 258 insertions(+), 8 deletions(-) create mode 100644 sonoff/xdrv_28_pcf8574.ino diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 3f88ba690..7739e9a0b 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -6,6 +6,7 @@ * Add Zigbee more support - collect endpoints and clusters, added ZigbeeDump command * Add initial support for shutters by Stefan Bode (#288) * Add command to MCP230xx: sensor29 pin,0/1/2 for OFF/ON/TOGGLE + * Add initial support for PCF8574 I2C I/O Expander (currently output only) by Stefan Bode * * 6.6.0.13 20190922 * Add command EnergyReset4 x,x to initialize total usage for two tarrifs diff --git a/sonoff/settings.h b/sonoff/settings.h index c11926855..4f808586d 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -93,8 +93,8 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t spare27 : 1; uint32_t spare28 : 1; uint32_t spare29 : 1; - uint32_t shutter_mode : 1; // bit 30 (v6.6.0.15) - SetOption80 - Enable shutter support - uint32_t spare31 : 1; + uint32_t shutter_mode : 1; // bit 30 (v6.6.0.14) - SetOption80 - Enable shutter support + uint32_t pcf8574_ports_inverted : 1; // bit 31 (v6.6.0.14) - SetOption81 - Invert all ports on PCF8574 devices }; } SysBitfield3; @@ -376,7 +376,6 @@ struct SYSCFG { uint16_t ina226_r_shunt[4]; // E20 uint16_t ina226_i_fs[4]; // E28 uint16_t tariff[4][2]; // E30 - uint16_t shutter_opentime[MAX_SHUTTERS]; // E40 uint16_t shutter_closetime[MAX_SHUTTERS]; // E48 int16_t shuttercoeff[5][MAX_SHUTTERS]; // E50 @@ -384,8 +383,9 @@ struct SYSCFG { uint8_t shutter_set50percent[MAX_SHUTTERS]; // E7C uint8_t shutter_position[MAX_SHUTTERS]; // E80 uint8_t shutter_startrelay[MAX_SHUTTERS]; // E84 + uint8_t pcf8574_config[MAX_PCF8574]; // E88 - uint8_t free_e88[368]; // E88 + uint8_t free_e90[360]; // E90 uint32_t cfg_timestamp; // FF8 uint32_t cfg_crc32; // FFC diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 5ee19873c..46c0868e2 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -68,6 +68,7 @@ const uint8_t MAX_XDSP_DRIVERS = 32; // Max number of allowed display dri const uint8_t MAX_XDRV_DRIVERS = 96; // Max number of allowed driver drivers const uint8_t MAX_XSNS_DRIVERS = 96; // Max number of allowed sensor drivers const uint8_t MAX_SHUTTERS = 4; // Max number of shutters +const uint8_t MAX_PCF8574 = 8; // Max number of PCF8574 devices const uint8_t MAX_RULE_MEMS = 5; // Max number of saved vars const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 512 characters const uint16_t MAX_RULE_SIZE = 512; // Max number of characters in rules diff --git a/sonoff/xdrv_27_shutter.ino b/sonoff/xdrv_27_shutter.ino index e7eaa4250..989a522bd 100644 --- a/sonoff/xdrv_27_shutter.ino +++ b/sonoff/xdrv_27_shutter.ino @@ -107,8 +107,6 @@ void ShutterInit(void) Shutter.mask = 0; //Initialize to get relay that changed Shutter.old_power = power; - char shutter_open_chr[10]; - char shutter_close_chr[10]; bool relay_in_interlock = false; AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Accuracy digits: %d"), Settings.shutter_accuracy); @@ -164,9 +162,11 @@ void ShutterInit(void) Shutter.real_position[i] = ShutterPercentToRealPosition(Settings.shutter_position[i], i); //Shutter.real_position[i] = Settings.shutter_position[i] <= 5 ? Settings.shuttercoeff[2][i] * Settings.shutter_position[i] : Settings.shuttercoeff[1][i] * Settings.shutter_position[i] + Settings.shuttercoeff[0,i]; Shutter.start_position[i] = Shutter.real_position[i]; - dtostrfd((float)Shutter.open_time[i] / 10 , 1, shutter_open_chr); - dtostrfd((float)Shutter.close_time[i] / 10, 1, shutter_close_chr); + char shutter_open_chr[10]; + dtostrfd((float)Shutter.open_time[i] / 10 , 1, shutter_open_chr); + char shutter_close_chr[10]; + dtostrfd((float)Shutter.close_time[i] / 10, 1, shutter_close_chr); AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Shutter %d (Relay:%d): Init. Pos: %d [%d %%], Open Vel.: 100 Close Vel.: %d , Max Way: %d, Opentime %s [s], Closetime %s [s], CoedffCalc: c0: %d, c1 %d, c2: %d, c3: %d, c4: %d, binmask %d, is inverted %d, shuttermode %d"), i, Settings.shutter_startrelay[i], Shutter.real_position[i], Settings.shutter_position[i], Shutter.close_velocity[i], Shutter.open_max[i], shutter_open_chr, shutter_close_chr, Settings.shuttercoeff[0][i], Settings.shuttercoeff[1][i], Settings.shuttercoeff[2][i], Settings.shuttercoeff[3][i], Settings.shuttercoeff[4][i], diff --git a/sonoff/xdrv_28_pcf8574.ino b/sonoff/xdrv_28_pcf8574.ino new file mode 100644 index 000000000..6b651a296 --- /dev/null +++ b/sonoff/xdrv_28_pcf8574.ino @@ -0,0 +1,248 @@ +/* + xdrv_28_pcf8574.ino - PCF8574 I2C support for Sonoff-Tasmota + + Copyright (C) 2019 Stefan Bode + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_I2C +#ifdef USE_PCF8574 +/*********************************************************************************************\ + * PCF8574 - I2C IO Expander + * + * I2C Address: PCF8574 = 0x20 .. 0x27, PCF8574A = 0x38 .. 0x3F +\*********************************************************************************************/ + +#define XDRV_28 28 + +#define PCF8574_ADDR1 0x20 // PCF8574 +#define PCF8574_ADDR2 0x38 // PCF8574A + +struct PCF8574 { + int error; + uint8_t pin[64]; + uint8_t address[MAX_PCF8574]; + uint8_t pin_mask[MAX_PCF8574] = { 0 }; + uint8_t max_connected_ports = 0; // Max numbers of devices comming from PCF8574 modules + uint8_t max_devices = 0; // Max numbers of PCF8574 modules + char stype[8]; + bool type = true; +} Pcf8574; + +void Pcf8574SwitchRelay(void) +{ + for (uint32_t i = 0; i < devices_present; i++) { + uint8_t relay_state = bitRead(XdrvMailbox.index, i); + + //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PCF: Pcf8574.max_devices %d requested pin %d"), Pcf8574.max_devices,Pcf8574.pin[i]); + + if (Pcf8574.max_devices > 0 && Pcf8574.pin[i] < 99) { + uint8_t board = Pcf8574.pin[i]>>3; + uint8_t oldpinmask = Pcf8574.pin_mask[board]; + uint8_t _val = bitRead(rel_inverted, i) ? !relay_state : relay_state; + + //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PCF: Pcf8574SwitchRelay %d on pin %d"), i,state); + + if (_val) { + Pcf8574.pin_mask[board] |= _val << (Pcf8574.pin[i]&0x7); + } else { + Pcf8574.pin_mask[board] &= ~(1 << (Pcf8574.pin[i]&0x7)); + } + if (oldpinmask != Pcf8574.pin_mask[board]) { + Wire.beginTransmission(Pcf8574.address[board]); + Wire.write(Pcf8574.pin_mask[board]); + Pcf8574.error = Wire.endTransmission(); + } + //pcf8574.write(Pcf8574.pin[i]&0x7, rel_inverted[i] ? !state : state); + } + } +} + +void Pcf8574Init() +{ + Pcf8574.type = false; + + uint8_t pcf8574_address = PCF8574_ADDR1; + for (uint32_t i = 0; i < MAX_PCF8574; i++) { + + // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PCF: Probing addr: 0x%x for PCF8574"), pcf8574_address); + + if (I2cDevice(pcf8574_address)) { + I2cSetActive(pcf8574_address); + Pcf8574.type = true; + + Pcf8574.address[Pcf8574.max_devices] = pcf8574_address; + Pcf8574.max_devices++; + + strcpy(Pcf8574.stype, "PCF8574"); + if (pcf8574_address >= PCF8574_ADDR2) { + strcpy(Pcf8574.stype, "PCF8574A"); + } + AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, Pcf8574.stype, pcf8574_address); + } + pcf8574_address++; + if ((PCF8574_ADDR1 + 8) == pcf8574_address) { + pcf8574_address = PCF8574_ADDR2; + } + } + if (Pcf8574.max_devices) { + for (uint32_t i = 0; i < sizeof(Pcf8574.pin); i++) { + Pcf8574.pin[i] = 99; + } + devices_present = devices_present - Pcf8574.max_connected_ports; // reset no of devices to avoid duplicate ports on duplicate init. + Pcf8574.max_connected_ports = 0; // reset no of devices to avoid duplicate ports on duplicate init. + for (uint32_t idx = 0; idx < Pcf8574.max_devices; idx++) { // suport up to 8 boards PCF8574 + + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PCF: Device %d config 0x%02x"), idx +1, Settings.pcf8574_config[idx]); + + for (uint32_t i = 0; i < 8; i++) { + uint8_t _result = Settings.pcf8574_config[idx] >> i &1; + //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PCF: I2C shift i %d: %d. Powerstate: %d, devices_present: %d"), i,_result, Settings.power>>i&1, devices_present); + if (_result > 0) { + Pcf8574.pin[devices_present] = i + 8 * idx; + bitWrite(rel_inverted, devices_present, Settings.flag3.pcf8574_ports_inverted); + devices_present++; + Pcf8574.max_connected_ports++; + } + } + } + AddLog_P2(LOG_LEVEL_INFO, PSTR("PCF: Total devices %d, PCF8574 output ports %d"), devices_present, Pcf8574.max_connected_ports); + } +} + +/*********************************************************************************************\ + * Presentation +\*********************************************************************************************/ + +#ifdef USE_WEBSERVER + +#define WEB_HANDLE_PCF8574 "pcf" + +const char HTTP_BTN_MENU_PCF8574[] PROGMEM = + "

"; + +const char HTTP_FORM_I2C_PCF8574_1[] PROGMEM = + "
 " D_PCF8574_PARAMETERS " " + "
" + "

" D_INVERT_PORTS "


"; + +const char HTTP_FORM_I2C_PCF8574_2[] PROGMEM = + "" D_DEVICE " %d " D_PORT " %d"; + +void HandlePcf8574(void) +{ + if (!HttpCheckPriviledgedAccess()) { return; } + + AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_CONFIGURE_PCF8574)); + + if (WebServer->hasArg("save")) { + Pcf8574SaveSettings(); + WebRestart(1); + return; + } + + WSContentStart_P(D_CONFIGURE_PCF8574); + WSContentSendStyle(); + WSContentSend_P(HTTP_FORM_I2C_PCF8574_1, (Settings.flag3.pcf8574_ports_inverted) ? " checked" : ""); + WSContentSend_P(HTTP_TABLE100); + for (uint32_t idx = 0; idx < Pcf8574.max_devices; idx++) { + for (uint32_t idx2 = 0; idx2 < 8; idx2++) { // 8 ports on PCF8574 + uint8_t helper = 1 << idx2; + WSContentSend_P(HTTP_FORM_I2C_PCF8574_2, + idx +1, idx2, + idx2 + 8*idx, + idx2 + 8*idx, + ((helper & Settings.pcf8574_config[idx]) >> idx2 == 0) ? " selected " : " ", + ((helper & Settings.pcf8574_config[idx]) >> idx2 == 1) ? " selected " : " " + ); + } + } + WSContentSend_P(PSTR("")); + WSContentSend_P(HTTP_FORM_END); + WSContentSpaceButton(BUTTON_CONFIGURATION); + WSContentStop(); +} + +void Pcf8574SaveSettings() +{ + char stemp[7]; + char tmp[100]; + + //AddLog_P(LOG_LEVEL_DEBUG, PSTR("PCF: Start working on Save arguements: inverted:%d")), WebServer->hasArg("b1"); + + Settings.flag3.pcf8574_ports_inverted = WebServer->hasArg("b1"); + for (byte idx = 0; idx < Pcf8574.max_devices; idx++) { + byte count=0; + byte n = Settings.pcf8574_config[idx]; + while(n!=0) { + n = n&(n-1); + count++; + } + if (count <= devices_present) { + devices_present = devices_present - count; + } + for (byte i = 0; i < 8; i++) { + snprintf_P(stemp, sizeof(stemp), PSTR("i2cs%d"), i+8*idx); + WebGetArg(stemp, tmp, sizeof(tmp)); + byte _value = (!strlen(tmp)) ? 0 : atoi(tmp); + if (_value) { + Settings.pcf8574_config[idx] = Settings.pcf8574_config[idx] | 1 << i; + devices_present++; + Pcf8574.max_connected_ports++; + } else { + Settings.pcf8574_config[idx] = Settings.pcf8574_config[idx] & ~(1 << i ); + } + } + //Settings.pcf8574_config[0] = (!strlen(webServer->arg("i2cs0").c_str())) ? 0 : atoi(webServer->arg("i2cs0").c_str()); + //AddLog_P2(LOG_LEVEL_INFO, PSTR("PCF: I2C Board: %d, Config: %2x")), idx, Settings.pcf8574_config[idx]; + + } +} +#endif // USE_WEBSERVER + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xdrv28(uint8_t function) +{ + bool result = false; + + if (i2c_flg && Pcf8574.type) { + switch (function) { + case FUNC_SET_POWER: + Pcf8574SwitchRelay(); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_ADD_BUTTON: + WSContentSend_P(HTTP_BTN_MENU_PCF8574); + break; + case FUNC_WEB_ADD_HANDLER: + WebServer->on("/" WEB_HANDLE_PCF8574, HandlePcf8574); + break; +#endif // USE_WEBSERVER + case FUNC_PRE_INIT: + Pcf8574Init(); + break; + } + } + return result; +} + +#endif // USE_PCF8574 +#endif // USE_I2C From be4867e7f6d51e866cc9771e8191821f4c0a1634 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 1 Oct 2019 16:45:53 +0200 Subject: [PATCH 10/46] Fix compilation error Fix compilation error --- sonoff/language/bg-BG.h | 8 ++++++++ sonoff/language/cs-CZ.h | 8 ++++++++ sonoff/language/de-DE.h | 8 ++++++++ sonoff/language/el-GR.h | 8 ++++++++ sonoff/language/en-GB.h | 8 ++++++++ sonoff/language/es-ES.h | 8 ++++++++ sonoff/language/fr-FR.h | 8 ++++++++ sonoff/language/he-HE.h | 8 ++++++++ sonoff/language/hu-HU.h | 8 ++++++++ sonoff/language/it-IT.h | 8 ++++++++ sonoff/language/ko-KO.h | 8 ++++++++ sonoff/language/nl-NL.h | 8 ++++++++ sonoff/language/pl-PL.h | 8 ++++++++ sonoff/language/pt-BR.h | 8 ++++++++ sonoff/language/pt-PT.h | 8 ++++++++ sonoff/language/ru-RU.h | 8 ++++++++ sonoff/language/sk-SK.h | 8 ++++++++ sonoff/language/sv-SE.h | 8 ++++++++ sonoff/language/tr-TR.h | 8 ++++++++ sonoff/language/uk-UK.h | 8 ++++++++ sonoff/language/zh-CN.h | 8 ++++++++ sonoff/language/zh-TW.h | 8 ++++++++ sonoff/my_user_config.h | 1 + sonoff/support_features.ino | 13 +++++++++---- tools/decode-status.py | 8 +++++--- 25 files changed, 191 insertions(+), 7 deletions(-) diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index 1cc34be2c..b7080f2ca 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Датчикът DS18x20 е зает" #define D_SENSOR_CRC_ERROR "Датчик DS18x20 - грешка CRC" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index c8a5713c8..d413910b3 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor DS18x20 obsazen" #define D_SENSOR_CRC_ERROR "Sensor DS18x20 chyba CRC" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index 295402d6b..f53267421 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor beschäftigt" #define D_SENSOR_CRC_ERROR "Sensor CRC-Fehler" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 222c06ef6..3b6f5edcc 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Ο αισθητήρας είναι απασχολημένος" #define D_SENSOR_CRC_ERROR "Σφάλμα CRC αισθητήρα" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index 546d99af1..af4ba7b64 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor busy" #define D_SENSOR_CRC_ERROR "Sensor CRC error" diff --git a/sonoff/language/es-ES.h b/sonoff/language/es-ES.h index b62e54661..94e2a092c 100644 --- a/sonoff/language/es-ES.h +++ b/sonoff/language/es-ES.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor ocupado" #define D_SENSOR_CRC_ERROR "Error CRC del Sensor" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index 6091da84f..3216932ee 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Capteur occupé" #define D_SENSOR_CRC_ERROR "Erreur CRC capteur" diff --git a/sonoff/language/he-HE.h b/sonoff/language/he-HE.h index ee16e5073..5fdcc93e3 100644 --- a/sonoff/language/he-HE.h +++ b/sonoff/language/he-HE.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "שרת עסוק" #define D_SENSOR_CRC_ERROR "בחיישן CRC שגיאת" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index 90a52b03a..0bcb1da05 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Szenzor foglalt" #define D_SENSOR_CRC_ERROR "Szenzor CRC hiba" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 2a990dc8e..f1183d090 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensore occupato" #define D_SENSOR_CRC_ERROR "Sensore errore CRC" diff --git a/sonoff/language/ko-KO.h b/sonoff/language/ko-KO.h index 7ffc5271d..5b99924bb 100644 --- a/sonoff/language/ko-KO.h +++ b/sonoff/language/ko-KO.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "센서가 사용 중" #define D_SENSOR_CRC_ERROR "센서 CRC 에러" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index 822bf1542..b8b0c1e88 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor bezet" #define D_SENSOR_CRC_ERROR "Sensor CRC fout" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index 8729be3c7..d3a7712b9 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Czujnik DS18x20 zajęty" #define D_SENSOR_CRC_ERROR "Czujnik DS18x20 błąd CRC" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index f1ec6326f..209738d81 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor ocupado" #define D_SENSOR_CRC_ERROR "Erro sensor CRC" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index 0fac99308..f9debe83b 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor ocupado" #define D_SENSOR_CRC_ERROR "Erro Sensor CRC" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index 2b0b68cb7..7306b1820 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Датчик DS18x20 занят" #define D_SENSOR_CRC_ERROR "Датчик DS18x20 - ошибка CRC" diff --git a/sonoff/language/sk-SK.h b/sonoff/language/sk-SK.h index 84385ee28..d462ecfac 100644 --- a/sonoff/language/sk-SK.h +++ b/sonoff/language/sk-SK.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor DS18x20 obsadený" #define D_SENSOR_CRC_ERROR "Sensor DS18x20 chyba CRC" diff --git a/sonoff/language/sv-SE.h b/sonoff/language/sv-SE.h index d55b6ddbc..a903db1f9 100644 --- a/sonoff/language/sv-SE.h +++ b/sonoff/language/sv-SE.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor upptagen" #define D_SENSOR_CRC_ERROR "Sensor CRC-fel" diff --git a/sonoff/language/tr-TR.h b/sonoff/language/tr-TR.h index f31efe078..7e23b9d4d 100755 --- a/sonoff/language/tr-TR.h +++ b/sonoff/language/tr-TR.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensör başgül" #define D_SENSOR_CRC_ERROR "Sensor CRC hatası" diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h index dd21904d8..dd694ff85 100644 --- a/sonoff/language/uk-UK.h +++ b/sonoff/language/uk-UK.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Датчик DS18x20 зайнятий" #define D_SENSOR_CRC_ERROR "Датчик DS18x20 - помилка CRC" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index 0d776f40c..8b1464b33 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "传感器正忙" #define D_SENSOR_CRC_ERROR "传感器 CRC 校验错误" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index 38d0b26be..8fa61ed9e 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -447,6 +447,14 @@ #define D_CLOSE "Close" #define D_DOMOTICZ_SHUTTER "Shutter" +// xdrv_28_pcf8574.ino +#define D_CONFIGURE_PCF8574 "Configure PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 parameters" +#define D_INVERT_PORTS "Invert Ports" +#define D_DEVICE "Device" +#define D_DEVICE_INPUT "Input" +#define D_DEVICE_OUTPUT "Output" + // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "傳感器正忙" #define D_SENSOR_CRC_ERROR "傳感器 CRC 校驗錯誤" diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index a2a2eda67..cd82cea53 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -372,6 +372,7 @@ // #define USE_MLX90614 // Enable MLX90614 ir temp sensor (I2C address 0x5a) (+0.6k code) // #define USE_CHIRP // Enable CHIRP soil moisture sensor (variable I2C address, default 0x20) // #define USE_PAJ7620 // Enable PAJ7620 gesture sensor (I2C address 0x73) (+2.5k code) +// #define USE_PCF8574 // Enable PCF8574 I/O Expander (I2C addresses 0x20 - 0x27 and 0x38 - 0x3F) (+1k9 code) // #define USE_DISPLAY // Add I2C Display Support (+2k code) #define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0 diff --git a/sonoff/support_features.ino b/sonoff/support_features.ino index 9b5e05747..999850db3 100644 --- a/sonoff/support_features.ino +++ b/sonoff/support_features.ino @@ -450,10 +450,15 @@ void GetFeatures(void) #ifdef USE_DDS2382 feature5 |= 0x00000040; // Xnrg_09_dds2382.ino #endif -// feature5 |= 0x00000080; - -// feature5 |= 0x00000100; -// feature5 |= 0x00000200; +#ifdef USE_SM2135 + feature5 |= 0x00000080; // Xdrv_026_sm2135.ino +#endif +#ifdef USE_SHUTTER + feature5 |= 0x00000100; // Xdrv_027_shutter.ino +#endif +#ifdef USE_PCF8574 + feature5 |= 0x00000200; // Xdrv_028_pcf8574.ino +#endif // feature5 |= 0x00000400; // feature5 |= 0x00000800; diff --git a/tools/decode-status.py b/tools/decode-status.py index f1c3bacf2..8682373ec 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -126,7 +126,9 @@ a_setoption = [[ "Enable Weekend Energy Tariff", "","","", "","","","", - "","","","" + "","", + "Enable shutter support", + "Invert PCF8574 ports" ]] a_features = [[ @@ -167,8 +169,8 @@ a_features = [[ "USE_MAX31865","USE_CHIRP","USE_SOLAX_X1","USE_PAJ7620" ],[ "USE_BUZZER","USE_RDM6300","USE_IBEACON","USE_SML_M", - "USE_INA226","USE_A4988_Stepper","USE_DDS2382","", - "","","","", + "USE_INA226","USE_A4988_Stepper","USE_DDS2382","USE_SM2135", + "USE_SHUTTER","USE_PCF8574","","", "","","","", "","","","", "","","","", From ea7718c81028003e4e232836a458e451da9bfced Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 1 Oct 2019 17:19:37 +0200 Subject: [PATCH 11/46] Fix ShutterClose Index display Fix ShutterClose Index display (#6535) --- sonoff/xdrv_27_shutter.ino | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/sonoff/xdrv_27_shutter.ino b/sonoff/xdrv_27_shutter.ino index 989a522bd..d02057bcd 100644 --- a/sonoff/xdrv_27_shutter.ino +++ b/sonoff/xdrv_27_shutter.ino @@ -441,7 +441,7 @@ void CmndShutterPosition(void) // Code for shutters with circuit safe configuration, switch the direction Relay ExecuteCommandPower(Settings.shutter_startrelay[index] +1, new_shutterdirection == 1 ? 0 : 1, SRC_SHUTTER); // power on - ExecuteCommandPower(Settings.shutter_startrelay[index] , 1, SRC_SHUTTER); + ExecuteCommandPower(Settings.shutter_startrelay[index], 1, SRC_SHUTTER); } else { // now start the motor for the right direction, work for momentary and normal shutters. AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Start shutter in direction %d"), Shutter.direction[index]); @@ -453,7 +453,8 @@ void CmndShutterPosition(void) } else { target_pos_percent = ShutterRealToPercentPosition(Shutter.real_position[index], index); } - ResponseCmndIdxNumber(Settings.shutter_invert[index] ? 100 - target_pos_percent : target_pos_percent); + XdrvMailbox.index = index +1; + ResponseCmndIdxNumber(Settings.shutter_invert[index] ? 100 - target_pos_percent : target_pos_percent); } } @@ -461,11 +462,11 @@ void CmndShutterOpenTime(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { if (XdrvMailbox.data_len > 0) { - Settings.shutter_opentime[XdrvMailbox.index-1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data)); + Settings.shutter_opentime[XdrvMailbox.index -1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data)); ShutterInit(); } char time_chr[10]; - dtostrfd((float)(Settings.shutter_opentime[XdrvMailbox.index-1]) / 10, 1, time_chr); + dtostrfd((float)(Settings.shutter_opentime[XdrvMailbox.index -1]) / 10, 1, time_chr); ResponseCmndIdxChar(time_chr); } } @@ -474,11 +475,11 @@ void CmndShutterCloseTime(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { if (XdrvMailbox.data_len > 0) { - Settings.shutter_closetime[XdrvMailbox.index-1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data)); + Settings.shutter_closetime[XdrvMailbox.index -1] = (uint16_t)(10 * CharToFloat(XdrvMailbox.data)); ShutterInit(); } char time_chr[10]; - dtostrfd((float)(Settings.shutter_closetime[XdrvMailbox.index-1]) / 10, 1, time_chr); + dtostrfd((float)(Settings.shutter_closetime[XdrvMailbox.index -1]) / 10, 1, time_chr); ResponseCmndIdxChar(time_chr); } } @@ -487,14 +488,14 @@ void CmndShutterRelay(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_SHUTTERS)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 64)) { - Settings.shutter_startrelay[XdrvMailbox.index-1] = XdrvMailbox.payload; + Settings.shutter_startrelay[XdrvMailbox.index -1] = XdrvMailbox.payload; if (XdrvMailbox.payload > 0) { Shutter.mask |= 3 << (XdrvMailbox.payload - 1); } else { - Shutter.mask ^= 3 << (Settings.shutter_startrelay[XdrvMailbox.index-1] - 1); + Shutter.mask ^= 3 << (Settings.shutter_startrelay[XdrvMailbox.index -1] - 1); } AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Relay %d is %d"), XdrvMailbox.index, XdrvMailbox.payload); - Settings.shutter_startrelay[XdrvMailbox.index-1] = XdrvMailbox.payload; + Settings.shutter_startrelay[XdrvMailbox.index -1] = XdrvMailbox.payload; ShutterInit(); // if payload is 0 to disable the relay there must be a reboot. Otherwhise does not work } @@ -506,11 +507,11 @@ void CmndShutterSetHalfway(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 100)) { - Settings.shutter_set50percent[XdrvMailbox.index-1] = Settings.shutter_invert[XdrvMailbox.index-1] ? 100 - XdrvMailbox.payload : XdrvMailbox.payload; + Settings.shutter_set50percent[XdrvMailbox.index -1] = Settings.shutter_invert[XdrvMailbox.index -1] ? 100 - XdrvMailbox.payload : XdrvMailbox.payload; ShutterInit(); ResponseCmndIdxNumber(XdrvMailbox.payload); // ???? } else { - ResponseCmndIdxNumber(Settings.shutter_set50percent[XdrvMailbox.index-1]); + ResponseCmndIdxNumber(Settings.shutter_set50percent[XdrvMailbox.index -1]); } } } @@ -518,9 +519,9 @@ void CmndShutterSetHalfway(void) void CmndShutterSetClose(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { - Shutter.real_position[XdrvMailbox.index-1] = 0; - ShutterStartInit(XdrvMailbox.index-1, 0, 0); - Settings.shutter_position[XdrvMailbox.index-1] = 0; + Shutter.real_position[XdrvMailbox.index -1] = 0; + ShutterStartInit(XdrvMailbox.index -1, 0, 0); + Settings.shutter_position[XdrvMailbox.index -1] = 0; ResponseCmndChar(D_CONFIGURATION_RESET); } } @@ -529,9 +530,9 @@ void CmndShutterInvert(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= shutters_present)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { - Settings.shutter_invert[XdrvMailbox.index-1] = XdrvMailbox.payload; + Settings.shutter_invert[XdrvMailbox.index -1] = XdrvMailbox.payload; } - ResponseCmndIdxNumber(Settings.shutter_invert[XdrvMailbox.index-1]); + ResponseCmndIdxNumber(Settings.shutter_invert[XdrvMailbox.index -1]); } } From d9aeb95503246a9dd5f927642a21c95ff0def13c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 1 Oct 2019 17:20:43 +0200 Subject: [PATCH 12/46] Update xdrv_27_shutter.ino --- sonoff/xdrv_27_shutter.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/xdrv_27_shutter.ino b/sonoff/xdrv_27_shutter.ino index d02057bcd..3a5aacd22 100644 --- a/sonoff/xdrv_27_shutter.ino +++ b/sonoff/xdrv_27_shutter.ino @@ -435,7 +435,7 @@ void CmndShutterPosition(void) ShutterStartInit(index, new_shutterdirection, Shutter.target_position[index]); Shutter.operations[index]++; if (Shutter.mode == SHT_OFF_ON__OPEN_CLOSE) { - ExecuteCommandPower(Settings.shutter_startrelay[index] , 0, SRC_SHUTTER); + ExecuteCommandPower(Settings.shutter_startrelay[index], 0, SRC_SHUTTER); //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Delay5 5s, xdrv %d"), XdrvMailbox.payload); ShutterDelayForMotorStop(); // Code for shutters with circuit safe configuration, switch the direction Relay @@ -453,7 +453,7 @@ void CmndShutterPosition(void) } else { target_pos_percent = ShutterRealToPercentPosition(Shutter.real_position[index], index); } - XdrvMailbox.index = index +1; + XdrvMailbox.index = index +1; // Fix random index for ShutterClose ResponseCmndIdxNumber(Settings.shutter_invert[index] ? 100 - target_pos_percent : target_pos_percent); } } From c7308e2dfff0bdbbbd36869d59968038cf3970f6 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Tue, 1 Oct 2019 17:05:58 -0300 Subject: [PATCH 13/46] Updated Spanish Translation --- sonoff/language/es-ES.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sonoff/language/es-ES.h b/sonoff/language/es-ES.h index 94e2a092c..239542068 100644 --- a/sonoff/language/es-ES.h +++ b/sonoff/language/es-ES.h @@ -28,7 +28,7 @@ * Use online command StateText to translate ON, OFF, HOLD and TOGGLE. * Use online command Prefix to translate cmnd, stat and tele. * - * Updated until v6.6.0.4 + * Updated until v6.6.0.14 \*********************************************************************/ #define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English) @@ -443,17 +443,17 @@ #define D_ENERGY_TOTAL "Energía Total" // xdrv_27_shutter.ino -#define D_OPEN "Open" -#define D_CLOSE "Close" -#define D_DOMOTICZ_SHUTTER "Shutter" +#define D_OPEN "Abrir" +#define D_CLOSE "Cerrar" +#define D_DOMOTICZ_SHUTTER "Cortina" // xdrv_28_pcf8574.ino -#define D_CONFIGURE_PCF8574 "Configure PCF8574" -#define D_PCF8574_PARAMETERS "PCF8574 parameters" -#define D_INVERT_PORTS "Invert Ports" -#define D_DEVICE "Device" -#define D_DEVICE_INPUT "Input" -#define D_DEVICE_OUTPUT "Output" +#define D_CONFIGURE_PCF8574 "Configurar PCF8574" +#define D_PCF8574_PARAMETERS "Parámetros de PCF8574" +#define D_INVERT_PORTS "Invertir Puertos" +#define D_DEVICE "Dispositivo" +#define D_DEVICE_INPUT "Entrada" +#define D_DEVICE_OUTPUT "Salida" // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor ocupado" From 838e571d10d1b258d54bf80d29ec2419204c79fd Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Tue, 1 Oct 2019 22:58:08 +0200 Subject: [PATCH 14/46] Fix TasmotaSerial: move serial send to IRAM for high speed baud rates --- .../README.md | 0 .../examples/swsertest/swsertest.ino | 0 .../keywords.txt | 0 .../library.json | 2 +- .../library.properties | 2 +- .../src/TasmotaSerial.cpp | 62 ++++++++++++++----- .../src/TasmotaSerial.h | 2 + sonoff/_changelog.ino | 1 + 8 files changed, 50 insertions(+), 19 deletions(-) rename lib/{TasmotaSerial-2.4.0 => TasmotaSerial-2.4.1}/README.md (100%) rename lib/{TasmotaSerial-2.4.0 => TasmotaSerial-2.4.1}/examples/swsertest/swsertest.ino (100%) rename lib/{TasmotaSerial-2.4.0 => TasmotaSerial-2.4.1}/keywords.txt (100%) rename lib/{TasmotaSerial-2.4.0 => TasmotaSerial-2.4.1}/library.json (94%) rename lib/{TasmotaSerial-2.4.0 => TasmotaSerial-2.4.1}/library.properties (94%) rename lib/{TasmotaSerial-2.4.0 => TasmotaSerial-2.4.1}/src/TasmotaSerial.cpp (88%) rename lib/{TasmotaSerial-2.4.0 => TasmotaSerial-2.4.1}/src/TasmotaSerial.h (97%) diff --git a/lib/TasmotaSerial-2.4.0/README.md b/lib/TasmotaSerial-2.4.1/README.md similarity index 100% rename from lib/TasmotaSerial-2.4.0/README.md rename to lib/TasmotaSerial-2.4.1/README.md diff --git a/lib/TasmotaSerial-2.4.0/examples/swsertest/swsertest.ino b/lib/TasmotaSerial-2.4.1/examples/swsertest/swsertest.ino similarity index 100% rename from lib/TasmotaSerial-2.4.0/examples/swsertest/swsertest.ino rename to lib/TasmotaSerial-2.4.1/examples/swsertest/swsertest.ino diff --git a/lib/TasmotaSerial-2.4.0/keywords.txt b/lib/TasmotaSerial-2.4.1/keywords.txt similarity index 100% rename from lib/TasmotaSerial-2.4.0/keywords.txt rename to lib/TasmotaSerial-2.4.1/keywords.txt diff --git a/lib/TasmotaSerial-2.4.0/library.json b/lib/TasmotaSerial-2.4.1/library.json similarity index 94% rename from lib/TasmotaSerial-2.4.0/library.json rename to lib/TasmotaSerial-2.4.1/library.json index cdce0deba..554d9ea9e 100644 --- a/lib/TasmotaSerial-2.4.0/library.json +++ b/lib/TasmotaSerial-2.4.1/library.json @@ -1,6 +1,6 @@ { "name": "TasmotaSerial", - "version": "2.4.0", + "version": "2.4.1", "keywords": [ "serial", "io", "TasmotaSerial" ], diff --git a/lib/TasmotaSerial-2.4.0/library.properties b/lib/TasmotaSerial-2.4.1/library.properties similarity index 94% rename from lib/TasmotaSerial-2.4.0/library.properties rename to lib/TasmotaSerial-2.4.1/library.properties index f1486dfab..b326d7404 100644 --- a/lib/TasmotaSerial-2.4.0/library.properties +++ b/lib/TasmotaSerial-2.4.1/library.properties @@ -1,5 +1,5 @@ name=TasmotaSerial -version=2.4.0 +version=2.4.1 author=Theo Arends maintainer=Theo Arends sentence=Implementation of software serial with hardware serial fallback for ESP8266. diff --git a/lib/TasmotaSerial-2.4.0/src/TasmotaSerial.cpp b/lib/TasmotaSerial-2.4.1/src/TasmotaSerial.cpp similarity index 88% rename from lib/TasmotaSerial-2.4.0/src/TasmotaSerial.cpp rename to lib/TasmotaSerial-2.4.1/src/TasmotaSerial.cpp index 5ffcaf390..0a1386375 100644 --- a/lib/TasmotaSerial-2.4.0/src/TasmotaSerial.cpp +++ b/lib/TasmotaSerial-2.4.1/src/TasmotaSerial.cpp @@ -213,6 +213,7 @@ int TasmotaSerial::available() #ifdef TM_SERIAL_USE_IRAM #define TM_SERIAL_WAIT_SND { while (ESP.getCycleCount() < (wait + start)) if (!m_high_speed) optimistic_yield(1); wait += m_bit_time; } // Watchdog timeouts +#define TM_SERIAL_WAIT_SND_FAST { while (ESP.getCycleCount() < (wait + start)); wait += m_bit_time; } #define TM_SERIAL_WAIT_RCV { while (ESP.getCycleCount() < (wait + start)); wait += m_bit_time; } #define TM_SERIAL_WAIT_RCV_LOOP { while (ESP.getCycleCount() < (wait + start)); } #else @@ -221,31 +222,58 @@ int TasmotaSerial::available() #define TM_SERIAL_WAIT_RCV_LOOP { while (ESP.getCycleCount() < (wait + start)); } #endif +#ifdef TM_SERIAL_USE_IRAM +void ICACHE_RAM_ATTR TasmotaSerial::_fast_write(uint8_t b) { +#else +void TasmotaSerial::_fast_write(uint8_t b) { +#endif + uint32_t wait = m_bit_time; + uint32_t start = ESP.getCycleCount(); + // Start bit; + digitalWrite(m_tx_pin, LOW); + TM_SERIAL_WAIT_SND_FAST; + for (uint32_t i = 0; i < 8; i++) { + digitalWrite(m_tx_pin, (b & 1) ? HIGH : LOW); + TM_SERIAL_WAIT_SND_FAST; + b >>= 1; + } + // Stop bit(s) + digitalWrite(m_tx_pin, HIGH); + for (uint32_t i = 0; i < m_stop_bits; i++) { + TM_SERIAL_WAIT_SND_FAST; + } +} + size_t TasmotaSerial::write(uint8_t b) { if (m_hardserial) { return Serial.write(b); } else { if (-1 == m_tx_pin) return 0; - if (m_high_speed) cli(); // Disable interrupts in order to get a clean transmit - uint32_t wait = m_bit_time; - //digitalWrite(m_tx_pin, HIGH); // already in HIGH mode - uint32_t start = ESP.getCycleCount(); - // Start bit; - digitalWrite(m_tx_pin, LOW); - TM_SERIAL_WAIT_SND; - for (uint32_t i = 0; i < 8; i++) { - digitalWrite(m_tx_pin, (b & 1) ? HIGH : LOW); - TM_SERIAL_WAIT_SND; - b >>= 1; - } - // Stop bit(s) - digitalWrite(m_tx_pin, HIGH); - // re-enable interrupts during stop bits, it's not an issue if they are longer than expected - if (m_high_speed) sei(); - for (uint32_t i = 0; i < m_stop_bits; i++) { + if (m_high_speed) { + cli(); // Disable interrupts in order to get a clean transmit + _fast_write(b); + sei(); + } else { + uint32_t wait = m_bit_time; + //digitalWrite(m_tx_pin, HIGH); // already in HIGH mode + uint32_t start = ESP.getCycleCount(); + // Start bit; + digitalWrite(m_tx_pin, LOW); TM_SERIAL_WAIT_SND; + for (uint32_t i = 0; i < 8; i++) { + digitalWrite(m_tx_pin, (b & 1) ? HIGH : LOW); + TM_SERIAL_WAIT_SND; + b >>= 1; + } + // Stop bit(s) + digitalWrite(m_tx_pin, HIGH); + // re-enable interrupts during stop bits, it's not an issue if they are longer than expected + for (uint32_t i = 0; i < m_stop_bits; i++) { + TM_SERIAL_WAIT_SND; + } } + return 1; } } diff --git a/lib/TasmotaSerial-2.4.0/src/TasmotaSerial.h b/lib/TasmotaSerial-2.4.1/src/TasmotaSerial.h similarity index 97% rename from lib/TasmotaSerial-2.4.0/src/TasmotaSerial.h rename to lib/TasmotaSerial-2.4.1/src/TasmotaSerial.h index 41f3cd0d7..81545f522 100644 --- a/lib/TasmotaSerial-2.4.0/src/TasmotaSerial.h +++ b/lib/TasmotaSerial-2.4.1/src/TasmotaSerial.h @@ -81,6 +81,8 @@ class TasmotaSerial : public Stream { bool m_high_speed = false; bool m_very_high_speed = false; // above 100000 bauds uint8_t *m_buffer; + + void _fast_write(uint8_t b); // IRAM minimized version }; #endif // TasmotaSerial_h diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 7739e9a0b..be07e8788 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -7,6 +7,7 @@ * Add initial support for shutters by Stefan Bode (#288) * Add command to MCP230xx: sensor29 pin,0/1/2 for OFF/ON/TOGGLE * Add initial support for PCF8574 I2C I/O Expander (currently output only) by Stefan Bode + * Fix TasmotaSerial: move serial send to IRAM for high speed baud rates * * 6.6.0.13 20190922 * Add command EnergyReset4 x,x to initialize total usage for two tarrifs From 6379677218078e123bf549324ef69ddecbb84c6f Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Wed, 2 Oct 2019 10:39:14 +0200 Subject: [PATCH 15/46] Shutter and PC8574 --- sonoff/language/de-DE.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index f53267421..71c4a1de1 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -28,7 +28,7 @@ * Use online command StateText to translate ON, OFF, HOLD and TOGGLE. * Use online command Prefix to translate cmnd, stat and tele. * - * Updated until v6.6.0.4 + * Updated until v6.6.0.14 \*********************************************************************/ //#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English) @@ -443,17 +443,17 @@ #define D_ENERGY_TOTAL "Energie insgesamt" // xdrv_27_shutter.ino -#define D_OPEN "Open" -#define D_CLOSE "Close" -#define D_DOMOTICZ_SHUTTER "Shutter" +#define D_OPEN "Öffnen" +#define D_CLOSE "Schliessen" +#define D_DOMOTICZ_SHUTTER "Rollo" // xdrv_28_pcf8574.ino -#define D_CONFIGURE_PCF8574 "Configure PCF8574" -#define D_PCF8574_PARAMETERS "PCF8574 parameters" -#define D_INVERT_PORTS "Invert Ports" -#define D_DEVICE "Device" -#define D_DEVICE_INPUT "Input" -#define D_DEVICE_OUTPUT "Output" +#define D_CONFIGURE_PCF8574 "Konfiguriere PCF8574" +#define D_PCF8574_PARAMETERS "PCF8574 Parameter" +#define D_INVERT_PORTS "Invertiere Ports" +#define D_DEVICE "Gerät" +#define D_DEVICE_INPUT "Eingang" +#define D_DEVICE_OUTPUT "Ausgang" // xsns_05_ds18b20.ino #define D_SENSOR_BUSY "Sensor beschäftigt" From 37fc7d22592058b5793de83fa7e096306b4de735 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 2 Oct 2019 11:24:51 +0200 Subject: [PATCH 16/46] Add command SetOption71 for DDS238-2 Add command SetOption71 0/1 to switch between different Modbus Active Energy registers on DDS238-2 energy meters (#6531) --- sonoff/_changelog.ino | 1 + sonoff/settings.h | 2 +- sonoff/xnrg_09_dds2382.ino | 15 ++++++++++----- tools/decode-status.py | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 7739e9a0b..9139cb622 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -7,6 +7,7 @@ * Add initial support for shutters by Stefan Bode (#288) * Add command to MCP230xx: sensor29 pin,0/1/2 for OFF/ON/TOGGLE * Add initial support for PCF8574 I2C I/O Expander (currently output only) by Stefan Bode + * Add command SetOption71 0/1 to switch between different Modbus Active Energy registers on DDS238-2 energy meters (#6531) * * 6.6.0.13 20190922 * Add command EnergyReset4 x,x to initialize total usage for two tarrifs diff --git a/sonoff/settings.h b/sonoff/settings.h index 4f808586d..c2be9d6e3 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -84,7 +84,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t pwm_multi_channels : 1; // bit 18 (v6.6.0.3) - SetOption68 - Enable multi-channels PWM instead of Color PWM uint32_t tuya_dimmer_min_limit : 1; // bit 19 (v6.6.0.5) - SetOption69 - Limits Tuya dimmers to minimum of 10% (25) when enabled. uint32_t energy_weekend : 1; // bit 20 (v6.6.0.8) - CMND_TARIFF - uint32_t spare21 : 1; + uint32_t dds2382_model : 1; // bit 21 (v6.6.0.14) - SetOption71 - Select different Modbus registers for Active Energy (#6531) uint32_t spare22 : 1; uint32_t spare23 : 1; uint32_t spare24 : 1; diff --git a/sonoff/xnrg_09_dds2382.ino b/sonoff/xnrg_09_dds2382.ino index b36a12d8f..590a60186 100644 --- a/sonoff/xnrg_09_dds2382.ino +++ b/sonoff/xnrg_09_dds2382.ino @@ -54,8 +54,10 @@ void Dds2382EverySecond(void) } else { Energy.data_valid[0] = 0; - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 - // SA FC BC EnergyTotal ExportActiv ImportActiv Volta Curre APowe RPowe PFact Frequ Crc-- + // 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 = ModBus register + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 = Buffer index + // SA FC BC EnergyTotal ExportActiv ImportActiv Volta Curre APowe RPowe PFact Frequ Crc-- = DDS238-2 ZN/S version 1 (#6384) + // SA FC BC EnergyTotal ExportActiv ImportActiv Volta Curre APowe RPowe PFact Frequ Crc-- = DDS238-2 ZN/S version 2 (#6531) Energy.voltage[0] = (float)((buffer[27] << 8) + buffer[28]) / 10.0; Energy.current[0] = (float)((buffer[29] << 8) + buffer[30]) / 100.0; @@ -63,9 +65,12 @@ void Dds2382EverySecond(void) Energy.reactive_power[0] = (float)((buffer[33] << 8) + buffer[34]); Energy.power_factor[0] = (float)((buffer[35] << 8) + buffer[36]) / 1000.0; // 1.00 Energy.frequency[0] = (float)((buffer[37] << 8) + buffer[38]) / 100.0; // 50.0 Hz - Energy.export_active = (float)((buffer[11] << 24) + (buffer[12] << 16) + (buffer[13] << 8) + buffer[14]) / 100.0; // 429496729.0 W -// float energy_total = (float)((buffer[3] << 24) + (buffer[4] << 16) + (buffer[5] << 8) + buffer[6]) / 100.0; // 429496729.0 W - float import_active = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[17] << 8) + buffer[18]) / 100.0; // 429496729.0 W + uint8_t offset = 11; + if (Settings.flag3.dds2382_model) { + offset = 19; + } + Energy.export_active = (float)((buffer[offset] << 24) + (buffer[offset +1] << 16) + (buffer[offset +2] << 8) + buffer[offset +3]) / 100.0; // 429496729.0 W + float import_active = (float)((buffer[offset +4] << 24) + (buffer[offset +5] << 16) + (buffer[offset +6] << 8) + buffer[offset +7]) / 100.0; // 429496729.0 W EnergyUpdateTotal(import_active, false); // 484.708 kWh } diff --git a/tools/decode-status.py b/tools/decode-status.py index 8682373ec..a08689306 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -124,7 +124,8 @@ a_setoption = [[ "Enable multi-channels PWM instead of Color PWM", "Limits Tuya MCU dimmers to minimum of 10% (25) when enabled", "Enable Weekend Energy Tariff", - "","","", + "Select different Modbus registers for Active Energy", + "","", "","","","", "","", "Enable shutter support", From f946ebaf7b558f996a1adb0db003afc0fa6817b3 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Wed, 2 Oct 2019 11:11:50 +0100 Subject: [PATCH 17/46] Dimmer: Change SetOption43 (Dimmer Max) generic instead of Tuya only --- sonoff/settings.ino | 10 +++++----- sonoff/sonoff.h | 2 +- sonoff/support_command.ino | 2 +- sonoff/xdrv_16_tuyamcu.ino | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 289c8392b..f16273f7c 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -125,8 +125,8 @@ #ifndef ENERGY_OVERTEMP #define ENERGY_OVERTEMP 90 // Overtemp in Celsius #endif -#ifndef TUYA_DIMMER_MAX -#define TUYA_DIMMER_MAX 100 +#ifndef DEFAULT_DIMMER_MAX +#define DEFAULT_DIMMER_MAX 100 #endif enum WebColors { @@ -774,7 +774,7 @@ void SettingsDefaultSet2(void) // Settings.light_rotation = 0; SettingsDefaultSet_5_8_1(); // Clock color - Settings.param[P_TUYA_DIMMER_MAX] = TUYA_DIMMER_MAX; + Settings.param[P_DIMMER_MAX] = DEFAULT_DIMMER_MAX; // Display SettingsDefaultSet_5_10_1(); // Display settings @@ -1084,9 +1084,9 @@ void SettingsDelta(void) if (Settings.version < 0x06060008) { // Move current tuya dimmer range to the new param. if (Settings.flag3.tuya_dimmer_range_255) { - Settings.param[P_TUYA_DIMMER_MAX] = 100; + Settings.param[P_DIMMER_MAX] = 100; } else { - Settings.param[P_TUYA_DIMMER_MAX] = 255; + Settings.param[P_DIMMER_MAX] = 255; } } if (Settings.version < 0x06060009) { diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 46c0868e2..c1c19f3fe 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -249,7 +249,7 @@ enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; enum SettingsParamIndex { P_HOLD_TIME, P_MAX_POWER_RETRY, P_ex_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_IR_UNKNOW_THRESHOLD, // SetOption32 .. SetOption38 P_CSE7766_INVALID_POWER, P_HOLD_IGNORE, P_ex_TUYA_RELAYS, P_OVER_TEMP, // SetOption39 .. SetOption42 - P_TUYA_DIMMER_MAX, + P_DIMMER_MAX, P_ex_TUYA_VOLTAGE_ID, P_ex_TUYA_CURRENT_ID, P_ex_TUYA_POWER_ID, // SetOption43 .. SetOption46 P_ex_ENERGY_TARIFF1, P_ex_ENERGY_TARIFF2, // SetOption47 .. SetOption48 P_MAX_PARAM8 }; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index 0e2f6d4e6..9e2fd5fcb 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -687,7 +687,7 @@ void CmndSetoption(void) break; #endif #ifdef USE_TUYA_MCU - case P_TUYA_DIMMER_MAX: + case P_DIMMER_MAX: restart_flag = 2; // Need a restart to update GUI break; #endif diff --git a/sonoff/xdrv_16_tuyamcu.ino b/sonoff/xdrv_16_tuyamcu.ino index d849d4712..db190f58f 100644 --- a/sonoff/xdrv_16_tuyamcu.ino +++ b/sonoff/xdrv_16_tuyamcu.ino @@ -297,14 +297,14 @@ void LightSerialDuty(uint8_t duty) if (Settings.flag3.tuya_dimmer_min_limit) { // Enable dimming limit SetOption69: Enabled by default if (duty < 25) { duty = 25; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself } - duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]); + duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_DIMMER_MAX]); if (Tuya.new_dim != duty) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, dpid); TuyaSendValue(dpid, duty); } } else if (dpid > 0) { Tuya.ignore_dim = false; // reset flag - duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]); + duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_DIMMER_MAX]); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim skipped value=%d"), duty); // due to 0 or already set } else { AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: Cannot set dimmer. Dimmer Id unknown")); // @@ -375,7 +375,7 @@ void TuyaPacketProcess(void) bool tuya_energy_enabled = (XNRG_16 == energy_flg); if (fnId == TUYA_MCU_FUNC_DIMMER) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), Tuya.buffer[13]); - Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, Settings.param[P_TUYA_DIMMER_MAX], 0, 100); + Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, Settings.param[P_DIMMER_MAX], 0, 100); if ((power || Settings.flag3.tuya_apply_o20) && (Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) { Tuya.ignore_dim = true; From 39b201898d7bfc2a4838b04899db19594f573db7 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Wed, 2 Oct 2019 11:12:51 +0100 Subject: [PATCH 18/46] PS_16_DZ: Implement SetOption43 (Dimmer Max) for PS_16_DZ dimmers. Fixes #6544 --- sonoff/xdrv_19_ps16dz_dimmer.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index b0dc80190..0c637a2ae 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -83,6 +83,7 @@ void PS16DZSerialSendUpdateCommand(void) uint8_t light_state_dimmer = light_state.getDimmer(); // Dimming acts odd below 10% - this mirrors the threshold set on the faceplate itself light_state_dimmer = (light_state_dimmer < 10) ? 10 : light_state_dimmer; + light_state_dimmer = (light_state_dimmer > Settings.param[P_DIMMER_MAX]) ? Settings.param[P_DIMMER_MAX] : light_state_dimmer; snprintf_P(Ps16dz.tx_buffer, PS16DZ_BUFFER_SIZE, PSTR("AT+UPDATE=\"sequence\":\"%d%03d\",\"switch\":\"%s\",\"bright\":%d"), LocalTime(), millis()%1000, power?"on":"off", light_state_dimmer); From bac30bbe1bdbaada05fa963c71897e09b1402390 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 2 Oct 2019 12:51:37 +0200 Subject: [PATCH 19/46] Try to catch domoticz test Try to catch domoticz test (#6529) --- sonoff/xdrv_02_mqtt.ino | 6 +- sonoff/xdrv_07_domoticz.ino | 170 ++++++++++++++++++------------------ sonoff/xdrv_10_rules.ino | 2 +- sonoff/xdrv_interface.ino | 10 --- 4 files changed, 92 insertions(+), 96 deletions(-) diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino index d1bf375a6..81fd45b6f 100644 --- a/sonoff/xdrv_02_mqtt.ino +++ b/sonoff/xdrv_02_mqtt.ino @@ -279,7 +279,11 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) // if (LOG_LEVEL_DEBUG_MORE <= seriallog_level) { Serial.println(dataBuf); } // MQTT pre-processing - if (XdrvMqttData(topic, strlen(topic), (char*)data, data_len)) { return; } + XdrvMailbox.index = strlen(topic); + XdrvMailbox.data_len = data_len; + XdrvMailbox.topic = topic; + XdrvMailbox.data = (char*)data; + if (XdrvCall(FUNC_MQTT_DATA)) { return; } ShowSource(SRC_MQTT); diff --git a/sonoff/xdrv_07_domoticz.ino b/sonoff/xdrv_07_domoticz.ino index 44959045b..0bdc22b83 100644 --- a/sonoff/xdrv_07_domoticz.ino +++ b/sonoff/xdrv_07_domoticz.ino @@ -199,102 +199,104 @@ void DomoticzMqttSubscribe(void) bool DomoticzMqttData(void) { - char stemp1[10]; - unsigned long idx = 0; - int16_t nvalue = -1; - bool found = false; - domoticz_update_flag = true; - if (!strncmp(XdrvMailbox.topic, domoticz_out_topic, strlen(domoticz_out_topic))) { - if (XdrvMailbox.data_len < 20) { - return true; // No valid data - } - StaticJsonBuffer<400> jsonBuf; - JsonObject& domoticz = jsonBuf.parseObject(XdrvMailbox.data); - if (!domoticz.success()) { - return true; // To much or invalid data - } + + if (strncasecmp(XdrvMailbox.topic, domoticz_out_topic, strlen(domoticz_out_topic)) != 0) { + return false; // Process unchanged data + } + + // topic is domoticz/out so try to analyse + if (XdrvMailbox.data_len < 20) { + return true; // No valid data + } + StaticJsonBuffer<400> jsonBuf; + JsonObject& domoticz = jsonBuf.parseObject(XdrvMailbox.data); + if (!domoticz.success()) { + return true; // To much or invalid data + } // if (strcmp_P(domoticz["dtype"],PSTR("Light/Switch"))) { // return true; // } - idx = domoticz["idx"]; - if (domoticz.containsKey("nvalue")) { - nvalue = domoticz["nvalue"]; - } + uint32_t idx = domoticz["idx"]; + int16_t nvalue = -1; + if (domoticz.containsKey("nvalue")) { + nvalue = domoticz["nvalue"]; + } - AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_DOMOTICZ "idx %d, nvalue %d"), idx, nvalue); + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_DOMOTICZ "idx %d, nvalue %d"), idx, nvalue); - if ((idx > 0) && (nvalue >= 0) && (nvalue <= 15)) { - uint8_t maxdev = (devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : devices_present; - for (uint32_t i = 0; i < maxdev; i++) { - if (idx == Settings.domoticz_relay_idx[i]) { - bool iscolordimmer = strcmp_P(domoticz["dtype"],PSTR("Color Switch")) == 0; - snprintf_P(stemp1, sizeof(stemp1), PSTR("%d"), i +1); + bool found = false; + if ((idx > 0) && (nvalue >= 0) && (nvalue <= 15)) { + uint8_t maxdev = (devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : devices_present; + for (uint32_t i = 0; i < maxdev; i++) { + if (idx == Settings.domoticz_relay_idx[i]) { + bool iscolordimmer = strcmp_P(domoticz["dtype"],PSTR("Color Switch")) == 0; + char stemp1[10]; + snprintf_P(stemp1, sizeof(stemp1), PSTR("%d"), i +1); #ifdef USE_SONOFF_IFAN - if (IsModuleIfan() && (1 == i)) { // Idx 2 is fanspeed - uint8_t svalue = 0; - if (domoticz.containsKey("svalue1")) { - svalue = domoticz["svalue1"]; - } else { - return true; // Invalid data - } - svalue = (nvalue == 2) ? svalue / 10 : 0; - if (GetFanspeed() == svalue) { - return true; // Stop loop as already set - } - if (TimePassedSince(domoticz_fan_debounce) < 1000) { - return true; // Stop loop if device in limbo - } - snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_FANSPEED)); - snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%d"), svalue); - found = true; - } else + if (IsModuleIfan() && (1 == i)) { // Idx 2 is fanspeed + uint8_t svalue = 0; + if (domoticz.containsKey("svalue1")) { + svalue = domoticz["svalue1"]; + } else { + return true; // Invalid data + } + svalue = (nvalue == 2) ? svalue / 10 : 0; + if (GetFanspeed() == svalue) { + return true; // Stop loop as already set + } + if (TimePassedSince(domoticz_fan_debounce) < 1000) { + return true; // Stop loop if device in limbo + } + snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_FANSPEED)); + snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%d"), svalue); + found = true; + } else #endif // USE_SONOFF_IFAN - if (iscolordimmer && 10 == nvalue) { // Color_SetColor - JsonObject& color = domoticz["Color"]; - uint16_t level = nvalue = domoticz["svalue1"]; - uint16_t r = color["r"]; r = r * level / 100; - uint16_t g = color["g"]; g = g * level / 100; - uint16_t b = color["b"]; b = b * level / 100; - uint16_t cw = color["cw"]; cw = cw * level / 100; - uint16_t ww = color["ww"]; ww = ww * level / 100; - snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_COLOR)); - snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%02x%02x%02x%02x%02x"), r, g, b, cw, ww); - found = true; - } - else if ((!iscolordimmer && 2 == nvalue) || // gswitch_sSetLevel - (iscolordimmer && 15 == nvalue)) { // Color_SetBrightnessLevel - if (domoticz.containsKey("svalue1")) { - nvalue = domoticz["svalue1"]; - } else { - return true; // Invalid data - } - if (light_type && (Settings.light_dimmer == nvalue) && ((power >> i) &1)) { - return true; // State already set - } - snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_DIMMER)); - snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%d"), nvalue); - found = true; - } - else if (1 == nvalue || 0 == nvalue) { - if (((power >> i) &1) == (power_t)nvalue) { - return true; // Stop loop - } - snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_POWER "%s"), (devices_present > 1) ? stemp1 : ""); - snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%d"), nvalue); - found = true; - } - break; + if (iscolordimmer && 10 == nvalue) { // Color_SetColor + JsonObject& color = domoticz["Color"]; + uint16_t level = nvalue = domoticz["svalue1"]; + uint16_t r = color["r"]; r = r * level / 100; + uint16_t g = color["g"]; g = g * level / 100; + uint16_t b = color["b"]; b = b * level / 100; + uint16_t cw = color["cw"]; cw = cw * level / 100; + uint16_t ww = color["ww"]; ww = ww * level / 100; + snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_COLOR)); + snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%02x%02x%02x%02x%02x"), r, g, b, cw, ww); + found = true; } + else if ((!iscolordimmer && 2 == nvalue) || // gswitch_sSetLevel + (iscolordimmer && 15 == nvalue)) { // Color_SetBrightnessLevel + if (domoticz.containsKey("svalue1")) { + nvalue = domoticz["svalue1"]; + } else { + return true; // Invalid data + } + if (light_type && (Settings.light_dimmer == nvalue) && ((power >> i) &1)) { + return true; // State already set + } + snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_DIMMER)); + snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%d"), nvalue); + found = true; + } + else if (1 == nvalue || 0 == nvalue) { + if (((power >> i) &1) == (power_t)nvalue) { + return true; // Stop loop + } + snprintf_P(XdrvMailbox.topic, XdrvMailbox.index, PSTR("/" D_CMND_POWER "%s"), (devices_present > 1) ? stemp1 : ""); + snprintf_P(XdrvMailbox.data, XdrvMailbox.data_len, PSTR("%d"), nvalue); + found = true; + } + break; } } - if (!found) { return true; } // No command received - - AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_DOMOTICZ D_RECEIVED_TOPIC " %s, " D_DATA " %s"), XdrvMailbox.topic, XdrvMailbox.data); - - domoticz_update_flag = false; } - return false; // Process unchanged or new data + if (!found) { return true; } // No command received + + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_DOMOTICZ D_RECEIVED_TOPIC " %s, " D_DATA " %s"), XdrvMailbox.topic, XdrvMailbox.data); + + domoticz_update_flag = false; + return false; // Process new data } /*********************************************************************************************/ diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index b26e5402d..04a6d3413 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -698,10 +698,10 @@ void RulesTeleperiod(void) */ bool RulesMqttData(void) { - bool serviced = false; if (XdrvMailbox.data_len < 1 || XdrvMailbox.data_len > 256) { return false; } + bool serviced = false; String sTopic = XdrvMailbox.topic; String sData = XdrvMailbox.data; //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: MQTT Topic %s, Event %s"), XdrvMailbox.topic, XdrvMailbox.data); diff --git a/sonoff/xdrv_interface.ino b/sonoff/xdrv_interface.ino index be9936c4d..ead58e613 100644 --- a/sonoff/xdrv_interface.ino +++ b/sonoff/xdrv_interface.ino @@ -847,16 +847,6 @@ void XsnsDriverState(void) /*********************************************************************************************/ -bool XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf) -{ - XdrvMailbox.index = stopicBuf; - XdrvMailbox.data_len = sdataBuf; - XdrvMailbox.topic = topicBuf; - XdrvMailbox.data = dataBuf; - - return XdrvCall(FUNC_MQTT_DATA); -} - bool XdrvRulesProcess(void) { return XdrvCallDriver(10, FUNC_RULES_PROCESS); From da2b2efae03cfd8504a70cd6aa76ada1ca8b5c0c Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Wed, 2 Oct 2019 13:38:05 +0200 Subject: [PATCH 20/46] update scripter hue without devices --- sonoff/support_udp.ino | 4 + sonoff/xdrv_10_scripter.ino | 185 ++++++++++++++++++++++++++++-------- sonoff/xdrv_20_hue.ino | 12 ++- 3 files changed, 159 insertions(+), 42 deletions(-) diff --git a/sonoff/support_udp.ino b/sonoff/support_udp.ino index 550e97b97..a33ca6973 100644 --- a/sonoff/support_udp.ino +++ b/sonoff/support_udp.ino @@ -85,7 +85,11 @@ void PollUdp(void) // AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("\n%s"), packet_buffer); // Simple Service Discovery Protocol (SSDP) +#ifdef USE_SCRIPT_HUE + if (!udp_response_mutex && (strstr_P(packet_buffer, PSTR("M-SEARCH")) != nullptr)) { +#else if (devices_present && !udp_response_mutex && (strstr_P(packet_buffer, PSTR("M-SEARCH")) != nullptr)) { +#endif udp_response_mutex = true; udp_remote_ip = PortUdp.remoteIP(); diff --git a/sonoff/xdrv_10_scripter.ino b/sonoff/xdrv_10_scripter.ino index ce0430f8f..4c12c6253 100644 --- a/sonoff/xdrv_10_scripter.ino +++ b/sonoff/xdrv_10_scripter.ino @@ -3366,30 +3366,8 @@ void ScriptSaveSettings(void) { #endif -#if defined(USE_WEBSERVER) && defined(USE_EMULATION) && defined(USE_EMULATION_HUE) && defined(USE_LIGHT) +#if defined(USE_SCRIPT_HUE) && defined(USE_WEBSERVER) && defined(USE_EMULATION) && defined(USE_EMULATION_HUE) && defined(USE_LIGHT) -/* -"state": { -"temperature": 2674, -"lastupdated": "2017-08-04T12:13:04" -}, -"config": { -"on": true, -"battery": 100, -"reachable": true, -"alert": "none", -"ledindication": false, -"usertest": false, -"pending": [] -}, -"name": "Hue temperature sensor 1", -"type": "ZLLTemperature", -"modelid": "SML001", -"manufacturername": "Philips", -"swversion": "6.1.0.18912", -"uniqueid": "xxx" -} -*/ #define HUE_DEV_MVNUM 5 #define HUE_DEV_NSIZE 16 @@ -3414,8 +3392,76 @@ const char SCRIPT_HUE_LIGHTS_STATUS_JSON1[] PROGMEM = "\"uniqueid\":\"{j2\"," "\"swversion\":\"5.50.1.19085\"}"; +/* +const char SCRIPT_HUE_LIGHTS_STATUS_JSON2[] PROGMEM = + "{\"state\":" + "{\"temperature\": 2674," + "\"lastupdated\": \"2019-08-04T12:13:04\"}," + "\"config\": {" + "\"on\": true," + "\"battery\": 100," + "\"reachable\": true," + "\"alert\": \"none\"," + "\"ledindication\": false," + "\"usertest\": false," + "\"pending\": []" + "}," + "\"name\": \"{j1\"," + "\"type\": \"ZLLTemperature\"," + "\"modelid\": \"SML001\"," + "\"manufacturername\": \"Philips\"," + "\"swversion\": \"6.1.0.18912\"," + "\"uniqueid\": \"{j2\"}"; +*/ + + +const char SCRIPT_HUE_LIGHTS_STATUS_JSON2[] PROGMEM = +"{\"state\":{" +"\"presence\":{state}," +"\"lastupdated\":\"2017-10-01T12:37:30\"" +"}," +"\"swupdate\":{" +"\"state\":\"noupdates\"," +"\"lastinstall\": null" +"}," +"\"config\":{" +"\"on\":true," +"\"battery\":100," +"\"reachable\":true," +"\"alert\":\"none\"," +"\"ledindication\":false," +"\"usertest\":false," +"\"sensitivity\":2," +"\"sensitivitymax\":2," +"\"pending\":[]" +"}," +"\"name\":\"{j1\"," +"\"type\":\"ZLLPresence\"," +"\"modelid\":\"SML001\"," +"\"manufacturername\":\"Philips\"," +"\"swversion\":\"6.1.0.18912\"," +"\"uniqueid\":\"{j2\"" +"}"; + +/* + temperature ZLLTemperature + lightlevel ZLLLightLevel + presence ZLLPresence + */ + + void Script_HueStatus(String *response, uint16_t hue_devs) { + + if (hue_script[hue_devs].type=='P') { + *response+=FPSTR(SCRIPT_HUE_LIGHTS_STATUS_JSON2); + response->replace("{j1",hue_script[hue_devs].name); + response->replace("{j2", GetHueDeviceId(hue_devs)); + uint8_t pwr=glob_script_mem.fvars[hue_script[hue_devs].index[0]-1]; + response->replace("{state}", (pwr ? "true" : "false")); + return; + } + *response+=FPSTR(SCRIPT_HUE_LIGHTS_STATUS_JSON1); uint8_t pwr=glob_script_mem.fvars[hue_script[hue_devs].index[0]-1]; response->replace("{state}", (pwr ? "true" : "false")); @@ -3454,16 +3500,44 @@ void Script_HueStatus(String *response, uint16_t hue_devs) { light_status += ","; } - response->replace("{light_status}", light_status); - response->replace("{j1",hue_script[hue_devs].name); - response->replace("{j2", GetHueDeviceId(hue_devs<<8)); - - if (hue_script[hue_devs].type=='E') { - response->replace("{type}","Extended color light"); - } else { - response->replace("{type}","color light"); + float temp; + switch (hue_script[hue_devs].type) { + case 'E': + response->replace("{type}","Extended color light"); + break; + case 'S': + response->replace("{type}","color light"); + break; + case 'T': + response->replace("{type}","ZLLTemperature"); + temp=glob_script_mem.fvars[hue_script[hue_devs].index[2]-1]; + light_status += "\"temperature\":"; + light_status += String(temp*100); + light_status += ","; + break; + case 'L': + response->replace("{type}","ZLLLightLevel"); + temp=glob_script_mem.fvars[hue_script[hue_devs].index[2]-1]; + light_status += "\"lightlevel\":"; + light_status += String(temp); + light_status += ","; + break; + case 'P': + response->replace("{type}","ZLLPresence"); + temp=glob_script_mem.fvars[hue_script[hue_devs].index[0]-1]; + light_status += "\"presence\":"; + if (temp==0)light_status += "false"; + else light_status += "true"; + light_status += ","; + break; + default: + response->replace("{type}","color light"); + break; } + response->replace("{light_status}", light_status); + response->replace("{j1",hue_script[hue_devs].name); + response->replace("{j2", GetHueDeviceId(hue_devs)); } @@ -3570,7 +3644,13 @@ void Script_Check_Hue(String *response) { } // append response if (response) { - *response+=",\""+String(EncodeLightId(hue_devs+devices_present+1))+"\":"; + if (devices_present) { + *response+=",\""; + } + else { + if (hue_devs>0) *response+=",\""; + } + *response+=String(EncodeLightId(hue_devs+devices_present+1))+"\":"; Script_HueStatus(response,hue_devs); } @@ -3584,16 +3664,22 @@ void Script_Check_Hue(String *response) { lp++; } } -#if 0 - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Hue: %d"), hue_devs); - toLog(">>>>"); - toLog(response->c_str()); - toLog(response->c_str()+LOGSZ); +#if 1 + if (response) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Hue: %d"), hue_devs); + toLog(">>>>"); + toLog(response->c_str()); + toLog(response->c_str()+LOGSZ); + } #endif } const char sHUE_LIGHT_RESPONSE_JSON[] PROGMEM = "{\"success\":{\"/lights/{id/state/{cm\":{re}}"; + +const char sHUE_SENSOR_RESPONSE_JSON[] PROGMEM = + "{\"success\":{\"/lights/{id/state/{cm\":{re}}"; + const char sHUE_ERROR_JSON[] PROGMEM = "[{\"error\":{\"type\":901,\"address\":\"/\",\"description\":\"Internal Error\"}}]"; @@ -3649,6 +3735,27 @@ void Script_Handle_Hue(String *path) { glob_script_mem.type[hue_script[index].vindex[1]].bits.changed=1; resp = true; } + if (hue_json.containsKey("xy")) { // Saturation of the light. 254 is the most saturated (colored) and 0 is the least saturated (white). + float x, y; + x = hue_json["xy"][0]; + y = hue_json["xy"][1]; + const String &x_str = hue_json["xy"][0]; + const String &y_str = hue_json["xy"][1]; + uint8_t rr,gg,bb; + LightStateClass::XyToRgb(x, y, &rr, &gg, &bb); + LightStateClass::RgbToHsb(rr, gg, bb, &hue, &sat, nullptr); + if (resp) { response += ","; } + response += FPSTR(sHUE_LIGHT_RESPONSE_JSON); + response.replace("{id", String(device)); + response.replace("{cm", "xy"); + response.replace("{re", "[" + x_str + "," + y_str + "]"); + glob_script_mem.fvars[hue_script[index].index[2]-1]=hue; + glob_script_mem.type[hue_script[index].vindex[2]].bits.changed=1; + glob_script_mem.fvars[hue_script[index].index[3]-1]=sat; + glob_script_mem.type[hue_script[index].vindex[3]].bits.changed=1; + resp = true; + } + if (hue_json.containsKey("hue")) { // The hue value is a wrapping value between 0 and 65535. Both 0 and 65535 are red, 25500 is green and 46920 is blue. tmp = hue_json["hue"]; //hue = changeUIntScale(tmp, 0, 65535, 0, 359); @@ -4067,7 +4174,7 @@ const char SCRIPT_MSG_BUTTONa_TBL[] PROGMEM = ""; const char SCRIPT_MSG_BUTTONb[] PROGMEM = - "<\img>"; + ""; const char SCRIPT_MSG_BUT_START[] PROGMEM = "
"; @@ -4437,7 +4544,9 @@ bool Xdrv10(uint8_t function) if (bitRead(Settings.rule_enabled, 0)) { Run_Scripter(">B",2,0); fast_script=Run_Scripter(">F",-2,0); +#if defined(USE_SCRIPT_HUE) && defined(USE_WEBSERVER) && defined(USE_EMULATION) && defined(USE_EMULATION_HUE) && defined(USE_LIGHT) Script_Check_Hue(0); +#endif } break; case FUNC_EVERY_100_MSECOND: diff --git a/sonoff/xdrv_20_hue.ino b/sonoff/xdrv_20_hue.ino index d39da9a4c..cd41a30ef 100644 --- a/sonoff/xdrv_20_hue.ino +++ b/sonoff/xdrv_20_hue.ino @@ -36,7 +36,7 @@ const char HUE_RESPONSE[] PROGMEM = "CACHE-CONTROL: max-age=100\r\n" "EXT:\r\n" "LOCATION: http://%s:80/description.xml\r\n" - "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/1.17.0\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/1.24.0\r\n" // was 1.17 "hue-bridgeid: %s\r\n"; const char HUE_ST1[] PROGMEM = "ST: upnp:rootdevice\r\n" @@ -503,7 +503,7 @@ void HueLights(String *path) response += ",\""; } } -#ifdef USE_SCRIPT +#ifdef USE_SCRIPT_HUE Script_Check_Hue(&response); #endif response += "}"; @@ -513,7 +513,7 @@ void HueLights(String *path) path->remove(path->indexOf("/state")); // Remove /state device = DecodeLightId(atoi(path->c_str())); -#ifdef USE_SCRIPT +#ifdef USE_SCRIPT_HUE if (device>devices_present) { return Script_Handle_Hue(path); } @@ -706,7 +706,7 @@ void HueLights(String *path) path->remove(0,8); // Remove /lights/ device = DecodeLightId(atoi(path->c_str())); -#ifdef USE_SCRIPT +#ifdef USE_SCRIPT_HUE if (device>devices_present) { Script_HueStatus(&response,device-devices_present-1); goto exit; @@ -799,7 +799,11 @@ bool Xdrv20(uint8_t function) { bool result = false; +#ifdef USE_SCRIPT_HUE + if ((EMUL_HUE == Settings.flag2.emulation)) { +#else if (devices_present && (EMUL_HUE == Settings.flag2.emulation)) { +#endif switch (function) { case FUNC_WEB_ADD_HANDLER: WebServer->on("/description.xml", HandleUpnpSetupHue); From 8c34b9edbd9efc3405c1c29324e347f6accd8de1 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 2 Oct 2019 16:45:53 +0200 Subject: [PATCH 21/46] Change command handling * Change command SetOption43 to make it more general. Now supports PS_16_DZ driver too (#6547) * Change command handling by moving buffers up in chain solving MQTTlog support (#6524) * Change detection of non-MQTT commands by allowing non-space characters as delimiter (#6540) --- sonoff/_changelog.ino | 3 ++ sonoff/support_command.ino | 73 ++++++++++++++++++++------------------ sonoff/xdrv_02_mqtt.ino | 17 +++++---- 3 files changed, 53 insertions(+), 40 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 9139cb622..8345f9e52 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -8,6 +8,9 @@ * Add command to MCP230xx: sensor29 pin,0/1/2 for OFF/ON/TOGGLE * Add initial support for PCF8574 I2C I/O Expander (currently output only) by Stefan Bode * Add command SetOption71 0/1 to switch between different Modbus Active Energy registers on DDS238-2 energy meters (#6531) + * Change command SetOption43 to make it more general. Now supports PS_16_DZ driver too (#6547) + * Change command handling by moving buffers up in chain solving MQTTlog support (#6524) + * Change detection of non-MQTT commands by allowing non-space characters as delimiter (#6540) * * 6.6.0.13 20190922 * Add command EnergyReset4 x,x to initialize total usage for two tarrifs diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index 9e2fd5fcb..182796519 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -81,55 +81,61 @@ void ResponseCmndIdxChar(const char* value) /********************************************************************************************/ -void ExecuteCommand(char *cmnd, uint32_t source) +void ExecuteCommand(const char *cmnd, uint32_t source) { - char *start; - char *token; - + // cmnd: "status 0" = stopic "status" and svalue " 0" + // cmnd: "var1 =1" = stopic "var1" and svalue " =1" + // cmnd: "var1=1" = stopic "var1" and svalue "=1" #ifdef USE_DEBUG_DRIVER ShowFreeMem(PSTR("ExecuteCommand")); #endif ShowSource(source); - token = strtok(cmnd, " "); - if (token != nullptr) { - start = strrchr(token, '/'); // Skip possible cmnd/sonoff/ preamble - if (start) { token = start +1; } + const char *pos = cmnd; + while (*pos && isspace(*pos)) { + pos++; // Skip all spaces } - uint32_t size = (token != nullptr) ? strlen(token) : 0; - char stopic[size +2]; // / + \0 - snprintf_P(stopic, sizeof(stopic), PSTR("/%s"), (token == nullptr) ? "" : token); - token = strtok(nullptr, ""); - size = (token != nullptr) ? strlen(token) : 0; - char svalue[size +1]; - strlcpy(svalue, (token == nullptr) ? "" : token, sizeof(svalue)); // Fixed 5.8.0b - CommandHandler(stopic, (uint8_t*)svalue, strlen(svalue)); + const char *start = pos; + // Get a command. Commands can only use letters, digits and underscores + while (*pos && (isalpha(*pos) || isdigit(*pos) || '_' == *pos || '/' == *pos)) { + if ('/' == *pos) { // Skip possible cmnd/sonoff/ preamble + start = pos + 1; + } + pos++; + } + if ('\0' == *start || pos <= start) { + return; // Did not find any command to execute + } + + uint32_t size = pos - start; + char stopic[size + 2]; // with leader '/' and end '\0' + stopic[0] = '/'; + memcpy(stopic+1, start, size); + stopic[size+1] = '\0'; + + char svalue[strlen(pos) +1]; // pos point to the start of parameters + strlcpy(svalue, pos, sizeof(svalue)); + CommandHandler(stopic, svalue, strlen(svalue)); } /********************************************************************************************/ -// topic: /power1 data: toggle = Console command -// topic: cmnd/sonoff/power1 data: toggle = Mqtt command using topic -// topic: cmnd/sonoffs/power1 data: toggle = Mqtt command using a group topic -// topic: cmnd/DVES_83BB10_fb/power1 data: toggle = Mqtt command using fallback topic +// topicBuf: /power1 dataBuf: toggle = Console command +// topicBuf: cmnd/sonoff/power1 dataBuf: toggle = Mqtt command using topic +// topicBuf: cmnd/sonoffs/power1 dataBuf: toggle = Mqtt command using a group topic +// topicBuf: cmnd/DVES_83BB10_fb/power1 dataBuf: toggle = Mqtt command using fallback topic -void CommandHandler(char* topic, uint8_t* data, uint32_t data_len) +void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) { #ifdef USE_DEBUG_DRIVER ShowFreeMem(PSTR("CommandHandler")); #endif - char topicBuf[TOPSZ]; - strlcpy(topicBuf, topic, sizeof(topicBuf)); - - uint32_t i = 0; - for (i = 0; i < data_len; i++) { - if (!isspace(data[i])) { break; } // Skip leading spaces in data + while (*dataBuf && isspace(*dataBuf)) { + dataBuf++; // Skip leading spaces in data + data_len--; } - data_len -= i; - char dataBuf[data_len+1]; - memcpy(dataBuf, data +i, sizeof(dataBuf)); bool grpflg = (strstr(topicBuf, Settings.mqtt_grptopic) != nullptr); @@ -137,8 +143,9 @@ void CommandHandler(char* topic, uint8_t* data, uint32_t data_len) GetFallbackTopic_P(stemp1, CMND, ""); // Full Fallback topic = cmnd/DVES_xxxxxxxx_fb/ fallback_topic_flag = (!strncmp(topicBuf, stemp1, strlen(stemp1))); - char *type = strrchr(topicBuf, '/'); // Last part of received topic is always the command (type) + char *type = strrchr(topicBuf, '/'); // Last part of received topic is always the command (type) + uint32_t i = 0; uint32_t index = 1; bool user_index = false; if (type != nullptr) { @@ -156,7 +163,7 @@ void CommandHandler(char* topic, uint8_t* data, uint32_t data_len) type[i] = '\0'; } - DEBUG_CORE_LOG(PSTR("CMD: " D_GROUP " %d, " D_INDEX " %d, " D_COMMAND " \"%s\", " D_DATA " \"%s\""), grpflg, index, type, dataBuf); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("CMD: " D_GROUP " %d, " D_INDEX " %d, " D_COMMAND " \"%s\", " D_DATA " \"%s\""), grpflg, index, type, dataBuf); if (type != nullptr) { Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"}")); @@ -686,11 +693,9 @@ void CmndSetoption(void) IrReceiveUpdateThreshold(); break; #endif -#ifdef USE_TUYA_MCU case P_DIMMER_MAX: restart_flag = 2; // Need a restart to update GUI break; -#endif } } } diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino index 81fd45b6f..edc844448 100644 --- a/sonoff/xdrv_02_mqtt.ino +++ b/sonoff/xdrv_02_mqtt.ino @@ -251,7 +251,7 @@ bool MqttPublishLib(const char* topic, bool retained) return result; } -void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) +void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len) { #ifdef USE_DEBUG_DRIVER ShowFreeMem(PSTR("MqttDataHandler")); @@ -262,8 +262,8 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) // Do not execute multiple times if Prefix1 equals Prefix2 if (!strcmp(Settings.mqtt_prefix[0], Settings.mqtt_prefix[1])) { - char *str = strstr(topic, Settings.mqtt_prefix[0]); - if ((str == topic) && mqtt_cmnd_publish) { + char *str = strstr(mqtt_topic, Settings.mqtt_prefix[0]); + if ((str == mqtt_topic) && mqtt_cmnd_publish) { if (mqtt_cmnd_publish > 3) { mqtt_cmnd_publish -= 3; } else { @@ -273,10 +273,15 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) } } - data[data_len] = 0; + // Save MQTT data ASAP as it's data is discarded by PubSubClient with next publish as used in MQTTlog + char topic[TOPSZ]; + strlcpy(topic, mqtt_topic, sizeof(topic)); + mqtt_data[data_len] = 0; + char data[data_len +1]; + memcpy(data, mqtt_data, sizeof(data)); - AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_RECEIVED_TOPIC " %s, " D_DATA_SIZE " %d, " D_DATA " %s"), topic, data_len, data); -// if (LOG_LEVEL_DEBUG_MORE <= seriallog_level) { Serial.println(dataBuf); } + AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_MQTT D_RECEIVED_TOPIC " \"%s\", " D_DATA_SIZE " %d, " D_DATA " \"%s\""), topic, data_len, data); +// if (LOG_LEVEL_DEBUG_MORE <= seriallog_level) { Serial.println(data); } // MQTT pre-processing XdrvMailbox.index = strlen(topic); From 3e7e882ee5a9ad774daae77b18e54d2f59898a5d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 2 Oct 2019 17:20:03 +0200 Subject: [PATCH 22/46] Update TasmotaSerial.cpp --- lib/TasmotaSerial-2.4.1/src/TasmotaSerial.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/TasmotaSerial-2.4.1/src/TasmotaSerial.cpp b/lib/TasmotaSerial-2.4.1/src/TasmotaSerial.cpp index 0a1386375..ebce5a496 100644 --- a/lib/TasmotaSerial-2.4.1/src/TasmotaSerial.cpp +++ b/lib/TasmotaSerial-2.4.1/src/TasmotaSerial.cpp @@ -218,6 +218,7 @@ int TasmotaSerial::available() #define TM_SERIAL_WAIT_RCV_LOOP { while (ESP.getCycleCount() < (wait + start)); } #else #define TM_SERIAL_WAIT_SND { while (ESP.getCycleCount() < (wait + start)); wait += m_bit_time; } +#define TM_SERIAL_WAIT_SND_FAST { while (ESP.getCycleCount() < (wait + start)); wait += m_bit_time; } #define TM_SERIAL_WAIT_RCV { while (ESP.getCycleCount() < (wait + start)); wait += m_bit_time; } #define TM_SERIAL_WAIT_RCV_LOOP { while (ESP.getCycleCount() < (wait + start)); } #endif From bc55237154061d22677a01e8ef66235780579ae1 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 2 Oct 2019 17:39:27 +0200 Subject: [PATCH 23/46] Fix domoticz core 2.3.0 compilation error Fix domoticz core 2.3.0 compilation error --- sonoff/_changelog.ino | 4 ++-- sonoff/xdrv_07_domoticz.ino | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 98b13e80e..ac8e7a1b0 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -8,8 +8,8 @@ * Add command to MCP230xx: sensor29 pin,0/1/2 for OFF/ON/TOGGLE * Add initial support for PCF8574 I2C I/O Expander (currently output only) by Stefan Bode * Add command SetOption71 0/1 to switch between different Modbus Active Energy registers on DDS238-2 energy meters (#6531) - * Change command SetOption43 to make it more general. Now supports PS_16_DZ driver too (#6547) - * Change command handling by moving buffers up in chain solving MQTTlog support (#6524) + * Change command SetOption43 to make it more general. Now supports PS_16_DZ driver too (#6544) + * Change command handling by moving buffers up in chain solving MQTTlog support (#6529) * Change detection of non-MQTT commands by allowing non-space characters as delimiter (#6540) * Fix TasmotaSerial: move serial send to IRAM for high speed baud rates * diff --git a/sonoff/xdrv_07_domoticz.ino b/sonoff/xdrv_07_domoticz.ino index 0bdc22b83..e4f1b5ca1 100644 --- a/sonoff/xdrv_07_domoticz.ino +++ b/sonoff/xdrv_07_domoticz.ino @@ -45,7 +45,6 @@ const char kDomoticzSensors[] PROGMEM = D_DOMOTICZ_COUNT "|" D_DOMOTICZ_VOLTAGE "|" D_DOMOTICZ_CURRENT "|" D_DOMOTICZ_AIRQUALITY "|" D_DOMOTICZ_P1_SMART_METER "|" D_DOMOTICZ_SHUTTER ; char domoticz_in_topic[] = DOMOTICZ_IN_TOPIC; -char domoticz_out_topic[] = DOMOTICZ_OUT_TOPIC; int domoticz_update_timer = 0; uint32_t domoticz_fan_debounce = 0; // iFan02 state debounce timer @@ -166,7 +165,7 @@ void DomoticzMqttSubscribe(void) } if (domoticz_subscribe) { char stopic[TOPSZ]; - snprintf_P(stopic, sizeof(stopic), PSTR("%s/#"), domoticz_out_topic); // domoticz topic + snprintf_P(stopic, sizeof(stopic), PSTR(DOMOTICZ_OUT_TOPIC "/#")); // domoticz topic MqttSubscribe(stopic); } } @@ -201,7 +200,7 @@ bool DomoticzMqttData(void) { domoticz_update_flag = true; - if (strncasecmp(XdrvMailbox.topic, domoticz_out_topic, strlen(domoticz_out_topic)) != 0) { + if (strncasecmp_P(XdrvMailbox.topic, PSTR(DOMOTICZ_OUT_TOPIC), strlen(DOMOTICZ_OUT_TOPIC)) != 0) { return false; // Process unchanged data } From 4eef80e4d9689f2a37b068df559af4c7df707a4a Mon Sep 17 00:00:00 2001 From: Federico Leoni Date: Wed, 2 Oct 2019 13:16:14 -0300 Subject: [PATCH 24/46] Update xdrv_12_home_assistant.ino --- sonoff/xdrv_12_home_assistant.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/xdrv_12_home_assistant.ino b/sonoff/xdrv_12_home_assistant.ino index 538c25e06..3d887bde1 100644 --- a/sonoff/xdrv_12_home_assistant.ino +++ b/sonoff/xdrv_12_home_assistant.ino @@ -347,7 +347,7 @@ void HAssAnnounceSwitches(void) // Send info about buttons char *tmp = Settings.switch_topic; Format(sw_topic, tmp, sizeof(sw_topic)); - if ((strlen(sw_topic) != 0) && strcmp(sw_topic, "0")) { + if (strlen(sw_topic) != 0) { for (uint32_t switch_index = 0; switch_index < MAX_SWITCHES; switch_index++) { uint8_t switch_present = 0; uint8_t toggle = 1; @@ -376,7 +376,7 @@ void HAssAnnounceButtons(void) // Send info about buttons char *tmp = Settings.button_topic; Format(key_topic, tmp, sizeof(key_topic)); - if ((strlen(key_topic) != 0) && strcmp(key_topic, "0")) { + if (strlen(key_topic) != 0) { for (uint32_t button_index = 0; button_index < MAX_KEYS; button_index++) { uint8_t button_present = 0; uint8_t toggle = 1; From 11d4cd9058770e0edd8ac01711881ae08b64b58e Mon Sep 17 00:00:00 2001 From: Federico Leoni Date: Wed, 2 Oct 2019 16:58:52 -0300 Subject: [PATCH 25/46] Update my_user_config.h --- sonoff/my_user_config.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index cd82cea53..2310df0d2 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -66,8 +66,9 @@ #define STA_PASS1 "" // [Password1] Wifi password #define STA_SSID2 "" // [Ssid2] Optional alternate AP Wifi SSID #define STA_PASS2 "" // [Password2] Optional alternate AP Wifi password -#define WIFI_CONFIG_TOOL WIFI_RETRY // [WifiConfig] Default tool if wifi fails to connect - // (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL) +#define WIFI_CONFIG_TOOL WIFI_RETRY // [WifiConfig] Default tool if wifi fails to connect (default option: 4 - WIFI_RETRY) + // (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, WIFI_MANAGER_RESET_ONLY) + // The configuration can be changed after first setup using WifiConfig 0, 1, 2, 3, 4, 5, 6 and 7. #define WIFI_CONFIG_NO_SSID WIFI_WPSCONFIG // Default tool if wifi fails to connect and no SSID is configured // (WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_SERIAL) // *** NOTE: When WPS is disabled by USE_WPS below, WIFI_WPSCONFIG will execute WIFI_MANAGER *** From 913a80924293ffe7a0f49378bd0f1e95ce3707e4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 3 Oct 2019 09:58:23 +0200 Subject: [PATCH 26/46] Bump version 6.6.0.15 Bump version 6.6.0.15 --- sonoff/_changelog.ino | 2 ++ sonoff/sonoff_version.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index ac8e7a1b0..13a994061 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,6 @@ /*********************************************************************************************\ + * 6.6.0.15 20191003 + * * 6.6.0.14 20190925 * Change command Tariffx to allow time entries like 23 (hours), 1320 (minutes) or 23:00. NOTE: As this is development branch previous tariffs are lost! (#6488) * Remove support for define USE_DS18x20_LEGACY and legacy DS18x20 driver (#6486) diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 02af08bab..51d92d944 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,6 +20,6 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -const uint32_t VERSION = 0x0606000E; +const uint32_t VERSION = 0x0606000F; #endif // _SONOFF_VERSION_H_ From cbb3f9e0af6e163cebf18a29c4d011281743db23 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 3 Oct 2019 10:02:57 +0200 Subject: [PATCH 27/46] Change command PulseTime JSON message Change command PulseTime JSON message format and allow display of all pulsetimer information (#6519) --- sonoff/_changelog.ino | 1 + sonoff/i18n.h | 3 ++- sonoff/support_command.ino | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 13a994061..e9cdf437d 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,5 +1,6 @@ /*********************************************************************************************\ * 6.6.0.15 20191003 + * Change command PulseTime JSON message format and allow display of all pulsetimer information (#6519) * * 6.6.0.14 20190925 * Change command Tariffx to allow time entries like 23 (hours), 1320 (minutes) or 23:00. NOTE: As this is development branch previous tariffs are lost! (#6488) diff --git a/sonoff/i18n.h b/sonoff/i18n.h index 5dae197a6..089140dd9 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -118,6 +118,7 @@ #define D_JSON_PROGRAMFLASHSIZE "ProgramFlashSize" #define D_JSON_PROGRAMSIZE "ProgramSize" #define D_JSON_REFERENCETEMPERATURE "ReferenceTemperature" +#define D_JSON_REMAINING "Remaining" #define D_JSON_RESET "Reset" #define D_JSON_RESISTANCE "Resistance" #define D_JSON_RESOLUTION "Resolution" @@ -132,6 +133,7 @@ #define D_JSON_SDKVERSION "SDK" #define D_JSON_SELECTED "selected" #define D_JSON_SERIALRECEIVED "SerialReceived" +#define D_JSON_SET "Set" #define D_JSON_SSID "SSId" #define D_JSON_STARTDST "StartDST" // Start Daylight Savings Time #define D_JSON_STARTED "Started" @@ -557,7 +559,6 @@ const char S_JSON_COMMAND_INDEX_LVALUE[] PROGMEM = "{\"%s%d\":%lu}"; const char S_JSON_COMMAND_INDEX_SVALUE[] PROGMEM = "{\"%s%d\":\"%s\"}"; const char S_JSON_COMMAND_INDEX_ASTERISK[] PROGMEM = "{\"%s%d\":\"" D_ASTERISK_PWD "\"}"; const char S_JSON_COMMAND_INDEX_SVALUE_SVALUE[] PROGMEM = "{\"%s%d\":\"%s%s\"}"; -const char S_JSON_COMMAND_INDEX_NVALUE_ACTIVE_NVALUE[] PROGMEM = "{\"%s%d\":{\"%d\":{\"" D_JSON_ACTIVE "\":\"%d\"}}}"; const char S_JSON_SENSOR_INDEX_NVALUE[] PROGMEM = "{\"" D_CMND_SENSOR "%d\":%d}"; const char S_JSON_SENSOR_INDEX_SVALUE[] PROGMEM = "{\"" D_CMND_SENSOR "%d\":\"%s\"}"; diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index 182796519..4683c7c85 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -565,11 +565,23 @@ void CmndPowerOnState(void) void CmndPulsetime(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_PULSETIMERS)) { - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) { - Settings.pulse_timer[XdrvMailbox.index -1] = XdrvMailbox.payload; // 0 - 65535 - SetPulseTimer(XdrvMailbox.index -1, XdrvMailbox.payload); + uint32_t items = 1; + if (!XdrvMailbox.usridx) { + items = MAX_PULSETIMERS; + } else { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) { + Settings.pulse_timer[XdrvMailbox.index -1] = XdrvMailbox.payload; // 0 - 65535 + SetPulseTimer(XdrvMailbox.index -1, XdrvMailbox.payload); + } } - Response_P(S_JSON_COMMAND_INDEX_NVALUE_ACTIVE_NVALUE, XdrvMailbox.command, XdrvMailbox.index, Settings.pulse_timer[XdrvMailbox.index -1], GetPulseTimer(XdrvMailbox.index -1)); + mqtt_data[0] = '\0'; + for (uint32_t i = 0; i < items; i++) { + ResponseAppend_P(PSTR("%c\"%s%d\":{\"" D_JSON_SET "\":%d,\"" D_JSON_REMAINING "\":%d}"), + (i) ? ',' : '{', + XdrvMailbox.command, (1 == items) ? XdrvMailbox.index : i +1, + Settings.pulse_timer[XdrvMailbox.index -1], GetPulseTimer(XdrvMailbox.index -1)); + } + ResponseJsonEnd(); } } From 9e711095490eb70f07ad0623195710f88e71eee4 Mon Sep 17 00:00:00 2001 From: pablozg Date: Thu, 3 Oct 2019 10:06:51 +0200 Subject: [PATCH 28/46] add support to chint ddsu666 --- sonoff/language/bg-BG.h | 2 + sonoff/language/cs-CZ.h | 2 + sonoff/language/de-DE.h | 2 + sonoff/language/el-GR.h | 2 + sonoff/language/en-GB.h | 2 + sonoff/language/es-ES.h | 2 + sonoff/language/fr-FR.h | 2 + sonoff/language/he-HE.h | 2 + sonoff/language/hu-HU.h | 2 + sonoff/language/it-IT.h | 2 + sonoff/language/ko-KO.h | 2 + sonoff/language/nl-NL.h | 2 + sonoff/language/pl-PL.h | 2 + sonoff/language/pt-BR.h | 2 + sonoff/language/pt-PT.h | 2 + sonoff/language/ru-RU.h | 2 + sonoff/language/sk-SK.h | 2 + sonoff/language/sv-SE.h | 2 + sonoff/language/tr-TR.h | 2 + sonoff/language/uk-UK.h | 2 + sonoff/language/zh-CN.h | 2 + sonoff/language/zh-TW.h | 2 + sonoff/my_user_config.h | 2 + sonoff/sonoff_post.h | 6 ++ sonoff/sonoff_template.h | 7 ++ sonoff/support_features.ino | 4 +- sonoff/xnrg_11_ddsu666.ino | 175 ++++++++++++++++++++++++++++++++++++ tools/decode-status.py | 2 +- 28 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 sonoff/xnrg_11_ddsu666.ino diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index b7080f2ca..43792cdb3 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index d413910b3..1067a6f02 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index 71c4a1de1..fe6067153 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 3b6f5edcc..3c43b65c6 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index af4ba7b64..27ef1e342 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/es-ES.h b/sonoff/language/es-ES.h index 239542068..252f72ce3 100644 --- a/sonoff/language/es-ES.h +++ b/sonoff/language/es-ES.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index 3216932ee..1c8eb4eec 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/he-HE.h b/sonoff/language/he-HE.h index 5fdcc93e3..b551de296 100644 --- a/sonoff/language/he-HE.h +++ b/sonoff/language/he-HE.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index 0bcb1da05..81f1d080a 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index f1183d090..1c6390cc2 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/ko-KO.h b/sonoff/language/ko-KO.h index 5b99924bb..0f628e04e 100644 --- a/sonoff/language/ko-KO.h +++ b/sonoff/language/ko-KO.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index b8b0c1e88..d79a419b2 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index d3a7712b9..8e374437f 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index 209738d81..831d79d03 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index f9debe83b..970fb2b8a 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index 7306b1820..474d7f254 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "А" diff --git a/sonoff/language/sk-SK.h b/sonoff/language/sk-SK.h index d462ecfac..092661890 100644 --- a/sonoff/language/sk-SK.h +++ b/sonoff/language/sk-SK.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/sv-SE.h b/sonoff/language/sv-SE.h index a903db1f9..16d5110be 100644 --- a/sonoff/language/sv-SE.h +++ b/sonoff/language/sv-SE.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/tr-TR.h b/sonoff/language/tr-TR.h index 7e23b9d4d..e17623637 100755 --- a/sonoff/language/tr-TR.h +++ b/sonoff/language/tr-TR.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h index dd694ff85..92b3711fd 100644 --- a/sonoff/language/uk-UK.h +++ b/sonoff/language/uk-UK.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "А" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index 8b1464b33..872c13563 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "安" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index 8fa61ed9e..4d26109fa 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -617,6 +617,8 @@ #define D_SENSOR_A4988_MS3 "A4988 MS3" #define D_SENSOR_DDS2382_TX "DDS238-2 Tx" #define D_SENSOR_DDS2382_RX "DDS238-2 Rx" +#define D_SENSOR_DDSU666_TX "DDSU666 Tx" +#define D_SENSOR_DDSU666_RX "DDSU666 Rx" // Units #define D_UNIT_AMPERE "安" diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 2310df0d2..e13a666e5 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -447,6 +447,8 @@ //#define USE_SOLAX_X1 // Add support for Solax X1 series Modbus log info (+4k1 code) #define SOLAXX1_SPEED 9600 // Solax X1 Modbus RS485 serial speed (default: 9600 baud) #define SOLAXX1_PV2 // Solax X1 using second PV +//#define USE_DDSU666 // Add support for Chint DDSU666 Modbus energy monitor (+0k6 code) + #define DDSU666_SPEED 9600 // Chint DDSU666 Modbus RS485 serial speed (default: 9600 baud) // -- Low level interface devices ----------------- #define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor (1k6 code) diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h index 3a792f569..eceb972a0 100644 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -165,6 +165,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #define USE_SDM120_2 // Add support for Eastron SDM120-Modbus energy monitor (+1k1 code) #define USE_SDM630_2 // Add support for Eastron SDM630-Modbus energy monitor (+0k6 code) #define USE_DDS2382 // Add support for Hiking DDS2382 Modbus energy monitor (+0k6 code) +#define USE_DDSU666 // Add support for Chint DDSU666 Modbus energy monitor (+0k6 code) #define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor #define USE_MAX31855 // Add support for MAX31855 K-Type thermocouple sensor using softSPI @@ -251,6 +252,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #undef USE_SDM120_2 // Disable support for Eastron SDM120-Modbus energy meter #undef USE_SDM630_2 // Disable support for Eastron SDM630-Modbus energy monitor (+0k6 code) #undef USE_DDS2382 // Disable support for Hiking DDS2382 Modbus energy monitor (+0k6 code) +#undef USE_DDSU666 // Disable support for Chint DDSU666 Modbus energy monitor (+0k6 code) #define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor #undef USE_MAX31855 // Disable MAX31855 K-Type thermocouple sensor using softSPI @@ -305,6 +307,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #undef USE_SDM120_2 // Disable support for Eastron SDM120-Modbus energy meter #undef USE_SDM630_2 // Disable support for Eastron SDM630-Modbus energy monitor (+0k6 code) #undef USE_DDS2382 // Disable support for Hiking DDS2382 Modbus energy monitor (+0k6 code) + #undef USE_DDSU666 // Disable support for Chint DDSU666 Modbus energy monitor (+0k6 code) #undef USE_EMULATION // Disable Belkin WeMo and Hue Bridge emulation for Alexa (-16k code, -2k mem) #undef USE_DOMOTICZ // Disable Domoticz #undef USE_HOME_ASSISTANT // Disable Home Assistant @@ -388,6 +391,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #undef USE_SDM120_2 // Disable support for Eastron SDM120-Modbus energy meter #undef USE_SDM630_2 // Disable support for Eastron SDM630-Modbus energy monitor (+0k6 code) #undef USE_DDS2382 // Disable support for Hiking DDS2382 Modbus energy monitor (+0k6 code) +#undef USE_DDSU666 // Disable support for Chint DDSU666 Modbus energy monitor (+0k6 code) //#define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor #undef USE_MAX31855 // Disable MAX31855 K-Type thermocouple sensor using softSPI @@ -484,6 +488,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #undef USE_SDM120_2 // Disable support for Eastron SDM120-Modbus energy meter #undef USE_SDM630_2 // Disable support for Eastron SDM630-Modbus energy monitor (+0k6 code) #undef USE_DDS2382 // Disable support for Hiking DDS2382 Modbus energy monitor (+0k6 code) +#undef USE_DDSU666 // Disable support for Chint DDSU666 Modbus energy monitor (+0k6 code) #undef USE_DHT // Disable support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor #undef USE_MAX31855 // Disable MAX31855 K-Type thermocouple sensor using softSPI @@ -568,6 +573,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c #undef USE_SDM120_2 // Disable support for Eastron SDM120-Modbus energy meter #undef USE_SDM630_2 // Disable support for Eastron SDM630-Modbus energy monitor (+0k6 code) #undef USE_DDS2382 // Disable support for Hiking DDS2382 Modbus energy monitor (+0k6 code) +#undef USE_DDSU666 // Disable support for Chint DDSU666 Modbus energy monitor (+0k6 code) #undef USE_DHT // Disable support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor #undef USE_MAX31855 // Disable MAX31855 K-Type thermocouple sensor using softSPI diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index e0f3c6e06..6781e607f 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -202,6 +202,8 @@ enum UserSelectablePins { GPIO_A4988_MS3, // A4988 microstep pin3 GPIO_DDS2382_TX, // DDS2382 Serial interface GPIO_DDS2382_RX, // DDS2382 Serial interface + GPIO_DDSU666_TX, // DDSU666 Serial interface + GPIO_DDSU666_RX, // DDSU666 Serial interface GPIO_SENSOR_END }; // Programmer selectable GPIO functionality @@ -277,6 +279,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_IBEACON_TX "|" D_SENSOR_IBEACON_RX "|" D_SENSOR_A4988_DIR "|" D_SENSOR_A4988_STP "|" D_SENSOR_A4988_ENA "|" D_SENSOR_A4988_MS1 "|" D_SENSOR_A4988_MS2 "|" D_SENSOR_A4988_MS3 "|" D_SENSOR_DDS2382_TX "|" D_SENSOR_DDS2382_RX "|" + D_SENSOR_DDSU666_TX "|" D_SENSOR_DDSU666_RX "|" ; // User selectable ADC0 functionality @@ -645,6 +648,10 @@ const uint8_t kGpioNiceList[] PROGMEM = { GPIO_SOLAXX1_TX, // Solax Inverter tx pin GPIO_SOLAXX1_RX, // Solax Inverter rx pin #endif +#ifdef USE_DDSU666 + GPIO_DDSU666_TX, // DDSU666 Serial interface + GPIO_DDSU666_RX, // DDSU666 Serial interface +#endif // USE_DDSU666 #ifdef USE_SERIAL_BRIDGE GPIO_SBR_TX, // Serial Bridge Serial interface diff --git a/sonoff/support_features.ino b/sonoff/support_features.ino index 999850db3..30403e6c3 100644 --- a/sonoff/support_features.ino +++ b/sonoff/support_features.ino @@ -459,7 +459,9 @@ void GetFeatures(void) #ifdef USE_PCF8574 feature5 |= 0x00000200; // Xdrv_028_pcf8574.ino #endif -// feature5 |= 0x00000400; +#ifdef USE_DDSU666 + feature5 |= 0x00000400; // Xnrg_11_ddsu666.ino +#endif // feature5 |= 0x00000800; // feature5 |= 0x00001000; diff --git a/sonoff/xnrg_11_ddsu666.ino b/sonoff/xnrg_11_ddsu666.ino new file mode 100644 index 000000000..2f6dfbf36 --- /dev/null +++ b/sonoff/xnrg_11_ddsu666.ino @@ -0,0 +1,175 @@ +/* + xnrg_11_ddsu666.ino - Chint DDSU666-Modbus energy meter support for Sonoff-Tasmota + + Copyright (C) 2019 Pablo Zerón and Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_ENERGY_SENSOR +#ifdef USE_DDSU666 +/*********************************************************************************************\ + * Chint DDSU666 Modbus energy meter +\*********************************************************************************************/ + +#define XNRG_11 11 + +// can be user defined in my_user_config.h +#ifndef DDSU666_SPEED + #define DDSU666_SPEED 9600 // default DDSU66 Modbus address +#endif +// can be user defined in my_user_config.h +#ifndef DDSU666_ADDR + #define DDSU666_ADDR 1 // default DDSU66 Modbus address +#endif + +#include +TasmotaModbus *Ddsu666Modbus; + +const uint16_t Ddsu666_start_addresses[] { + 0x2000, // DDSU666_VOLTAGE [V] + 0x2002, // DDSU666_CURRENT [A] + 0x2004, // DDSU666_POWER [KW] + 0x2006, // DDSU666_REACTIVE_POWER [KVAR] + 0x200A, // DDSU666_POWER_FACTOR + 0x200E, // DDSU666_FREQUENCY [Hz] + 0X4000, // DDSU666_IMPORT_ACTIVE [kWh] + 0X400A, // DDSU666_EXPORT_ACTIVE [kWh] +}; + +struct DDSU666 { + float import_active = NAN; + uint8_t read_state = 0; + uint8_t send_retry = 0; +} Ddsu666; + +/*********************************************************************************************/ + +void DDSU666Every250ms(void) +{ + bool data_ready = Ddsu666Modbus->ReceiveReady(); + + if (data_ready) { + uint8_t buffer[14]; // At least 5 + (2 * 2) = 9 + + uint32_t error = Ddsu666Modbus->ReceiveBuffer(buffer, 2); + AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, Ddsu666Modbus->ReceiveCount()); + + if (error) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SDM: Ddsu666 error %d"), error); + } else { + Energy.data_valid[0] = 0; + + // 0 1 2 3 4 5 6 7 8 + // SA FC BC Fh Fl Sh Sl Cl Ch + // 01 04 04 43 66 33 34 1B 38 = 230.2 Volt + float value; + ((uint8_t*)&value)[3] = buffer[3]; // Get float values + ((uint8_t*)&value)[2] = buffer[4]; + ((uint8_t*)&value)[1] = buffer[5]; + ((uint8_t*)&value)[0] = buffer[6]; + + switch(Ddsu666.read_state) { + case 0: + Energy.voltage[0] = value; // 230.2 V + break; + + case 1: + Energy.current[0] = value; // 1.260 A + break; + + case 2: + Energy.active_power[0] = value * 1000; // -196.3 W + break; + + case 3: + Energy.reactive_power[0] = value * 1000; // 92.2 + break; + + case 4: + Energy.power_factor[0] = value; // 0.91 + break; + + case 5: + Energy.frequency[0] = value; // 50.0 Hz + break; + + case 6: + Ddsu666.import_active = value; // 478.492 kWh + break; + + case 7: + Energy.export_active = value; // 6.216 kWh + break; + } + + Ddsu666.read_state++; + + if (Ddsu666.read_state == 8) { + Ddsu666.read_state = 0; + EnergyUpdateTotal(Ddsu666.import_active, true); // 484.708 kWh + } + } + } // end data ready + + if (0 == Ddsu666.send_retry || data_ready) { + Ddsu666.send_retry = 5; + Ddsu666Modbus->Send(DDSU666_ADDR, 0x04, Ddsu666_start_addresses[Ddsu666.read_state], 2); + } else { + Ddsu666.send_retry--; + } +} + +void Ddsu666SnsInit(void) +{ + Ddsu666Modbus = new TasmotaModbus(pin[GPIO_DDSU666_RX], pin[GPIO_DDSU666_TX]); + uint8_t result = Ddsu666Modbus->Begin(DDSU666_SPEED); + if (result) { + if (2 == result) { ClaimSerial(); } + } else { + energy_flg = ENERGY_NONE; + } +} + +void Ddsu666DrvInit(void) +{ + if ((pin[GPIO_DDSU666_RX] < 99) && (pin[GPIO_DDSU666_TX] < 99)) { + energy_flg = XNRG_11; + } +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xnrg11(uint8_t function) +{ + bool result = false; + + switch (function) { + case FUNC_EVERY_250_MSECOND: + if (uptime > 4) { DDSU666Every250ms(); } + break; + case FUNC_INIT: + Ddsu666SnsInit(); + break; + case FUNC_PRE_INIT: + Ddsu666DrvInit(); + break; + } + return result; +} + +#endif // USE_DDSU666 +#endif // USE_ENERGY_SENSOR diff --git a/tools/decode-status.py b/tools/decode-status.py index a08689306..3d35f1147 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -171,7 +171,7 @@ a_features = [[ ],[ "USE_BUZZER","USE_RDM6300","USE_IBEACON","USE_SML_M", "USE_INA226","USE_A4988_Stepper","USE_DDS2382","USE_SM2135", - "USE_SHUTTER","USE_PCF8574","","", + "USE_SHUTTER","USE_PCF8574","USE_DDSU666","", "","","","", "","","","", "","","","", From aebe37c8909d90f4d1372dbc8c6f5ee2bd8dadd0 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 3 Oct 2019 13:11:43 +0200 Subject: [PATCH 29/46] Fix PulseTime command responses Fix PulseTime command responses --- sonoff/support_command.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index 4683c7c85..d940985f9 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -566,7 +566,7 @@ void CmndPulsetime(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_PULSETIMERS)) { uint32_t items = 1; - if (!XdrvMailbox.usridx) { + if (!XdrvMailbox.usridx && !XdrvMailbox.data_len) { items = MAX_PULSETIMERS; } else { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) { @@ -576,10 +576,11 @@ void CmndPulsetime(void) } mqtt_data[0] = '\0'; for (uint32_t i = 0; i < items; i++) { + uint32_t index = (1 == items) ? XdrvMailbox.index : i +1; ResponseAppend_P(PSTR("%c\"%s%d\":{\"" D_JSON_SET "\":%d,\"" D_JSON_REMAINING "\":%d}"), (i) ? ',' : '{', - XdrvMailbox.command, (1 == items) ? XdrvMailbox.index : i +1, - Settings.pulse_timer[XdrvMailbox.index -1], GetPulseTimer(XdrvMailbox.index -1)); + XdrvMailbox.command, index, + Settings.pulse_timer[index -1], GetPulseTimer(index -1)); } ResponseJsonEnd(); } From 0580ceb0b6f94f7e97540f6c7fd79905aa35581a Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 3 Oct 2019 14:18:04 +0200 Subject: [PATCH 30/46] Add support for Chint DDSU666 Modbus energy meter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for Chint DDSU666 Modbus energy meter by Pablo Zerón --- sonoff/_changelog.ino | 1 + sonoff/my_user_config.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index e9cdf437d..badd8306c 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,6 +1,7 @@ /*********************************************************************************************\ * 6.6.0.15 20191003 * Change command PulseTime JSON message format and allow display of all pulsetimer information (#6519) + * Add support for Chint DDSU666 Modbus energy meter by Pablo Zerón * * 6.6.0.14 20190925 * Change command Tariffx to allow time entries like 23 (hours), 1320 (minutes) or 23:00. NOTE: As this is development branch previous tariffs are lost! (#6488) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index e13a666e5..95def6f00 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -438,6 +438,8 @@ #define SDM630_SPEED 9600 // SDM630-Modbus RS485 serial speed (default: 9600 baud) //#define USE_DDS2382 // Add support for Hiking DDS2382 Modbus energy monitor (+0k6 code) #define DDS2382_SPEED 9600 // Hiking DDS2382 Modbus RS485 serial speed (default: 9600 baud) +//#define USE_DDSU666 // Add support for Chint DDSU666 Modbus energy monitor (+0k6 code) + #define DDSU666_SPEED 9600 // Chint DDSU666 Modbus RS485 serial speed (default: 9600 baud) //#define USE_SDM120 // Add support for Eastron SDM120-Modbus energy meter (+2k4 code) // #define SDM120_SPEED 2400 // SDM120-Modbus RS485 serial speed (default: 2400 baud) @@ -447,8 +449,6 @@ //#define USE_SOLAX_X1 // Add support for Solax X1 series Modbus log info (+4k1 code) #define SOLAXX1_SPEED 9600 // Solax X1 Modbus RS485 serial speed (default: 9600 baud) #define SOLAXX1_PV2 // Solax X1 using second PV -//#define USE_DDSU666 // Add support for Chint DDSU666 Modbus energy monitor (+0k6 code) - #define DDSU666_SPEED 9600 // Chint DDSU666 Modbus RS485 serial speed (default: 9600 baud) // -- Low level interface devices ----------------- #define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor (1k6 code) From a0c7db7f7c7c2744a6fa993684a2ab5999951e88 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 3 Oct 2019 14:27:01 +0200 Subject: [PATCH 31/46] Add Mqtt log level text Add Mqtt log level text --- sonoff/language/bg-BG.h | 1 + sonoff/language/cs-CZ.h | 1 + sonoff/language/de-DE.h | 1 + sonoff/language/el-GR.h | 1 + sonoff/language/en-GB.h | 1 + sonoff/language/es-ES.h | 1 + sonoff/language/fr-FR.h | 1 + sonoff/language/he-HE.h | 1 + sonoff/language/hu-HU.h | 1 + sonoff/language/it-IT.h | 1 + sonoff/language/ko-KO.h | 1 + sonoff/language/nl-NL.h | 1 + sonoff/language/pl-PL.h | 1 + sonoff/language/pt-BR.h | 1 + sonoff/language/pt-PT.h | 1 + sonoff/language/ru-RU.h | 1 + sonoff/language/sk-SK.h | 1 + sonoff/language/sv-SE.h | 1 + sonoff/language/tr-TR.h | 1 + sonoff/language/uk-UK.h | 1 + sonoff/language/zh-CN.h | 1 + sonoff/language/zh-TW.h | 1 + 22 files changed, 22 insertions(+) diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index 43792cdb3..83323eb7d 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Параметри на лога" #define D_SERIAL_LOG_LEVEL "Степен на серийния лог" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Степен на уеб лога" #define D_SYS_LOG_LEVEL "Степен на системния лог" #define D_MORE_DEBUG "Още дебъгване" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index 1067a6f02..fac229e77 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Volba logování" #define D_SERIAL_LOG_LEVEL "Seriová úroveň logu" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Webová úroveň logu" #define D_SYS_LOG_LEVEL "Systemová úroveň logu" #define D_MORE_DEBUG "Více debug informací" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index fe6067153..60d4243d5 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Logging-Einstellungen" #define D_SERIAL_LOG_LEVEL "Seriell-Log Level" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web-Log Level" #define D_SYS_LOG_LEVEL "Sys-Log Level" #define D_MORE_DEBUG "More debug" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 3c43b65c6..27fbaff3f 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Παράμετροι καταγραφής" #define D_SERIAL_LOG_LEVEL "Επίπεδο Σειριακής" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Επίπεδο Web" #define D_SYS_LOG_LEVEL "Επίπεδο Syslog" #define D_MORE_DEBUG "More debug" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index 27ef1e342..b09cd462f 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Logging parameters" #define D_SERIAL_LOG_LEVEL "Serial log level" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web log level" #define D_SYS_LOG_LEVEL "Syslog level" #define D_MORE_DEBUG "More debug" diff --git a/sonoff/language/es-ES.h b/sonoff/language/es-ES.h index 252f72ce3..987951e02 100644 --- a/sonoff/language/es-ES.h +++ b/sonoff/language/es-ES.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Parámetros Logging" #define D_SERIAL_LOG_LEVEL "Nivel de log Serial" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Nivel de log Web" #define D_SYS_LOG_LEVEL "Nivel de Syslog" #define D_MORE_DEBUG "Más Debug" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index 1c8eb4eec..838e50616 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Paramètres du journal" #define D_SERIAL_LOG_LEVEL "Niveau de journalisation série" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Niveau de journalisation web" #define D_SYS_LOG_LEVEL "Niveau SysLog" #define D_MORE_DEBUG "Plus de debug" diff --git a/sonoff/language/he-HE.h b/sonoff/language/he-HE.h index b551de296..226141459 100644 --- a/sonoff/language/he-HE.h +++ b/sonoff/language/he-HE.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "פרמטרי לוגים" #define D_SERIAL_LOG_LEVEL "רמת לוג עבור סריאל" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "רמת לוג עבור אתר" #define D_SYS_LOG_LEVEL "Syslog רמת לוג עבור שרת" #define D_MORE_DEBUG "מיפוי נוסף" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index 81f1d080a..425dc27f1 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Naplózási paraméterek" #define D_SERIAL_LOG_LEVEL "Soros naplózási szint" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web naplózási szint" #define D_SYS_LOG_LEVEL "Syslog szint" #define D_MORE_DEBUG "Részletes hibakeresés" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 1c6390cc2..a29916940 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Parametri Logging" #define D_SERIAL_LOG_LEVEL "Livello di log Seriale" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "livello di log Web" #define D_SYS_LOG_LEVEL "livello di log Sys" #define D_MORE_DEBUG "Debug aggiuntivo" diff --git a/sonoff/language/ko-KO.h b/sonoff/language/ko-KO.h index 0f628e04e..065b4d8e0 100644 --- a/sonoff/language/ko-KO.h +++ b/sonoff/language/ko-KO.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "로그 상세" #define D_SERIAL_LOG_LEVEL "시리얼 로그 레벨" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web 로그 레벨" #define D_SYS_LOG_LEVEL "Syslog 로그 레벨" #define D_MORE_DEBUG "More debug" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index d79a419b2..c568395cf 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Logging parameters" #define D_SERIAL_LOG_LEVEL "Serieel log niveau" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web log niveau" #define D_SYS_LOG_LEVEL "Syslog niveau" #define D_MORE_DEBUG "Meer debug" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index 8e374437f..c8366f1b9 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Opcje dziennika" #define D_SERIAL_LOG_LEVEL "Serial poziom dziennika" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web poziom dziennika" #define D_SYS_LOG_LEVEL "System poziom dziennika" #define D_MORE_DEBUG "Więcej informacji debug" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index 831d79d03..f05d2fffe 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Parâmetros Logging" #define D_SERIAL_LOG_LEVEL "Nível de registro serial" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Nível de registro WEB" #define D_SYS_LOG_LEVEL "Nível de registro Syslog" #define D_MORE_DEBUG "Depurar mais" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index 970fb2b8a..92b43739e 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Parametros Logging" #define D_SERIAL_LOG_LEVEL "Nível de registro serial" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Nível de registro WEB" #define D_SYS_LOG_LEVEL "Nível de registro Syslog" #define D_MORE_DEBUG "Depurar mais" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index 474d7f254..73b4604aa 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Параметры Logging" #define D_SERIAL_LOG_LEVEL "Serial лог уровень" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web лог уровень" #define D_SYS_LOG_LEVEL "System лог уровень" #define D_MORE_DEBUG "Дополнительная информация для отладки" diff --git a/sonoff/language/sk-SK.h b/sonoff/language/sk-SK.h index 092661890..e0b055fcc 100644 --- a/sonoff/language/sk-SK.h +++ b/sonoff/language/sk-SK.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Voľba logovania" #define D_SERIAL_LOG_LEVEL "Sériová úroveň logu" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Webová úroveň logu" #define D_SYS_LOG_LEVEL "Systemová úroveň logu" #define D_MORE_DEBUG "Viac debug informácí" diff --git a/sonoff/language/sv-SE.h b/sonoff/language/sv-SE.h index 16d5110be..a3f326fc7 100644 --- a/sonoff/language/sv-SE.h +++ b/sonoff/language/sv-SE.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Loggningsparametrar" #define D_SERIAL_LOG_LEVEL "Seriell loggnivå" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Webb loggnivå" #define D_SYS_LOG_LEVEL "Syslog-nivå" #define D_MORE_DEBUG "Mer debugging" diff --git a/sonoff/language/tr-TR.h b/sonoff/language/tr-TR.h index e17623637..7c22cedbe 100755 --- a/sonoff/language/tr-TR.h +++ b/sonoff/language/tr-TR.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Loglama parametreleri" #define D_SERIAL_LOG_LEVEL "Serial log seviyesi" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web log seviyesi" #define D_SYS_LOG_LEVEL "Syslog seviyesi" #define D_MORE_DEBUG "Hata ayıklama devamı" diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h index 92b3711fd..a586a5114 100644 --- a/sonoff/language/uk-UK.h +++ b/sonoff/language/uk-UK.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "Параметри журналу" #define D_SERIAL_LOG_LEVEL "Serial рівень" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web рівень" #define D_SYS_LOG_LEVEL "System рівень" #define D_MORE_DEBUG "Додаткова інформація для налагодження" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index 872c13563..30a733b1d 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "日志设置" #define D_SERIAL_LOG_LEVEL "串口日志级别" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web 日志级别" #define D_SYS_LOG_LEVEL "Syslog 日志级别" #define D_MORE_DEBUG "全部调试" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index 4d26109fa..bfac974f5 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -284,6 +284,7 @@ #define D_LOGGING_PARAMETERS "日志設置" #define D_SERIAL_LOG_LEVEL "串口日志級別" +#define D_MQTT_LOG_LEVEL "Mqtt log level" #define D_WEB_LOG_LEVEL "Web 日志級別" #define D_SYS_LOG_LEVEL "Syslog 日志級別" #define D_MORE_DEBUG "全部調試" From fef7faa5beeda6ecf2b8ce5642e24209230657b0 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 3 Oct 2019 14:45:24 +0200 Subject: [PATCH 32/46] Add MQTTLog option to GUI Add MQTTLog option to GUI --- sonoff/xdrv_01_webserver.ino | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index 9f8ec9eed..aeb9fcbcf 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -527,7 +527,7 @@ const char kButtonConfirm[] PROGMEM = D_CONFIRM_RESTART "|" D_CONFIRM_RESET_CONF enum CTypes { CT_HTML, CT_PLAIN, CT_XML, CT_JSON, CT_STREAM }; const char kContentTypes[] PROGMEM = "text/html|text/plain|text/xml|application/json|application/octet-stream"; -const char kLoggingOptions[] PROGMEM = D_SERIAL_LOG_LEVEL "|" D_WEB_LOG_LEVEL "|" D_SYS_LOG_LEVEL; +const char kLoggingOptions[] PROGMEM = D_SERIAL_LOG_LEVEL "|" D_WEB_LOG_LEVEL "|" D_MQTT_LOG_LEVEL "|" D_SYS_LOG_LEVEL; const char kLoggingLevels[] PROGMEM = D_NONE "|" D_ERROR "|" D_INFO "|" D_DEBUG "|" D_MORE_DEBUG; const char kEmulationOptions[] PROGMEM = D_NONE "|" D_BELKIN_WEMO "|" D_HUE_BRIDGE; @@ -1618,9 +1618,10 @@ void HandleLoggingConfiguration(void) WSContentSend_P(HTTP_FORM_LOG1); char stemp1[45]; char stemp2[32]; - uint8_t dlevel[3] = { LOG_LEVEL_INFO, LOG_LEVEL_INFO, LOG_LEVEL_NONE }; - for (uint32_t idx = 0; idx < 3; idx++) { - uint32_t llevel = (0==idx)?Settings.seriallog_level:(1==idx)?Settings.weblog_level:Settings.syslog_level; + uint8_t dlevel[4] = { LOG_LEVEL_INFO, LOG_LEVEL_INFO, LOG_LEVEL_NONE, LOG_LEVEL_NONE }; + for (uint32_t idx = 0; idx < 4; idx++) { + if ((2==idx) && !Settings.flag.mqtt_enabled) { continue; } + uint32_t llevel = (0==idx)?Settings.seriallog_level:(1==idx)?Settings.weblog_level:(2==idx)?Settings.mqttlog_level:Settings.syslog_level; WSContentSend_P(PSTR("

%s (%s)