From 8183b44e03341751227b698704b872154cfeb33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Thu, 24 Aug 2017 18:42:35 +0200 Subject: [PATCH] Support for EXS Wifi Relay 3.1 (untested) --- code/espurna/config/general.h | 2 +- code/espurna/config/hardware.h | 23 +++++++++ code/espurna/hardware.ino | 85 +++++++++++++++++++--------------- code/espurna/relay.ino | 9 ++-- code/platformio.ini | 21 +++++++++ 5 files changed, 97 insertions(+), 43 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 224d3e73..183849cf 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -188,7 +188,7 @@ PROGMEM const char* const custom_reset_string[] = { #define RELAY_FLOOD_CHANGES 5 // Pulse with in milliseconds for a latched relay -#define RELAY_LATCHING_PULSE 50 +#define RELAY_LATCHING_PULSE 10 //------------------------------------------------------------------------------ // I18N diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index fcb45e8f..1c74ccba 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -785,6 +785,29 @@ #define LED1_PIN 2 #define LED1_PIN_INVERSE 0 +// ----------------------------------------------------------------------------- +// EX-Store Wifi Relay v3.1 +// https://ex-store.de/ESP8266-WiFi-Relay-V31 +// ----------------------------------------------------------------------------- + +#elif defined(EXS_WIFI_RELAY_V31) + + // Untested + + // Info + #define MANUFACTURER "EXS" + #define DEVICE "WIFI_RELAY_V31" + + // Buttons + #define BUTTON1_PIN 0 + #define BUTTON1_RELAY 1 + #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH + + // Relays + #define RELAY1_PIN 13 + #define RELAY1_TYPE RELAY_TYPE_LATCHED + #define RELAY1_RESET_PIN 12 + // ----------------------------------------------------------------------------- // Unknown hardware // ----------------------------------------------------------------------------- diff --git a/code/espurna/hardware.ino b/code/espurna/hardware.ino index 4965d97e..d465a487 100644 --- a/code/espurna/hardware.ino +++ b/code/espurna/hardware.ino @@ -26,7 +26,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(WEMOS_D1_MINI_RELAYSHIELD) @@ -34,7 +34,7 @@ void hwUpwardsCompatibility() { setSetting("ledGPIO", 1, 2); setSetting("ledLogic", 1, 1); setSetting("relayGPIO", 1, 5); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_BASIC) @@ -44,7 +44,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_TH) @@ -54,7 +54,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_SV) @@ -64,7 +64,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_TOUCH) @@ -74,7 +74,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_POW) @@ -84,7 +84,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); setSetting("selGPIO", 5); setSetting("cf1GPIO", 13); setSetting("cfGPIO", 14); @@ -106,7 +106,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_4CH) @@ -125,10 +125,10 @@ void hwUpwardsCompatibility() { setSetting("relayGPIO", 2, 5); setSetting("relayGPIO", 3, 4); setSetting("relayGPIO", 4, 15); - setSetting("relayLogic", 1, 0); - setSetting("relayLogic", 2, 0); - setSetting("relayLogic", 3, 0); - setSetting("relayLogic", 4, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + setSetting("relayType", 2, RELAY_TYPE_NORMAL); + setSetting("relayType", 3, RELAY_TYPE_NORMAL); + setSetting("relayType", 4, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SLAMPHER) @@ -138,7 +138,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(ITEAD_S20) @@ -148,7 +148,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(ELECTRODRAGON_WIFI_IOT) @@ -161,8 +161,8 @@ void hwUpwardsCompatibility() { setSetting("btnRelay", 2, 2); setSetting("relayGPIO", 1, 12); setSetting("relayGPIO", 2, 13); - setSetting("relayLogic", 1, 0); - setSetting("relayLogic", 2, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + setSetting("relayType", 2, RELAY_TYPE_NORMAL); #elif defined(WORKCHOICE_ECOPLUG) @@ -172,7 +172,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 13); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 15); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(JANGOE_WIFI_RELAY_NC) @@ -183,8 +183,8 @@ void hwUpwardsCompatibility() { setSetting("btnRelay", 2, 2); setSetting("relayGPIO", 1, 2); setSetting("relayGPIO", 2, 14); - setSetting("relayLogic", 1, 1); - setSetting("relayLogic", 2, 1); + setSetting("relayType", 1, RELAY_TYPE_INVERSE); + setSetting("relayType", 2, RELAY_TYPE_INVERSE); #elif defined(JANGOE_WIFI_RELAY_NO) @@ -195,8 +195,8 @@ void hwUpwardsCompatibility() { setSetting("btnRelay", 2, 2); setSetting("relayGPIO", 1, 2); setSetting("relayGPIO", 2, 14); - setSetting("relayLogic", 1, 0); - setSetting("relayLogic", 2, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + setSetting("relayType", 2, RELAY_TYPE_NORMAL); #elif defined(OPENENERGYMONITOR_MQTT_RELAY) @@ -206,15 +206,15 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(JORGEGARCIA_WIFI_RELAYS) setSetting("board", 19); setSetting("relayGPIO", 1, 0); - setSetting("relayLogic", 1, 1); setSetting("relayGPIO", 2, 2); - setSetting("relayLogic", 2, 1); + setSetting("relayType", 1, RELAY_TYPE_INVERSE); + setSetting("relayType", 2, RELAY_TYPE_INVERSE); #elif defined(AITHINKER_AI_LIGHT) @@ -250,7 +250,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(TINKERMAN_ESPURNA_H) @@ -260,7 +260,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 4); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 1); + setSetting("relayType", 1, RELAY_TYPE_INVERSE); setSetting("selGPIO", 2); setSetting("cf1GPIO", 13); setSetting("cfGPIO", 14); @@ -321,10 +321,10 @@ void hwUpwardsCompatibility() { setSetting("relayGPIO", 2, 5); setSetting("relayGPIO", 3, 4); setSetting("relayGPIO", 4, 15); - setSetting("relayLogic", 1, 0); - setSetting("relayLogic", 2, 0); - setSetting("relayLogic", 3, 0); - setSetting("relayLogic", 4, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + setSetting("relayType", 2, RELAY_TYPE_NORMAL); + setSetting("relayType", 3, RELAY_TYPE_NORMAL); + setSetting("relayType", 4, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_B1) @@ -356,7 +356,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 9); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 5); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_T1_2CH) @@ -369,8 +369,8 @@ void hwUpwardsCompatibility() { setSetting("btnRelay", 2, 2); setSetting("relayGPIO", 1, 12); setSetting("relayGPIO", 2, 4); - setSetting("relayLogic", 1, 0); - setSetting("relayLogic", 2, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + setSetting("relayType", 2, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_T1_3CH) @@ -386,9 +386,9 @@ void hwUpwardsCompatibility() { setSetting("relayGPIO", 1, 12); setSetting("relayGPIO", 2, 5); setSetting("relayGPIO", 3, 4); - setSetting("relayLogic", 1, 0); - setSetting("relayLogic", 2, 0); - setSetting("relayLogic", 3, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + setSetting("relayType", 2, RELAY_TYPE_NORMAL); + setSetting("relayType", 3, RELAY_TYPE_NORMAL); #elif defined(ITEAD_SONOFF_RF) @@ -398,7 +398,7 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 0); setSetting("btnRelay", 1, 1); setSetting("relayGPIO", 1, 12); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #elif defined(WION_50055) @@ -408,7 +408,16 @@ void hwUpwardsCompatibility() { setSetting("btnGPIO", 1, 13); setSetting("btnRelay", 1,1); setSetting("relayGPIO", 1, 15); - setSetting("relayLogic", 1, 0); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); + + #elif defined(EXS_WIFI_RELAY_V31) + + setSetting("board", 35); + setSetting("btnGPIO", 1, 0); + setSetting("btnRelay", 1, 1); + setSetting("relayGPIO", 1, 13); + setSetting("relayResetGPIO", 1, 12); + setSetting("relayType", 1, RELAY_TYPE_NORMAL); #else diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 0b7c29ab..4ad4d786 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -67,15 +67,16 @@ void relayProviderStatus(unsigned char id, bool status) { } else if (_relays[id].type == RELAY_TYPE_INVERSE) { digitalWrite(_relays[id].pin, !status); } else if (_relays[id].type == RELAY_TYPE_LATCHED) { + digitalWrite(_relays[id].pin, LOW); + digitalWrite(_relays[id].reset_pin, LOW); if (status) { digitalWrite(_relays[id].pin, HIGH); - delay(RELAY_LATCHING_PULSE); - digitalWrite(_relays[id].pin, LOW); } else { digitalWrite(_relays[id].reset_pin, HIGH); - delay(RELAY_LATCHING_PULSE); - digitalWrite(_relays[id].reset_pin, LOW); } + delay(RELAY_LATCHING_PULSE); + digitalWrite(_relays[id].pin, LOW); + digitalWrite(_relays[id].reset_pin, LOW); } #endif diff --git a/code/platformio.ini b/code/platformio.ini index fc0fa840..0057ce49 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -675,3 +675,24 @@ build_flags = ${common.build_flags_1m} -DWION_50055 upload_speed = 115200 upload_port = "192.168.4.1" upload_flags = --auth=fibonacci --port 8266 + +[env:exs-wifi-relay-v31] +platform = espressif8266 +framework = arduino +board = esp07 +board_flash_mode = dout +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m} -DEXS_WIFI_RELAY_V31 + +[env:exs-wifi-relay-v31-ota] +platform = espressif8266 +framework = arduino +board = esp07 +board_flash_mode = dout +lib_deps = ${common.lib_deps} +lib_ignore = ${common.lib_ignore} +build_flags = ${common.build_flags_1m} -DEXS_WIFI_RELAY_V31 +upload_speed = 115200 +upload_port = "192.168.4.1" +upload_flags = --auth=fibonacci --port 8266