diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 2af5885db..e04c9c727 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,8 @@ -/* 6.2.1.11 20181002 +/* 6.2.1.12 20181007 + * Fix Shelly1 switchmode 3 and 4 when using pushbutton (#3989) + * Add support for CSL Aplic WDP 303075 Power Socket with Energy Monitoring (#3991, #3996) + * + * 6.2.1.11 20181002 * Remove support for MQTT Client based on esp-mqtt-arduino by #define MQTT_LIBRARY_TYPE MQTT_ESPMQTTARDUINO * Add support for MQTT Client based on lwmqtt to be selected by #define MQTT_LIBRARY_TYPE MQTT_ARDUINOMQTT * Change MQTT_ARDUINOMQTT command timeout from 1 to 10 seconds diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index b89ffe138..958c7879b 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2306,9 +2306,11 @@ void GpioSwitchPinMode(uint8_t index) if (pin[GPIO_SWT1 +index] < 99) { // pinMode(pin[GPIO_SWT1 +index], (16 == pin[GPIO_SWT1 +index]) ? INPUT_PULLDOWN_16 : bitRead(switch_no_pullup, index) ? INPUT : INPUT_PULLUP); - uint8_t no_pullup = 0; - if (bitRead(switch_no_pullup, index)) { - no_pullup = (Settings.switchmode[index] < PUSHBUTTON); + uint8_t no_pullup = bitRead(switch_no_pullup, index); + if (no_pullup) { + if (SHELLY2 == Settings.module) { + no_pullup = (Settings.switchmode[index] < PUSHBUTTON); + } } pinMode(pin[GPIO_SWT1 +index], (16 == pin[GPIO_SWT1 +index]) ? INPUT_PULLDOWN_16 : (no_pullup) ? INPUT : INPUT_PULLUP); } diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index f997eb555..ca352149d 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -135,9 +135,11 @@ enum ProgramSelectablePins { GPIO_SPI_MISO, // SPI MISO library fixed pin GPIO12 GPIO_SPI_MOSI, // SPI MOSI library fixed pin GPIO13 GPIO_SPI_CLK, // SPI Clk library fixed pin GPIO14 - GPIO_HLW_SEL, // HLW8012 Sel output (Sonoff Pow) - GPIO_HLW_CF1, // HLW8012 CF1 voltage / current (Sonoff Pow) - GPIO_HLW_CF, // HLW8012 CF power (Sonoff Pow) + GPIO_NRG_SEL, // HLW8012/HLJ-01 Sel output (1 = Voltage) + GPIO_NRG_SEL_INV, // HLW8012/HLJ-01 Sel output (0 = Voltage) + GPIO_NRG_CF1, // HLW8012/HLJ-01 CF1 voltage / current + GPIO_HLW_CF, // HLW8012 CF power + GPIO_HJL_CF, // HJL-01/BL0937 CF power GPIO_ADC0, // ADC GPIO_DI, // my92x1 PWM input GPIO_DCKI, // my92x1 CLK input @@ -396,6 +398,7 @@ const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { SHELLY2, BLITZWOLF_BWSHP2, // Socket Relay Devices with Energy Monitoring TECKIN, + APLIC_WDP303075, NEO_COOLCAM, // Socket Relay Devices OBI, ESP_SWITCH, // Switch Devices @@ -410,8 +413,7 @@ const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { AILIGHT, // Light Bulbs PHILIPS, WITTY, // Development Devices - WEMOS, - APLIC_WDP303075 + WEMOS }; // Default module settings @@ -492,10 +494,10 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { { "Sonoff Pow", // Sonoff Pow (ESP8266 - HLW8012) GPIO_KEY1, // GPIO00 Button 0, 0, 0, 0, - GPIO_HLW_SEL, // GPIO05 HLW8012 Sel output + GPIO_NRG_SEL, // GPIO05 HLW8012 Sel output (1 = Voltage) 0, 0, 0, 0, 0, 0, // Flash connection GPIO_REL1, // GPIO12 Red Led and Relay (0 = Off, 1 = On) - GPIO_HLW_CF1, // GPIO13 HLW8012 CF1 voltage / current + GPIO_NRG_CF1, // GPIO13 HLW8012 CF1 voltage / current GPIO_HLW_CF, // GPIO14 HLW8012 CF power GPIO_LED1, // GPIO15 Blue Led (0 = On, 1 = Off) 0, 0 @@ -729,8 +731,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_KEY1, // GPIO4 Button GPIO_REL1_INV, // GPIO5 Relay (0 = On, 1 = Off) 0, 0, 0, 0, 0, 0, // Flash connection - GPIO_HLW_CF1, // GPIO12 HLW8012 CF1 voltage / current - GPIO_HLW_SEL, // GPIO13 HLW8012 Sel output + GPIO_NRG_CF1, // GPIO12 HLW8012 CF1 voltage / current + GPIO_NRG_SEL, // GPIO13 HLW8012 Sel output (1 = Voltage) GPIO_HLW_CF, // GPIO14 HLW8012 CF power 0, 0, 0 }, @@ -899,10 +901,10 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { // https://www.amazon.com/KMC-Timing-Monitoring-Network-125V-240V/dp/B06XRX2GTQ GPIO_KEY1, // GPIO00 Button 0, 0, 0, - GPIO_HLW_CF, // GPIO04 HLW8012 CF - GPIO_HLW_CF1, // GPIO05 HLW8012 CF1 + GPIO_HLW_CF, // GPIO04 HLW8012 CF power + GPIO_NRG_CF1, // GPIO05 HLW8012 CF1 voltage / current 0, 0, 0, 0, 0, 0, // Flash connection - GPIO_HLW_SEL, // GPIO12 HLW8012 SEL + GPIO_NRG_SEL, // GPIO12 HLW8012 SEL (1 = Voltage) GPIO_LED1_INV, // GPIO13 Green Led GPIO_REL1, // GPIO14 Relay 0, 0, 0 @@ -1030,11 +1032,11 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_LED1_INV, // GPIO02 Blue Led (1 = On, 0 = Off) GPIO_USER, // GPIO03 Serial TXD and Optional sensor 0, - GPIO_HLW_CF, // GPIO05 BL0937 or HJL-01 CF power + GPIO_HJL_CF, // GPIO05 BL0937 or HJL-01 CF power 0, 0, 0, 0, 0, 0, // Flash connection - GPIO_HLW_SEL, // GPIO12 BL0937 or HJL-01 Sel output + GPIO_NRG_SEL_INV, // GPIO12 BL0937 or HJL-01 Sel output (0 = Voltage) GPIO_KEY1, // GPIO13 Button - GPIO_HLW_CF1, // GPIO14 BL0937 or HJL-01 CF1 voltage / current + GPIO_NRG_CF1, // GPIO14 BL0937 or HJL-01 CF1 current / voltage GPIO_REL1, // GPIO15 Relay (0 = Off, 1 = On) 0, 0 }, @@ -1107,28 +1109,25 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_KEY1, // GPIO01 Serial TXD and Button 0, GPIO_LED2_INV, // GPIO03 Serial RXD and Red Led (0 = On, 1 = Off) - GPIO_HLW_CF, // GPIO04 BL0937 or HJL-01 CF power - GPIO_HLW_CF1, // GPIO05 BL0937 or HJL-01 CF1 voltage / current + GPIO_HJL_CF, // GPIO04 BL0937 or HJL-01 CF power + GPIO_NRG_CF1, // GPIO05 BL0937 or HJL-01 CF1 current / voltage 0, 0, 0, 0, 0, 0, // Flash connection - GPIO_HLW_SEL, // GPIO12 BL0937 or HJL-01 Sel output + GPIO_NRG_SEL_INV, // GPIO12 BL0937 or HJL-01 Sel output (0 = Voltage) GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off) GPIO_REL1, // GPIO14 Relay (0 = Off, 1 = On) 0, 0, 0 }, - { "AplicWDP303075", // Aplic WDP 303075 (ESP8285 - HLW8012 Energy Monitoring) + { "AplicWDP303075", // Aplic WDP 303075 (ESP8285 - HLW8012 Energy Monitoring) // https://www.amazon.de/dp/B07CNWVNJ2 - 0, // GPIO00 - 0, // GPIO01 - 0, // GPIO02 - GPIO_KEY1, // GPIO03 Button - GPIO_HLW_CF, // GPIO04 HLW8012 CF (power) - GPIO_HLW_CF1, // GPIO05 HLW8012 CF1 (current/voltage) - 0, 0, 0, 0, 0, 0, // ? - GPIO_HLW_SEL, // GPIO12 HLW8012 CF Sel output (CF) - GPIO_LED1_INV, // GPIO13 LED - GPIO_REL1, // GPIO14 Relay SRU 5VDC SDA (0= Off, 1 = On ) - 0, // GPIO15 - 0, 0 + 0, 0, 0, + GPIO_KEY1, // GPIO03 Button + GPIO_HLW_CF, // GPIO04 HLW8012 CF power + GPIO_NRG_CF1, // GPIO05 HLW8012 CF1 current / voltage + 0, 0, 0, 0, 0, 0, // Flash connection + GPIO_NRG_SEL_INV, // GPIO12 HLW8012 CF Sel output (0 = Voltage) + GPIO_LED1_INV, // GPIO13 LED (0 = On, 1 = Off) + GPIO_REL1, // GPIO14 Relay SRU 5VDC SDA (0 = Off, 1 = On ) + 0, 0, 0 } }; diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 60a044326..df02100d3 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x0602010B +#define VERSION 0x0602010C #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/xnrg_01_hlw8012.ino b/sonoff/xnrg_01_hlw8012.ino index 5c63b4826..0a7a074e7 100644 --- a/sonoff/xnrg_01_hlw8012.ino +++ b/sonoff/xnrg_01_hlw8012.ino @@ -27,26 +27,21 @@ #define XNRG_01 1 -// HLW8012 based (Sonoff Pow, KMC70011, HuaFan) +// Energy model type 0 (GPIO_HLW_CF) - HLW8012 based (Sonoff Pow, KMC70011, HuaFan, AplicWDP303075) #define HLW_PREF 10000 // 1000.0W #define HLW_UREF 2200 // 220.0V #define HLW_IREF 4545 // 4.545A -#define HLW_SEL_VOLTAGE 1 - -// HLW8012 based (APLIC_WDP303075) -#define A_HLW_SEL_VOLTAGE 0 - -// HJL-01 based (BlitzWolf, Homecube, Gosund, Teckin) +// Energy model type 1 (GPIO_HJL_CF) - HJL-01/BL0937 based (BlitzWolf, Homecube, Gosund, Teckin) #define HJL_PREF 1362 #define HJL_UREF 822 #define HJL_IREF 3300 -#define HJL_SEL_VOLTAGE 0 #define HLW_POWER_PROBE_TIME 10 // Number of seconds to probe for power before deciding none used byte hlw_select_ui_flag; byte hlw_ui_flag = 1; +byte hlw_model_type = 0; byte hlw_load_off; byte hlw_cf1_timer; unsigned long hlw_cf_pulse_length; @@ -124,7 +119,7 @@ void HlwEvery200ms() if (hlw_cf1_timer >= 8) { hlw_cf1_timer = 0; hlw_select_ui_flag = (hlw_select_ui_flag) ? 0 : 1; - digitalWrite(pin[GPIO_HLW_SEL], hlw_select_ui_flag); + digitalWrite(pin[GPIO_NRG_SEL], hlw_select_ui_flag); if (hlw_cf1_pulse_counter) { hlw_cf1_pulse_length = hlw_cf1_summed_pulse_length / hlw_cf1_pulse_counter; @@ -181,21 +176,14 @@ void HlwSnsInit() Settings.energy_current_calibration = HLW_IREF_PULSE; } - if ((BLITZWOLF_BWSHP2 == Settings.module) || (TECKIN == Settings.module)) { + if (hlw_model_type) { hlw_power_ratio = HJL_PREF; hlw_voltage_ratio = HJL_UREF; hlw_current_ratio = HJL_IREF; - hlw_ui_flag = HJL_SEL_VOLTAGE; - } else if (APLIC_WDP303075 == Settings.module){ - hlw_power_ratio = HLW_PREF; - hlw_voltage_ratio = HLW_UREF; - hlw_current_ratio = HLW_IREF; - hlw_ui_flag = A_HLW_SEL_VOLTAGE; } else { hlw_power_ratio = HLW_PREF; hlw_voltage_ratio = HLW_UREF; hlw_current_ratio = HLW_IREF; - hlw_ui_flag = HLW_SEL_VOLTAGE; } hlw_cf_pulse_length = 0; @@ -212,10 +200,10 @@ void HlwSnsInit() hlw_select_ui_flag = 0; // Voltage; - pinMode(pin[GPIO_HLW_SEL], OUTPUT); - digitalWrite(pin[GPIO_HLW_SEL], hlw_select_ui_flag); - pinMode(pin[GPIO_HLW_CF1], INPUT_PULLUP); - attachInterrupt(pin[GPIO_HLW_CF1], HlwCf1Interrupt, FALLING); + pinMode(pin[GPIO_NRG_SEL], OUTPUT); + digitalWrite(pin[GPIO_NRG_SEL], hlw_select_ui_flag); + pinMode(pin[GPIO_NRG_CF1], INPUT_PULLUP); + attachInterrupt(pin[GPIO_NRG_CF1], HlwCf1Interrupt, FALLING); pinMode(pin[GPIO_HLW_CF], INPUT_PULLUP); attachInterrupt(pin[GPIO_HLW_CF], HlwCfInterrupt, FALLING); @@ -225,7 +213,21 @@ void HlwSnsInit() void HlwDrvInit() { if (!energy_flg) { - if ((pin[GPIO_HLW_SEL] < 99) && (pin[GPIO_HLW_CF1] < 99) && (pin[GPIO_HLW_CF] < 99)) { // Sonoff Pow or any HLW8012 based device + hlw_model_type = 0; + if (pin[GPIO_HJL_CF] < 99) { + pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF]; + pin[GPIO_HJL_CF] = 99; + hlw_model_type = 1; + } + + hlw_ui_flag = 1; + if (pin[GPIO_NRG_SEL_INV] < 99) { + pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV]; + pin[GPIO_NRG_SEL_INV] = 99; + hlw_ui_flag = 0; + } + + if ((pin[GPIO_NRG_SEL] < 99) && (pin[GPIO_NRG_CF1] < 99) && (pin[GPIO_HLW_CF] < 99)) { // HLW8012 or HJL-01 based device energy_flg = XNRG_01; } }