From e9d8ad73644d91caa17b715c4a909dc31a813c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sat, 30 Jun 2018 22:27:11 +0200 Subject: [PATCH] Load config on boot from embedded JSON file --- code/espurna/button.ino | 197 ++-- code/espurna/config/general.h | 6 +- code/espurna/config/hardware.h | 66 +- code/espurna/config/types.h | 4 +- code/espurna/espurna.ino | 5 +- code/espurna/led.ino | 124 +-- code/espurna/mdns.ino | 2 +- code/espurna/migrate.ino | 1679 +------------------------------- code/espurna/relay.ino | 51 +- code/espurna/ssdp.ino | 2 +- code/espurna/utils.ino | 26 +- code/espurna/web.ino | 2 +- code/espurna/ws.ino | 4 +- code/lib/readme.txt | 38 - 14 files changed, 222 insertions(+), 1984 deletions(-) delete mode 100644 code/lib/readme.txt diff --git a/code/espurna/button.ino b/code/espurna/button.ino index 4f3b1532..c2dbdbec 100644 --- a/code/espurna/button.ino +++ b/code/espurna/button.ino @@ -48,19 +48,7 @@ bool _buttonKeyCheck(const char * key) { return (strncmp(key, "btn", 3) == 0); } -int buttonFromRelay(unsigned int relayID) { - for (unsigned int i=0; i < _buttons.size(); i++) { - if (_buttons[i].relayID == relayID) return i; - } - return -1; -} - -bool buttonState(unsigned char id) { - if (id >= _buttons.size()) return false; - return _buttons[id].button->pressed(); -} - -unsigned char buttonAction(unsigned char id, unsigned char event) { +unsigned char _buttonGetAction(unsigned char id, unsigned char event) { if (id >= _buttons.size()) return BUTTON_MODE_NONE; unsigned long actions = _buttons[id].actions; if (event == BUTTON_EVENT_PRESSED) return (actions) & 0x0F; @@ -72,18 +60,27 @@ unsigned char buttonAction(unsigned char id, unsigned char event) { return BUTTON_MODE_NONE; } -unsigned long buttonStore(unsigned long pressed, unsigned long click, unsigned long dblclick, unsigned long lngclick, unsigned long lnglngclick, unsigned long tripleclick) { - unsigned int value; - value = pressed; - value += click << 4; - value += dblclick << 8; - value += lngclick << 12; - value += lnglngclick << 16; - value += tripleclick << 20; +unsigned long _buttonGetActionMask(unsigned char id) { + + unsigned long pressAction = getSetting("btnPress", id, BUTTON_MODE_NONE).toInt(); + unsigned long clickAction = getSetting("btnClick", id, BUTTON_MODE_TOGGLE).toInt(); + unsigned long dblClickAction = getSetting("btnDblClick", id, (id == 1) ? BUTTON_MODE_AP : BUTTON_MODE_NONE).toInt(); + unsigned long lngClickAction = getSetting("btnLngClick", id, (id == 1) ? BUTTON_MODE_RESET : BUTTON_MODE_NONE).toInt(); + unsigned long lnglngClickAction = getSetting("btnLngLngClick", id, (id == 1) ? BUTTON_MODE_FACTORY : BUTTON_MODE_NONE).toInt(); + unsigned long tripleClickAction = getSetting("btnTripleClick", id, (id == 1) ? BUTTON_MODE_NONE : BUTTON_MODE_NONE).toInt(); + + unsigned long value; + value = pressAction; + value += clickAction << 4; + value += dblClickAction << 8; + value += lngClickAction << 12; + value += lnglngClickAction << 16; + value += tripleClickAction << 20; return value; + } -uint8_t mapEvent(uint8_t event, uint8_t count, uint16_t length) { +uint8_t _buttonGetEvent(uint8_t event, uint8_t count, uint16_t length) { if (event == EVENT_PRESSED) return BUTTON_EVENT_PRESSED; if (event == EVENT_CHANGED) return BUTTON_EVENT_CLICK; if (event == EVENT_RELEASED) { @@ -98,7 +95,7 @@ uint8_t mapEvent(uint8_t event, uint8_t count, uint16_t length) { return BUTTON_EVENT_NONE; } -void buttonEvent(unsigned int id, unsigned char event) { +void _buttonExecuteEvent(unsigned int id, unsigned char event) { DEBUG_MSG_P(PSTR("[BUTTON] Button #%u event %u\n"), id, event); if (event == 0) return; @@ -107,21 +104,21 @@ void buttonEvent(unsigned int id, unsigned char event) { buttonMQTT(id, event); #endif - unsigned char action = buttonAction(id, event); + unsigned char action = _buttonGetAction(id, event); if (action == BUTTON_MODE_TOGGLE) { - if (_buttons[id].relayID > 0) { - relayToggle(_buttons[id].relayID - 1); + if (RELAY_NONE != _buttons[id].relayID) { + relayToggle(_buttons[id].relayID); } } if (action == BUTTON_MODE_ON) { - if (_buttons[id].relayID > 0) { - relayStatus(_buttons[id].relayID - 1, true); + if (RELAY_NONE != _buttons[id].relayID) { + relayStatus(_buttons[id].relayID, true); } } if (action == BUTTON_MODE_OFF) { - if (_buttons[id].relayID > 0) { - relayStatus(_buttons[id].relayID - 1, false); + if (RELAY_NONE != _buttons[id].relayID) { + relayStatus(_buttons[id].relayID, false); } } if (action == BUTTON_MODE_AP) wifiStartAP(); @@ -142,85 +139,7 @@ void buttonEvent(unsigned int id, unsigned char event) { } -void buttonSetup() { - - #ifdef ITEAD_SONOFF_DUAL - - unsigned int actions = buttonStore(BUTTON_MODE_NONE, BUTTON_MODE_TOGGLE, BUTTON_MODE_NONE, BUTTON_MODE_NONE, BUTTON_MODE_NONE, BUTTON_MODE_NONE); - _buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, 1}); - _buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, 2}); - _buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, BUTTON3_RELAY}); - - #else - - unsigned long btnDelay = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt(); - - #if BUTTON1_PIN != GPIO_NONE - { - unsigned int actions = buttonStore(BUTTON1_PRESS, BUTTON1_CLICK, BUTTON1_DBLCLICK, BUTTON1_LNGCLICK, BUTTON1_LNGLNGCLICK, BUTTON1_TRIPLECLICK); - _buttons.push_back({new DebounceEvent(BUTTON1_PIN, BUTTON1_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON1_RELAY}); - } - #endif - #if BUTTON2_PIN != GPIO_NONE - { - unsigned int actions = buttonStore(BUTTON2_PRESS, BUTTON2_CLICK, BUTTON2_DBLCLICK, BUTTON2_LNGCLICK, BUTTON2_LNGLNGCLICK, BUTTON2_TRIPLECLICK); - _buttons.push_back({new DebounceEvent(BUTTON2_PIN, BUTTON2_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON2_RELAY}); - } - #endif - #if BUTTON3_PIN != GPIO_NONE - { - unsigned int actions = buttonStore(BUTTON3_PRESS, BUTTON3_CLICK, BUTTON3_DBLCLICK, BUTTON3_LNGCLICK, BUTTON3_LNGLNGCLICK, BUTTON3_TRIPLECLICK); - _buttons.push_back({new DebounceEvent(BUTTON3_PIN, BUTTON3_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON3_RELAY}); - } - #endif - #if BUTTON4_PIN != GPIO_NONE - { - unsigned int actions = buttonStore(BUTTON4_PRESS, BUTTON4_CLICK, BUTTON4_DBLCLICK, BUTTON4_LNGCLICK, BUTTON4_LNGLNGCLICK, BUTTON4_TRIPLECLICK); - _buttons.push_back({new DebounceEvent(BUTTON4_PIN, BUTTON4_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON4_RELAY}); - } - #endif - #if BUTTON5_PIN != GPIO_NONE - { - unsigned int actions = buttonStore(BUTTON5_PRESS, BUTTON5_CLICK, BUTTON5_DBLCLICK, BUTTON5_LNGCLICK, BUTTON5_LNGLNGCLICK, BUTTON5_TRIPLECLICK); - _buttons.push_back({new DebounceEvent(BUTTON5_PIN, BUTTON5_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON5_RELAY}); - } - #endif - #if BUTTON6_PIN != GPIO_NONE - { - unsigned int actions = buttonStore(BUTTON6_PRESS, BUTTON6_CLICK, BUTTON6_DBLCLICK, BUTTON6_LNGCLICK, BUTTON6_LNGLNGCLICK, BUTTON6_TRIPLECLICK); - _buttons.push_back({new DebounceEvent(BUTTON6_PIN, BUTTON6_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON6_RELAY}); - } - #endif - #if BUTTON7_PIN != GPIO_NONE - { - unsigned int actions = buttonStore(BUTTON7_PRESS, BUTTON7_CLICK, BUTTON7_DBLCLICK, BUTTON7_LNGCLICK, BUTTON7_LNGLNGCLICK, BUTTON7_TRIPLECLICK); - _buttons.push_back({new DebounceEvent(BUTTON7_PIN, BUTTON7_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON7_RELAY}); - } - #endif - #if BUTTON8_PIN != GPIO_NONE - { - unsigned int actions = buttonStore(BUTTON8_PRESS, BUTTON8_CLICK, BUTTON8_DBLCLICK, BUTTON8_LNGCLICK, BUTTON8_LNGLNGCLICK, BUTTON8_TRIPLECLICK); - _buttons.push_back({new DebounceEvent(BUTTON8_PIN, BUTTON8_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON8_RELAY}); - } - #endif - - #endif - - DEBUG_MSG_P(PSTR("[BUTTON] Number of buttons: %u\n"), _buttons.size()); - - // Websocket Callbacks - #if WEB_SUPPORT - wsOnSendRegister(_buttonWebSocketOnSend); - #endif - - settingsRegisterKeyCheck(_buttonKeyCheck); - - // Register loop - espurnaRegisterLoop(buttonLoop); - -} - -void buttonLoop() { +void _buttonLoop() { #ifdef ITEAD_SONOFF_DUAL @@ -236,7 +155,7 @@ void buttonLoop() { // (in the relayStatus method) it will only be present // here if it has actually been pressed if ((value & 4) == 4) { - buttonEvent(2, BUTTON_EVENT_CLICK); + _buttonExecuteEvent(2, BUTTON_EVENT_CLICK); return; } @@ -251,7 +170,7 @@ void buttonLoop() { // Check if the status for that relay has changed if (relayStatus(i) != status) { - buttonEvent(i, BUTTON_EVENT_CLICK); + _buttonExecuteEvent(i, BUTTON_EVENT_CLICK); break; } @@ -268,8 +187,8 @@ void buttonLoop() { if (unsigned char event = _buttons[i].button->loop()) { unsigned char count = _buttons[i].button->getEventCount(); unsigned long length = _buttons[i].button->getEventLength(); - unsigned char mapped = mapEvent(event, count, length); - buttonEvent(i, mapped); + unsigned char mapped = _buttonGetEvent(event, count, length); + _buttonExecuteEvent(i, mapped); } } @@ -277,4 +196,56 @@ void buttonLoop() { } +// ----------------------------------------------------------------------------- + +void buttonSetup() { + + #ifdef ITEAD_SONOFF_DUAL + + unsigned char relayId = getSetting("btnRelay", 2, RELAY_NONE).toInt(); + unsigned long actions = BUTTON_MODE_TOGGLE << 4; + _buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, 1}); + _buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, 2}); + _buttons.push_back({new DebounceEvent(0, BUTTON_PUSHBUTTON), actions, relayId}); + + #else + + // TODO: maybe this setting should be changed, btnDelay => btnClickDelay? + unsigned long btnDelay = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt(); + + unsigned char index = 0; + while (index < MAX_COMPONENTS) { + + unsigned char pin = getSetting("btnGPIO", index, GPIO_NONE).toInt(); + if (GPIO_NONE == pin) break; + unsigned char relayId = getSetting("btnRelay", index, RELAY_NONE).toInt(); + unsigned char mode = getSetting("btnMode", index, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH).toInt(); + unsigned long actions = _buttonGetActionMask(index); + + // DebounceEvent takes 4 parameters + // * GPIO + // * Button mode + // * Debounce delay + // * Wait delay for more clicks + _buttons.push_back({new DebounceEvent(pin, mode, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, relayId}); + ++index; + + } + + #endif + + DEBUG_MSG_P(PSTR("[BUTTON] Number of buttons: %u\n"), _buttons.size()); + + // Websocket Callbacks + #if WEB_SUPPORT + wsOnSendRegister(_buttonWebSocketOnSend); + #endif + + settingsRegisterKeyCheck(_buttonKeyCheck); + + // Register loop + espurnaRegisterLoop(_buttonLoop); + +} + #endif // BUTTON_SUPPORT diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 32e75298..c49cd2b5 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -7,8 +7,6 @@ // GENERAL //------------------------------------------------------------------------------ -#define DEVICE_NAME MANUFACTURER "_" DEVICE // Concatenate both to get a unique device name - #ifndef ADMIN_PASS #define ADMIN_PASS "fibonacci" // Default password (WEB, OTA, WIFI) #endif @@ -21,6 +19,10 @@ #define LOOP_DELAY_TIME 10 // Delay for this millis in the main loop [0-250] #endif +#ifndef MAX_COMPONENTS +#define MAX_COMPONENTS 8 // Max number of components (buttons, leds, relays,...) +#endif + //------------------------------------------------------------------------------ // DEBUG //------------------------------------------------------------------------------ diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index b4e2e652..1d6da8a3 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -63,48 +63,11 @@ #elif defined(NODEMCU_LOLIN) - // Info - #define MANUFACTURER "NODEMCU" - #define DEVICE "LOLIN" - - // Buttons - #define BUTTON1_PIN 0 - #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH - #define BUTTON1_RELAY 1 - - // Relays - #define RELAY1_PIN 12 - #define RELAY1_TYPE RELAY_TYPE_NORMAL - - // LEDs - #define LED1_PIN 2 - #define LED1_PIN_INVERSE 1 + #include "devices/002_nodemcu_lolin.json.h" #elif defined(WEMOS_D1_MINI_RELAYSHIELD) - // Info - #define MANUFACTURER "WEMOS" - #define DEVICE "D1_MINI_RELAYSHIELD" - - // Buttons - // No buttons on the D1 MINI alone, but defining it without adding a button doen't create problems - #define BUTTON1_PIN 0 // Connect a pushbutton between D3 and GND, - // it's the same as using a Wemos one button shield - #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH - #define BUTTON1_RELAY 1 - - // Relays - #define RELAY1_PIN 5 - #define RELAY1_TYPE RELAY_TYPE_NORMAL - - // LEDs - #define LED1_PIN 2 - #define LED1_PIN_INVERSE 1 - - // When Wemos relay shield is connected GPIO5 (D1) is used for relay, - // so I2C must be remapped to other pins - #define I2C_SDA_PIN 12 // D6 - #define I2C_SCL_PIN 14 // D5 + #include "devices/003_wemos_d1_mini_relayshield.json.h" // ----------------------------------------------------------------------------- // ESPurna @@ -112,24 +75,7 @@ #elif defined(TINKERMAN_ESPURNA_H06) - // Info - #define MANUFACTURER "TINKERMAN" - #define DEVICE "ESPURNA_H06" - - // Buttons - #define BUTTON1_PIN 4 - #define BUTTON1_RELAY 1 - - // Normal pushbutton - #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH - - // Relays - #define RELAY1_PIN 12 - #define RELAY1_TYPE RELAY_TYPE_INVERSE - - // LEDs - #define LED1_PIN 5 - #define LED1_PIN_INVERSE 1 + #include "devices/023_tinkerman_espurna_h06.json.h" // HLW8012 #ifndef HLW8012_SUPPORT @@ -2576,6 +2522,6 @@ // Check definitions // ----------------------------------------------------------------------------- -#if not defined(MANUFACTURER) || not defined(DEVICE) - #error "UNSUPPORTED HARDWARE!!" -#endif +//#if not defined(MANUFACTURER) || not defined(DEVICE) +// #error "UNSUPPORTED HARDWARE!!" +//#endif diff --git a/code/espurna/config/types.h b/code/espurna/config/types.h index 7d69eb25..76aeb45c 100644 --- a/code/espurna/config/types.h +++ b/code/espurna/config/types.h @@ -77,6 +77,8 @@ #define RELAY_PROVIDER_RFBRIDGE 3 #define RELAY_PROVIDER_STM 4 +#define RELAY_NONE 0xFF + //------------------------------------------------------------------------------ // UDP SYSLOG //------------------------------------------------------------------------------ @@ -305,7 +307,7 @@ // GPIO //-------------------------------------------------------------------------------- -#define GPIO_INVALID 0xFF +#define GPIO_NONE 0xFF #define GPIO_LOGIC_DIRECT 0 #define GPIO_LOGIC_INVERSE 1 diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 271703c7..0b10a7a5 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -58,8 +58,9 @@ void setup() { // Init persistance and terminal features settingsSetup(); - // Board name initialization - setBoardName(); + // Load board data + loadBoard(); + migrate(); // Show welcome message and system configuration info(); diff --git a/code/espurna/led.ino b/code/espurna/led.ino index b8603e68..3afbb8e4 100644 --- a/code/espurna/led.ino +++ b/code/espurna/led.ino @@ -22,7 +22,7 @@ typedef struct { } led_t; std::vector _leds; -bool _led_update = false; // For relay-based modes +bool _led_update = true; // For relay-based modes // ----------------------------------------------------------------------------- @@ -128,65 +128,7 @@ void _ledConfigure() { _led_update = true; } -// ----------------------------------------------------------------------------- - -void ledUpdate(bool value) { - _led_update = value; -} - -void ledSetup() { - - #if LED1_PIN != GPIO_NONE - _leds.push_back((led_t) { LED1_PIN, LED1_PIN_INVERSE, LED1_MODE, LED1_RELAY }); - #endif - #if LED2_PIN != GPIO_NONE - _leds.push_back((led_t) { LED2_PIN, LED2_PIN_INVERSE, LED2_MODE, LED2_RELAY }); - #endif - #if LED3_PIN != GPIO_NONE - _leds.push_back((led_t) { LED3_PIN, LED3_PIN_INVERSE, LED3_MODE, LED3_RELAY }); - #endif - #if LED4_PIN != GPIO_NONE - _leds.push_back((led_t) { LED4_PIN, LED4_PIN_INVERSE, LED4_MODE, LED4_RELAY }); - #endif - #if LED5_PIN != GPIO_NONE - _leds.push_back((led_t) { LED5_PIN, LED5_PIN_INVERSE, LED5_MODE, LED5_RELAY }); - #endif - #if LED6_PIN != GPIO_NONE - _leds.push_back((led_t) { LED6_PIN, LED6_PIN_INVERSE, LED6_MODE, LED6_RELAY }); - #endif - #if LED7_PIN != GPIO_NONE - _leds.push_back((led_t) { LED7_PIN, LED7_PIN_INVERSE, LED7_MODE, LED7_RELAY }); - #endif - #if LED8_PIN != GPIO_NONE - _leds.push_back((led_t) { LED8_PIN, LED8_PIN_INVERSE, LED8_MODE, LED8_RELAY }); - #endif - - for (unsigned int i=0; i < _leds.size(); i++) { - pinMode(_leds[i].pin, OUTPUT); - _ledStatus(i, false); - } - - _ledConfigure(); - - #if MQTT_SUPPORT - mqttRegister(_ledMQTTCallback); - #endif - - #if WEB_SUPPORT - wsOnSendRegister(_ledWebSocketOnSend); - wsOnAfterParseRegister(_ledConfigure); - #endif - - DEBUG_MSG_P(PSTR("[LED] Number of leds: %d\n"), _leds.size()); - - // Registers - espurnaRegisterLoop(ledLoop); - settingsRegisterKeyCheck(_ledKeyCheck); - - -} - -void ledLoop() { +void _ledLoop() { uint8_t wifi_state = wifiState(); @@ -204,6 +146,8 @@ void ledLoop() { _ledBlink(i, 500, 500); } + continue; + } if (_ledMode(i) == LED_MODE_FINDME_WIFI) { @@ -226,6 +170,8 @@ void ledLoop() { _ledBlink(i, 500, 500); } + continue; + } if (_ledMode(i) == LED_MODE_RELAY_WIFI) { @@ -248,17 +194,25 @@ void ledLoop() { _ledBlink(i, 500, 500); } + continue; + } // Relay-based modes, update only if relays have been updated if (!_led_update) continue; if (_ledMode(i) == LED_MODE_FOLLOW) { - _ledStatus(i, relayStatus(_leds[i].relay-1)); + if (RELAY_NONE != _leds[i].relay) { + _ledStatus(i, relayStatus(_leds[i].relay)); + } + continue; } if (_ledMode(i) == LED_MODE_FOLLOW_INVERSE) { - _ledStatus(i, !relayStatus(_leds[i].relay-1)); + if (RELAY_NONE != _leds[i].relay) { + _ledStatus(i, !relayStatus(_leds[i].relay)); + } + continue; } if (_ledMode(i) == LED_MODE_FINDME) { @@ -270,6 +224,7 @@ void ledLoop() { } } _ledStatus(i, status); + continue; } if (_ledMode(i) == LED_MODE_RELAY) { @@ -281,14 +236,17 @@ void ledLoop() { } } _ledStatus(i, status); + continue; } if (_ledMode(i) == LED_MODE_ON) { _ledStatus(i, true); + continue; } if (_ledMode(i) == LED_MODE_OFF) { _ledStatus(i, false); + continue; } } @@ -297,4 +255,46 @@ void ledLoop() { } +// ----------------------------------------------------------------------------- + +void ledUpdate(bool value) { + _led_update = value; +} + +void ledSetup() { + + unsigned char index = 0; + while (index < MAX_COMPONENTS) { + + unsigned char pin = getSetting("ledGPIO", index, GPIO_NONE).toInt(); + if (pin == GPIO_NONE) break; + + bool inverse = getSetting("ledLogic", index, 0).toInt() == 1; + unsigned char mode = getSetting("ledMode", index, index==0 ? LED_MODE_WIFI : LED_MODE_MQTT).toInt(); + unsigned char relayId = getSetting("ledRelay", index, RELAY_NONE).toInt(); + + _leds.push_back((led_t) { pin, inverse, mode, relayId }); + pinMode(pin, OUTPUT); + _ledStatus(index, false); + ++index; + + } + + #if MQTT_SUPPORT + mqttRegister(_ledMQTTCallback); + #endif + + #if WEB_SUPPORT + wsOnSendRegister(_ledWebSocketOnSend); + wsOnAfterParseRegister(_ledConfigure); + #endif + + DEBUG_MSG_P(PSTR("[LED] Number of leds: %d\n"), _leds.size()); + + // Registers + espurnaRegisterLoop(_ledLoop); + settingsRegisterKeyCheck(_ledKeyCheck); + +} + #endif LED_SUPPORT diff --git a/code/espurna/mdns.ino b/code/espurna/mdns.ino index 6d8826be..b0604f04 100644 --- a/code/espurna/mdns.ino +++ b/code/espurna/mdns.ino @@ -51,7 +51,7 @@ void mdnsServerSetup() { MDNS.addServiceTxt("arduino", "tcp", "app_name", APP_NAME); MDNS.addServiceTxt("arduino", "tcp", "app_version", APP_VERSION); MDNS.addServiceTxt("arduino", "tcp", "mac", WiFi.macAddress()); - MDNS.addServiceTxt("arduino", "tcp", "target_board", getBoardName()); + MDNS.addServiceTxt("arduino", "tcp", "target_board", getDevice()); { char buffer[6] = {0}; itoa(ESP.getFlashChipRealSize() / 1024, buffer, 10); diff --git a/code/espurna/migrate.ino b/code/espurna/migrate.ino index 17144850..f3e2d357 100644 --- a/code/espurna/migrate.ino +++ b/code/espurna/migrate.ino @@ -17,7 +17,16 @@ void _migrateMoveIndexDown(const char * key, int offset = 0) { } } -void _migrateBackwards() { +// Configuration versions +// +// 1: based on Embedis, no board definitions +// 2: based on Embedis, with board definitions 1-based +// 3: based on Embedis, with board definitions 0-based +// 4: based on Embedis, added sensors and force resetting + +void migrate() { + + moveSetting("boardName", "device"); moveSettings("relayGPIO", "rlyGPIO"); moveSettings("relayResetGPIO", "rlyResetGPIO"); moveSettings("relayType", "rlyType"); @@ -33,25 +42,10 @@ void _migrateBackwards() { moveSetting("hlwSelC", "hlwCurLevel"); moveSetting("hlwIntM", "hlwInt"); delSetting("ledWifi"); -} - -// Configuration versions -// -// 1: based on Embedis, no board definitions -// 2: based on Embedis, with board definitions 1-based -// 3: based on Embedis, with board definitions 0-based -// 4: based on Embedis, added sensors and force resetting - -void migrate() { - - _migrateBackwards(); // Get config version unsigned int board = getSetting("board", 0).toInt(); unsigned int config_version = getSetting("cfg", board > 0 ? 2 : 1).toInt(); - - // Update if not on latest version - if (config_version == CFG_VERSION) return; setSetting("cfg", CFG_VERSION); if (config_version == 2) { @@ -63,1657 +57,4 @@ void migrate() { _migrateMoveIndexDown("rlyType"); } - // ------------------------------------------------------------------------- - // Board definitions - // ------------------------------------------------------------------------- - - #if defined(NODEMCU_LOLIN) - - setSetting("board", 2); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(WEMOS_D1_MINI_RELAYSHIELD) - - setSetting("board", 3); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 5); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_BASIC) - - setSetting("board", 4); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_TH) - - setSetting("board", 5); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_SV) - - setSetting("board", 6); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_TOUCH) - - setSetting("board", 7); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnPress", 0, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 0, BUTTON_MODE_NONE); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngLngClick", 0, BUTTON_MODE_RESET); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_POW) - - setSetting("board", 8); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 15); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - setSetting("hlwEnabled", 1); - setSetting("hlwSELGPIO", 5); - setSetting("hlwCF1GPIO", 13); - setSetting("hlwCFGPIO", 14); - - #elif defined(ITEAD_SONOFF_DUAL) - - setSetting("board", 9); - - setSetting("btnRelay", 0, GPIO_INVALID); - setSetting("btnRelay", 1, GPIO_INVALID); - setSetting("btnRelay", 2, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyProvider", RELAY_PROVIDER_DUAL); - setSetting("rlyCount", 2); - - setSetting("dbgSerial", 0); - setSetting("dbgBaudrate", 19230); - - #elif defined(ITEAD_1CH_INCHING) - - // The inching functionality is managed by a misterious IC in the board. - // You cannot control the inching button and functionality from the ESP8266 - // Besides, enabling the inching functionality using the hardware button - // will result in the relay switching on and off continuously. - // Fortunately the unkown IC keeps memory of the hardware inching status - // so you can just disable it and forget. The inching LED must be lit. - // You can still use the pulse options from the web interface - // without problem. - - setSetting("board", 10); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_4CH) - - setSetting("board", 11); - - setSetting("btnGPIO", 0, 0); - setSetting("btnGPIO", 1, 9); - setSetting("btnGPIO", 2, 10); - setSetting("btnGPIO", 3, 14); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 2, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 3, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - setSetting("btnRelay", 2, 2); - setSetting("btnRelay", 3, 3); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyGPIO", 2, 4); - setSetting("rlyGPIO", 3, 15); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - setSetting("rlyType", 2, RELAY_TYPE_NORMAL); - setSetting("rlyType", 3, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SLAMPHER) - - setSetting("board", 12); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_S20) - - setSetting("board", 13); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ELECTRODRAGON_WIFI_IOT) - - setSetting("board", 14); - - setSetting("btnGPIO", 0, 0); - setSetting("btnGPIO", 1, 2); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - - setSetting("ledGPIO", 0, 16); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyGPIO", 1, 13); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - - #elif defined(WORKCHOICE_ECOPLUG) - - setSetting("board", 15); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 15); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(JANGOE_WIFI_RELAY_NC) - - // Jan Goedeke Wifi Relay - // https://github.com/JanGoe/esp8266-wifi-relay - - setSetting("board", 16); - - setSetting("btnGPIO", 0, 12); - setSetting("btnGPIO", 1, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - - setSetting("rlyGPIO", 0, 2); - setSetting("rlyGPIO", 1, 14); - setSetting("rlyType", 0, RELAY_TYPE_INVERSE); - setSetting("rlyType", 1, RELAY_TYPE_INVERSE); - - #elif defined(JANGOE_WIFI_RELAY_NO) - - setSetting("board", 17); - - setSetting("btnGPIO", 0, 12); - setSetting("btnGPIO", 1, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - - setSetting("rlyGPIO", 0, 2); - setSetting("rlyGPIO", 1, 14); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - - #elif defined(OPENENERGYMONITOR_MQTT_RELAY) - - setSetting("board", 18); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 16); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(JORGEGARCIA_WIFI_RELAYS) - - // Jorge García Wifi+Relays Board Kit - // https://www.tindie.com/products/jorgegarciadev/wifi--relays-board-kit - // https://github.com/jorgegarciadev/wifikit - - setSetting("board", 19); - - setSetting("rlyGPIO", 0, 0); - setSetting("rlyGPIO", 1, 2); - setSetting("rlyType", 0, RELAY_TYPE_INVERSE); - setSetting("rlyType", 1, RELAY_TYPE_INVERSE); - - #elif defined(AITHINKER_AI_LIGHT) - - setSetting("board", 20); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_MY92XX); - - setSetting("myModel", MY92XX_MODEL_MY9291); // 4 channels per chip - setSetting("myChips", 1); - setSetting("myDIGPIO", 13); - setSetting("myDCKIGPIO", 15); - setSetting("myMapping", "0123"); - - #elif defined(MAGICHOME_LED_CONTROLLER) - - setSetting("board", 21); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("irEnabled", 1); - setSetting("irGPIO", 4); - setSetting("irSet", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 14); - setSetting("litChGPIO", 1, 5); - setSetting("litChGPIO", 2, 12); - setSetting("litChGPIO", 3, 13); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 3, GPIO_LOGIC_DIRECT); - - #elif defined(ITEAD_MOTOR) - - setSetting("board", 22); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(TINKERMAN_ESPURNA_H06) - - setSetting("board", 23); - - setSetting("btnGPIO", 0, 4); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 5); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_INVERSE); - - setSetting("hlwEnabled", 1); - setSetting("hlwSELGPIO", 2); - setSetting("hlwCF1GPIO", 13); - setSetting("hlwCFGPIO", 14); - - #elif defined(HUACANXING_H801) - - setSetting("board", 24); - - setSetting("ledGPIO", 0, 5); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("dbgPort", 1); - setSetting("dbgRXEnabled", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 15); - setSetting("litChGPIO", 1, 13); - setSetting("litChGPIO", 2, 12); - setSetting("litChGPIO", 3, 14); - setSetting("litChGPIO", 4, 4); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 3, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 4, GPIO_LOGIC_DIRECT); - - #elif defined(ITEAD_BNSZ01) - - setSetting("board", 25); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 12); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - - #elif defined(ITEAD_SONOFF_RFBRIDGE) - - setSetting("board", 26); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyProvider", RELAY_PROVIDER_RFBRIDGE); - setSetting("rlyCount", 8); - - // When using un-modified harware, ESPurna communicates with the secondary - // MCU EFM8BB1 via UART at 19200 bps so we need to change the speed of - // the port and remove UART noise on serial line - setSetting("dbgSerial", 0); - setSetting("dbgBaudrate", 19200); - - setSetting("rfbDirect", 0); - setSetting("rfbRXGPIO", 4); - setSetting("rfbTXGPIO", 5); - - #elif defined(ITEAD_SONOFF_4CH_PRO) - - setSetting("board", 27); - - setSetting("btnGPIO", 0, 0); - setSetting("btnGPIO", 1, 9); - setSetting("btnGPIO", 2, 10); - setSetting("btnGPIO", 3, 14); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 2, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 3, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - setSetting("btnRelay", 2, 2); - setSetting("btnRelay", 3, 3); - - // Sonoff 4CH Pro uses a secondary STM32 microcontroller to handle - // buttons and relays, but it also forwards button presses to the ESP8285. - // This allows ESPurna to handle button presses -almost- the same way - // as with other devices except: - // * Double click seems to break/disable the button on the STM32 side - // * With S6 switch to 1 (self-locking and inching modes) everything's OK - // * With S6 switch to 0 (interlock mode) if there is a relay ON - // and you click on another relay button, the STM32 sends a "press" - // event for the button of the first relay (to turn it OFF) but it - // does not send a "release" event. It's like it's holding the - // button down since you can see it is still LOW. - // Whatever reason the result is that it may actually perform a - // long click or long-long click. - // The configuration below make the button toggle the relay on press events - // and disables any possibly harmful combination with S6 set to 0. - // If you are sure you will only use S6 to 1 you can comment the - // btnLngClick(0) and btnLngLngClick(0) options below to recover the - // reset mode and factory reset functionalities, or link other actions like - // AP mode in the commented line below. - setSetting("btnPress", 0, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 0, BUTTON_MODE_NONE); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngClick", 0, BUTTON_MODE_NONE); // or BUTTON_MODE_AP - setSetting("btnLngLngClick", 0, BUTTON_MODE_NONE); // or BUTTON_MODE_FACTORY - setSetting("btnPress", 1, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 1, BUTTON_MODE_NONE); - setSetting("btnPress", 2, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 2, BUTTON_MODE_NONE); - setSetting("btnPress", 3, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 3, BUTTON_MODE_NONE); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyGPIO", 2, 4); - setSetting("rlyGPIO", 3, 15); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - setSetting("rlyType", 2, RELAY_TYPE_NORMAL); - setSetting("rlyType", 3, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_B1) - - setSetting("board", 28); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_MY92XX); - setSetting("litChFactor", 4, 0.1); // White LEDs are way more bright in the B1 - setSetting("litChFactor", 5, 0.1); // White LEDs are way more bright in the B1 - - setSetting("myModel", MY92XX_MODEL_MY9231); // 3 channels per chip - setSetting("myChips", 2); - setSetting("myDIGPIO", 12); - setSetting("myDCKIGPIO", 14); - setSetting("myMapping", "43501"); // TODO - - #elif defined(ITEAD_SONOFF_LED) - - setSetting("board", 29); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 12); // Cold white - setSetting("litChGPIO", 1, 14); // Warm white - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - - #elif defined(ITEAD_SONOFF_T1_1CH) - - setSetting("board", 30); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("btnPress", 0, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 0, BUTTON_MODE_NONE); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngLngClick", 0, BUTTON_MODE_RESET); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_T1_2CH) - - setSetting("board", 31); - - setSetting("btnGPIO", 0, 0); - setSetting("btnGPIO", 1, 9); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - - setSetting("btnPress", 0, BUTTON_MODE_TOGGLE); - setSetting("btnPress", 1, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 0, BUTTON_MODE_NONE); - setSetting("btnClick", 1, BUTTON_MODE_NONE); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - setSetting("btnDblClick", 1, BUTTON_MODE_NONE); - setSetting("btnLngClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngClick", 1, BUTTON_MODE_NONE); - setSetting("btnLngLngClick", 0, BUTTON_MODE_RESET); - setSetting("btnLngLngClick", 1, BUTTON_MODE_RESET); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_T1_3CH) - - setSetting("board", 32); - - setSetting("btnGPIO", 0, 0); - setSetting("btnGPIO", 1, 9); - setSetting("btnGPIO", 2, 10); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 2, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - setSetting("btnRelay", 2, 2); - - setSetting("btnPress", 0, BUTTON_MODE_TOGGLE); - setSetting("btnPress", 1, BUTTON_MODE_TOGGLE); - setSetting("btnPress", 2, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 0, BUTTON_MODE_NONE); - setSetting("btnClick", 1, BUTTON_MODE_NONE); - setSetting("btnClick", 2, BUTTON_MODE_NONE); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - setSetting("btnDblClick", 1, BUTTON_MODE_NONE); - setSetting("btnDblClick", 2, BUTTON_MODE_NONE); - setSetting("btnLngClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngClick", 1, BUTTON_MODE_NONE); - setSetting("btnLngClick", 2, BUTTON_MODE_NONE); - setSetting("btnLngLngClick", 0, BUTTON_MODE_RESET); - setSetting("btnLngLngClick", 1, BUTTON_MODE_RESET); - setSetting("btnLngLngClick", 2, BUTTON_MODE_RESET); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyGPIO", 2, 4); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - setSetting("rlyType", 2, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_RF) - - setSetting("board", 33); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(WION_50055) - - // WiOn 50055 Indoor Wi-Fi Wall Outlet & Tap - // https://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_id=114&ipn=icep&toolid=20004&campid=5338044841&mpre=http%3A%2F%2Fwww.ebay.com%2Fitm%2FWiOn-50050-Indoor-Wi-Fi-Outlet-Wireless-Switch-Programmable-Timer-%2F263112281551 - // https://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_id=114&ipn=icep&toolid=20004&campid=5338044841&mpre=http%3A%2F%2Fwww.ebay.com%2Fitm%2FWiOn-50055-Indoor-Wi-Fi-Wall-Tap-Monitor-Energy-Usage-Wireless-Smart-Switch-%2F263020837777 - // Does not support power monitoring yet - - setSetting("board", 34); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 15); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(EXS_WIFI_RELAY_V31) - - // EX-Store Wifi Relay v3.1 - // https://ex-store.de/ESP8266-WiFi-Relay-V31 - - setSetting("board", 35); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("rlyGPIO", 0, 13); - setSetting("rlyResetGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_LATCHED); - - #elif defined(HUACANXING_H802) - - setSetting("board", 36); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("dbgPort", 1); - setSetting("dbgRXEnabled", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 12); - setSetting("litChGPIO", 1, 14); - setSetting("litChGPIO", 2, 13); - setSetting("litChGPIO", 3, 15); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 3, GPIO_LOGIC_DIRECT); - - #elif defined(GENERIC_V9261F) - - setSetting("board", 37); - - setSetting("v92Enabled", 1); - setSetting("v92GPIO", 2); - setSetting("v92Logic", GPIO_LOGIC_INVERSE); - - #elif defined(GENERIC_ECH1560) - - setSetting("board", 38); - - setSetting("echEnabled", 1); - setSetting("echCLKGPIO", 4); - setSetting("echMISOGPIO", 5); - setSetting("echLogic", GPIO_LOGIC_INVERSE); - - #elif defined(TINKERMAN_ESPURNA_H08) - - setSetting("board", 39); - - setSetting("btnGPIO", 0, 4); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - setSetting("hlwEnabled", 1); - setSetting("hlwSELGPIO", 5); - setSetting("hlwCF1GPIO", 13); - setSetting("hlwCFGPIO", 14); - - #elif defined(MANCAVEMADE_ESPLIVE) - - // ESPLive - // https://github.com/ManCaveMade/ESP-Live - - setSetting("board", 40); - - setSetting("btnGPIO", 0, 4); - setSetting("btnGPIO", 1, 5); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyGPIO", 1, 13); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - - setSetting("dsEnabled", 1); - setSetting("dsGPIO", 0, 2); - - #elif defined(INTERMITTECH_QUINLED) - - // QuinLED - // http://blog.quindorian.org/2017/02/esp8266-led-lighting-quinled-v2-6-pcb.html - - setSetting("board", 41); - - setSetting("ledGPIO", 0, 5); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 0); - setSetting("litChGPIO", 1, 2); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - - #elif defined(MAGICHOME_LED_CONTROLLER_20) - - setSetting("board", 42); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("irEnabled", 1); - setSetting("irGPIO", 4); - setSetting("irSet", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 5); - setSetting("litChGPIO", 1, 12); - setSetting("litChGPIO", 2, 13); - setSetting("litChGPIO", 3, 15); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 3, GPIO_LOGIC_DIRECT); - - #elif defined(ARILUX_AL_LC06) - - setSetting("board", 43); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 14); - setSetting("litChGPIO", 1, 12); - setSetting("litChGPIO", 2, 13); - setSetting("litChGPIO", 3, 15); - setSetting("litChGPIO", 4, 5); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 3, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 4, GPIO_LOGIC_DIRECT); - - #elif defined(XENON_SM_PW702U) - - setSetting("board", 44); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 4); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(AUTHOMETION_LYT8266) - - // AUTHOMETION LYT8266 - // https://authometion.com/shop/en/home/13-lyt8266.html - - setSetting("board", 45); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 13); - setSetting("litChGPIO", 1, 12); - setSetting("litChGPIO", 2, 14); - setSetting("litChGPIO", 3, 2); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 3, GPIO_LOGIC_DIRECT); - setSetting("litEnableGPIO", 15); - setSetting("litEnableLogic", GPIO_LOGIC_DIRECT); - - #elif defined(ARILUX_E27) - - setSetting("board", 46); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_MY92XX); - - setSetting("myModel", MY92XX_MODEL_MY9291); // 4 channels per chip - setSetting("myChips", 1); - setSetting("myDIGPIO", 13); - setSetting("myDCKIGPIO", 15); - setSetting("myMapping", "0123"); - - #elif defined(YJZK_SWITCH_2CH) - - setSetting("board", 47); - - setSetting("btnGPIO", 0, 0); - setSetting("btnGPIO", 1, 9); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_DUAL_R2) - - setSetting("board", 48); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("btnGPIO", 1, 9); - setSetting("btnGPIO", 2, 10); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 2, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 1, 1); - setSetting("btnRelay", 2, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - - #elif defined(GENERIC_8CH) - - setSetting("board", 49); - - setSetting("rlyGPIO", 0, 0); - setSetting("rlyGPIO", 1, 2); - setSetting("rlyGPIO", 2, 4); - setSetting("rlyGPIO", 3, 5); - setSetting("rlyGPIO", 4, 12); - setSetting("rlyGPIO", 5, 13); - setSetting("rlyGPIO", 6, 14); - setSetting("rlyGPIO", 7, 15); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - setSetting("rlyType", 2, RELAY_TYPE_NORMAL); - setSetting("rlyType", 3, RELAY_TYPE_NORMAL); - setSetting("rlyType", 4, RELAY_TYPE_NORMAL); - setSetting("rlyType", 5, RELAY_TYPE_NORMAL); - setSetting("rlyType", 6, RELAY_TYPE_NORMAL); - setSetting("rlyType", 7, RELAY_TYPE_NORMAL); - - #elif defined(ARILUX_AL_LC01) - - setSetting("board", 50); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 5); - setSetting("litChGPIO", 1, 12); - setSetting("litChGPIO", 2, 13); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - - #elif defined(ARILUX_AL_LC11) - - setSetting("board", 51); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 5); - setSetting("litChGPIO", 1, 4); - setSetting("litChGPIO", 2, 14); - setSetting("litChGPIO", 3, 13); - setSetting("litChGPIO", 4, 12); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 3, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 4, GPIO_LOGIC_DIRECT); - - #elif defined(ARILUX_AL_LC02) - - setSetting("board", 52); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 12); - setSetting("litChGPIO", 1, 5); - setSetting("litChGPIO", 2, 13); - setSetting("litChGPIO", 3, 15); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 3, GPIO_LOGIC_DIRECT); - - #elif defined(KMC_70011) - - // KMC 70011 - // https://www.amazon.com/KMC-Monitoring-Required-Control-Compatible/dp/B07313TH7B - - setSetting("board", 53); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 14); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - setSetting("hlwEnabled", 1); - setSetting("hlwSELGPIO", 12); - setSetting("hlwCF1GPIO", 5); - setSetting("hlwCFGPIO", 4); - setSetting("hlwVolResUp", 2000000); - - #elif defined(GIZWITS_WITTY_CLOUD) - - setSetting("board", 54); - - setSetting("btnGPIO", 0, 4); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnPress", 0, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 0, BUTTON_MODE_NONE); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngLngClick", 0, BUTTON_MODE_RESET); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyProvider", RELAY_PROVIDER_LIGHT); - setSetting("rlyCount", 1); - - setSetting("anaEnabled", 1); - - setSetting("litProvider", LIGHT_PROVIDER_DIMMER); - setSetting("litChGPIO", 0, 15); - setSetting("litChGPIO", 1, 12); - setSetting("litChGPIO", 2, 13); - setSetting("litChLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 1, GPIO_LOGIC_DIRECT); - setSetting("litChLogic", 2, GPIO_LOGIC_DIRECT); - - #elif defined(EUROMATE_WIFI_STECKER_SCHUKO) - - // Euromate (?) Wifi Stecker Shuko - // https://www.obi.de/hausfunksteuerung/wifi-stecker-schuko/p/2291706 - // Thanks to @Geitde - - // The relay in the device is not a bistable (latched) relay. - // The device is reported to have a flip-flop circuit to drive the relay - // So @Geitde hack is still the only possible - // Hack: drive GPIO12 low and use GPIO5 as normal relay pin: - - setSetting("board", 55); - - setSetting("btnGPIO", 0, 14); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH | BUTTON_SET_PULLUP); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 4); - setSetting("ledGPIO", 1, 12); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("ledLogic", 1, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 5); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(TONBUX_POWERSTRIP02) - - setSetting("board", 56); - - setSetting("btnGPIO", 0, 5); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 1); - - setSetting("ledGPIO", 0, 0); // 1 blue led - setSetting("ledGPIO", 1, 3); // 3 red leds - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - setSetting("ledLogic", 1, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 4); - setSetting("rlyGPIO", 1, 13); - setSetting("rlyGPIO", 2, 12); - setSetting("rlyGPIO", 3, 14); - setSetting("rlyGPIO", 4, 16); // Not a relay. USB ports on/off - setSetting("rlyType", 0, RELAY_TYPE_INVERSE); - setSetting("rlyType", 1, RELAY_TYPE_INVERSE); - setSetting("rlyType", 2, RELAY_TYPE_INVERSE); - setSetting("rlyType", 3, RELAY_TYPE_INVERSE); - setSetting("rlyType", 4, RELAY_TYPE_NORMAL); // Not a relay. USB ports on/off - - #elif defined(LINGAN_SWA1) - - setSetting("board", 57); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH | BUTTON_SET_PULLUP); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 4); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 5); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(HEYGO_HY02) - - setSetting("board", 58); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 4); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(MAXCIO_WUS002S) - - setSetting("board", 59); - - setSetting("btnGPIO", 0, 2); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 3); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 13); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - setSetting("hlwEnabled", 1); - setSetting("hlwSELGPIO", 12); - setSetting("hlwCF1GPIO", 5); - setSetting("hlwCFGPIO", 4); - setSetting("hlwCurRes", 0.002); - setSetting("hlwVolResUp", 2000000); - - #elif defined(YIDIAN_XSSSA05) - - setSetting("board", 60); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 4); - setSetting("ledGPIO", 2, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("ledLogic", 2, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - setSetting("hlwEnabled", 1); - setSetting("hlwSELGPIO", 3); - setSetting("hlwCF1GPIO", 14); - setSetting("hlwCFGPIO", 5); - setSetting("hlwVolResUp", 2400000); - - #elif defined(TONBUX_XSSSA06) - - setSetting("board", 61); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 0); // Red - setSetting("ledGPIO", 0, 5); // Green - setSetting("ledGPIO", 0, 2); // Blue - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 15); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(GREEN_ESP8266RELAY) - - // GREEN ESP8266 RELAY MODULE - // https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20180323113846&SearchText=Green+ESP8266 - - setSetting("board", 62); - - setSetting("btnGPIO", 0, 5); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 4); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(IKE_ESPIKE) - - // Henrique Gravina ESPIKE - // https://github.com/Henriquegravina/Espike - - setSetting("board", 63); - - setSetting("btnGPIO", 0, 13); - setSetting("btnGPIO", 1, 12); - setSetting("btnGPIO", 2, 14); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 2, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - setSetting("btnRelay", 2, 2); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngLngClick", 0, BUTTON_MODE_NONE); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 4); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyGPIO", 2, 16); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - setSetting("rlyType", 2, RELAY_TYPE_NORMAL); - - #elif defined(ARNIEX_SWIFITCH) - - // SWIFITCH - // https://github.com/ArnieX/swifitch - - setSetting("board", 64); - - setSetting("btnGPIO", 0, 4); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH | BUTTON_SET_PULLUP); - setSetting("btnRelay", 0, 1); - setSetting("btnPress", 0, BUTTON_MODE_NONE); - setSetting("btnClick", 0, BUTTON_MODE_TOGGLE); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngLngClick", 0, BUTTON_MODE_NONE); - - setSetting("ledGPIO", 0, 12); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 5); - setSetting("rlyType", 0, RELAY_TYPE_INVERSE); - - #elif defined(GENERIC_ESP01S_RELAY_V40) - - // ESP-01S RELAY v4.0 - // https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20180404024035&SearchText=esp-01s+relay - - setSetting("board", 65); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 0); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(GENERIC_ESP01S_RGBLED_V10) - - // ESP-01S RGB LED v1.0 (some sold with ws2818) - // https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20180404023816&SearchText=esp-01s+led+controller - - setSetting("board", 66); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - #elif defined(HELTEC_TOUCHRELAY) - - // Heltec Touch Relay - // https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20180408043114&SearchText=esp8266+touch+relay - - setSetting("board", 67); - - setSetting("btnGPIO", 0, 14); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 1); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(GENERIC_ESP01S_DHT11_V10) - - // ESP-01S DHT11 v1.0 - // https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20180410105907&SearchText=esp-01s+dht11 - - setSetting("board", 68); - - setSetting("dhtEnabled", 1); - setSetting("dhtGPIO", 0, 2); - setSetting("dhtType", 0, DHT_CHIP_DHT11); - - #elif defined(GENERIC_ESP01S_DS18B20_V10) - - // ESP-01S DS18B20 v1.0 - // https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20180410105933&SearchText=esp-01s+ds18b20 - - setSetting("board", 69); - - setSetting("dsEnabled", 1); - setSetting("dsGPIO", 0, 2); - - #elif defined(ZHILDE_EU44_W) - - // Zhilde ZLD-EU44-W - // http://www.zhilde.com/product/60705150109-805652505/EU_WiFi_Surge_Protector_Extension_Socket_4_Outlets_works_with_Amazon_Echo_Smart_Power_Strip.html - - setSetting("board", 70); - - setSetting("btnGPIO", 0, 3); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 1); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 5); - setSetting("rlyGPIO", 1, 4); - setSetting("rlyGPIO", 2, 12); - setSetting("rlyGPIO", 3, 13); - setSetting("rlyGPIO", 4, 14); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - setSetting("rlyType", 2, RELAY_TYPE_NORMAL); - setSetting("rlyType", 3, RELAY_TYPE_NORMAL); - setSetting("rlyType", 4, RELAY_TYPE_NORMAL); - - // Based on the reporter, this product uses GPIO1 and 3 for the button - // and onboard LED, so hardware serial should be disabled... - setSetting("dbgSerial", 0); - - #elif defined(ITEAD_SONOFF_POW_R2) - - setSetting("board", 71); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - setSetting("cseEnabled", 1); - setSetting("cseGPIO", 1); - - setSetting("dbgSerial", 0); - - #elif defined(LUANI_HVIO) - - // Luani HVIO - // https://luani.de/projekte/esp8266-hvio/ - // https://luani.de/blog/esp8266-230v-io-modul/ - - setSetting("board", 72); - - setSetting("ledGPIO", 0, 15); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("btnGPIO", 0, 12); - setSetting("btnGPIO", 1, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - - setSetting("rlyGPIO", 0, 4); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - - #elif defined(ALLNET_4DUINO_IOT_WLAN_RELAIS) - - // Allnet 4duino ESP8266-UP-Relais - // http://www.allnet.de/de/allnet-brand/produkte/neuheiten/p/allnet-4duino-iot-wlan-relais-unterputz-esp8266-up-relais/ - // https://shop.allnet.de/fileadmin/transfer/products/148814.pdf - - setSetting("board", 73); - - setSetting("ledGPIO", 0, 0); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 14); - setSetting("rlyResetGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_LATCHED); - - #elif defined(TONBUX_MOSQUITO_KILLER) - - // Tonbux 50-100M Smart Mosquito Killer USB - // https://www.aliexpress.com/item/Original-Tonbux-50-100M-Smart-Mosquito-Killer-USB-Plug-No-Noise-Repellent-App-Smart-Module/32859330820.html - - setSetting("board", 74); - - setSetting("btnGPIO", 0, 2); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 15); - setSetting("ledGPIO", 1, 14); - setSetting("ledGPIO", 2, 12); - setSetting("ledGPIO", 3, 16); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - setSetting("ledLogic", 1, GPIO_LOGIC_INVERSE); - setSetting("ledLogic", 2, GPIO_LOGIC_DIRECT); - setSetting("ledLogic", 3, GPIO_LOGIC_DIRECT); - setSetting("ledMode", 0, LED_MODE_WIFI); - setSetting("ledMode", 1, LED_MODE_RELAY); - setSetting("ledRelay", 1, 0); - - setSetting("rlyGPIO", 0, 5); // Fan - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(NEO_COOLCAM_NAS_WR01W) - - // NEO Coolcam NAS-WR01W Wifi Smart Power Plug - // https://es.aliexpress.com/item/-/32854589733.html?spm=a219c.12010608.0.0.6d084e68xX0y5N - // https://www.fasttech.com/product/9649426-neo-coolcam-nas-wr01w-wifi-smart-power-plug-eu - - setSetting("board", 75); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 4); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(PILOTAK_ESP_DIN_V1) - - // ESP-DIN relay board V1 - // https://github.com/pilotak/esp_din - - setSetting("board", 76); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 15); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 4); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - - setSetting("digEnabled", 1); - setSetting("digGPIO", 0, 16); - setSetting("digMode", 0, INPUT); - - setSetting("dsEnabled", 1); - setSetting("dsGPIO", 0, 2); - - setSetting("i2cEnable", 1); - setSetting("i2cSDAGPIO", 12); - setSetting("i2cSCLGPIO", 13); - - setSetting("rfEnabled", 1); - setSetting("rfGPIO", 14); - - #elif defined(ESTINK_WIFI_POWER_STRIP) - - // Estink Wifi Power Strip - // https://www.amazon.de/Steckdosenleiste-Ladeger%C3%A4t-Sprachsteuerung-SmartphonesTablets-Android/dp/B0796W5FZY - // Fornorm Wi-Fi USB Extension Socket (ZLD-34EU) - // https://www.aliexpress.com/item/Fornorm-WiFi-Extension-Socket-with-Surge-Protector-Smart-Power-Strip-3-Outlets-and-4-USB-Charging/32849743948.html - - setSetting("board", 77); - - setSetting("btnGPIO", 0, 16); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 3); - - setSetting("ledGPIO", 0, 0); - setSetting("ledGPIO", 1, 12); - setSetting("ledGPIO", 2, 3); - setSetting("ledGPIO", 3, 5); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - setSetting("ledLogic", 1, GPIO_LOGIC_INVERSE); - setSetting("ledLogic", 2, GPIO_LOGIC_INVERSE); - setSetting("ledLogic", 3, GPIO_LOGIC_INVERSE); - setSetting("ledMode", 0, LED_MODE_FINDME); - setSetting("ledMode", 1, LED_MODE_FOLLOW); - setSetting("ledMode", 2, LED_MODE_FOLLOW); - setSetting("ledMode", 3, LED_MODE_FOLLOW); - setSetting("ledRelay", 1, 1); - setSetting("ledRelay", 2, 2); - setSetting("ledRelay", 3, 3); - - setSetting("rlyGPIO", 0, 14); // USB power - setSetting("rlyGPIO", 1, 13); // power plug 1 - setSetting("rlyGPIO", 2, 4); // power plug 2 - setSetting("rlyGPIO", 3, 15); // power plug 3 - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - setSetting("rlyType", 2, RELAY_TYPE_NORMAL); - setSetting("rlyType", 3, RELAY_TYPE_NORMAL); - - setSetting("dbgSerial", 0); - - #elif defined(BH_ONOFRE) - - // Bruno Horta's OnOfre - // https://www.bhonofre.pt/ - // https://github.com/brunohorta82/BH_OnOfre/ - - setSetting("board", 78); - - setSetting("btnGPIO", 0, 12); - setSetting("btnGPIO", 1, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH | BUTTON_SET_PULLUP); - setSetting("btnMode", 1, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH | BUTTON_SET_PULLUP); - setSetting("btnRelay", 0, 0); - setSetting("btnRelay", 1, 1); - - setSetting("rlyGPIO", 0, 4); - setSetting("rlyGPIO", 1, 5); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - setSetting("rlyType", 1, RELAY_TYPE_NORMAL); - - #elif defined(BLITZWOLF_BWSHP2) - - // Several boards under different names uing a power chip labelled BL0937 or HJL-01 - // * Blitzwolf (https://www.amazon.es/Inteligente-Temporización-Dispositivos-Cualquier-BlitzWolf/dp/B07BMQP142) - // * HomeCube (https://www.amazon.de/Steckdose-Homecube-intelligente-Verbrauchsanzeige-funktioniert/dp/B076Q2LKHG) - // * Coosa (https://www.amazon.com/COOSA-Monitoring-Function-Campatible-Assiatant/dp/B0788W9TDR) - // * Goosund (http://www.gosund.com/?m=content&c=index&a=show&catid=6&id=5) - // * Ablue (https://www.amazon.de/Intelligente-Steckdose-Ablue-Funktioniert-Assistant/dp/B076DRFRZC) - - setSetting("board", 79); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 2); - setSetting("ledGPIO", 1, 0); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - setSetting("ledLogic", 1, GPIO_LOGIC_INVERSE); - setSetting("ledMode", 0, LED_MODE_WIFI); - setSetting("ledMode", 1, LED_MODE_FINDME); - setSetting("ledRelay", 1, 0); - - setSetting("rlyGPIO", 0, 15); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - setSetting("hlwSELGPIO", 12); - setSetting("hlwCF1GPIO", 14); - setSetting("hlwCFGPIO", 5); - setSetting("hlwCurLevel", LOW); - setSetting("hlwInt", FALLING); - setSetting("curRatio", 25740); - setSetting("volRatio", 313400); - setSetting("pwrRatio", 3414290); - - - #elif defined(TINKERMAN_ESPURNA_SWITCH) - - setSetting("board", 80); - - setSetting("btnGPIO", 0, 4); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON); - setSetting("btnPress", 0, BUTTON_MODE_TOGGLE); - setSetting("btnClick", 0, BUTTON_MODE_NONE); - setSetting("btnDblClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngClick", 0, BUTTON_MODE_NONE); - setSetting("btnLngLngClick", 0, BUTTON_MODE_NONE); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 2); - setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - #elif defined(ITEAD_SONOFF_S31) - - setSetting("board", 81); - - setSetting("btnGPIO", 0, 0); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 13); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - - setSetting("rlyGPIO", 0, 12); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - setSetting("cseEnabled", 1); - setSetting("cseGPIO", 1); - - setSetting("dbgSerial", 0); - - #elif defined(STM_RELAY) - - setSetting("board", 82); - - setSetting("rlyCount", 2); - setSetting("rlyProvider", RELAY_PROVIDER_STM) - - setSetting("dbgSerial", 0); - - #elif defined(VANZAVANZU_SMART_WIFI_PLUG_MINI) - - // VANZAVANZU Smart Outlet Socket (based on BL0937 or HJL-01) - // https://www.amazon.com/Smart-Plug-Wifi-Mini-VANZAVANZU/dp/B078PHD6S5 - - setSetting("board", 83); - - setSetting("btnGPIO", 0, 13); - setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); - setSetting("btnRelay", 0, 0); - - setSetting("ledGPIO", 0, 2); - setSetting("ledGPIO", 1, 0); - setSetting("ledLogic", 0, GPIO_LOGIC_INVERSE); - setSetting("ledLogic", 1, GPIO_LOGIC_INVERSE); - setSetting("ledMode", 0, LED_MODE_WIFI); - setSetting("ledMode", 1, LED_MODE_FINDME); - setSetting("ledRelay", 1, 0); - - setSetting("rlyGPIO", 0, 15); - setSetting("rlyType", 0, RELAY_TYPE_NORMAL); - - setSetting("hlwSELGPIO", 3); - setSetting("hlwCF1GPIO", 14); - setSetting("hlwCFGPIO", 5); - setSetting("hlwCurLevel", LOW); - setSetting("hlwInt", FALLING); - setSetting("curRatio", 25740); - setSetting("volRatio", 313400); - setSetting("pwrRatio", 3414290); - - #elif defined(GENERIC_GEIGER_COUNTER) - - setSetting("board", 83); - - setSetting("geiEnabled", 1); - - #elif defined(TINKERMAN_RFM69GW) - - setSetting("board", 84); - - setSetting("btnGPIO", 0, 0); - - setSetting("rfm69Enabled", 1); - setSetting("rfm69CSGPIO", 15); - setSetting("rfm69IRQGPIO", 5); - setSetting("rfm69ResetGPIO", 7); - setSetting("rfm69HW", 0) - - #else - - // Allow users to define new settings without migration config - //#error "UNSUPPORTED HARDWARE!" - - #endif - } diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 8be23db4..812912f6 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -907,39 +907,32 @@ void relaySetup() { // Dummy relays for AI Light, Magic Home LED Controller, H801, // Sonoff Dual and Sonoff RF Bridge - #if DUMMY_RELAY_COUNT > 0 - unsigned int _delay_on[8] = {RELAY1_DELAY_ON, RELAY2_DELAY_ON, RELAY3_DELAY_ON, RELAY4_DELAY_ON, RELAY5_DELAY_ON, RELAY6_DELAY_ON, RELAY7_DELAY_ON, RELAY8_DELAY_ON}; - unsigned int _delay_off[8] = {RELAY1_DELAY_OFF, RELAY2_DELAY_OFF, RELAY3_DELAY_OFF, RELAY4_DELAY_OFF, RELAY5_DELAY_OFF, RELAY6_DELAY_OFF, RELAY7_DELAY_OFF, RELAY8_DELAY_OFF}; - for (unsigned char i=0; i < DUMMY_RELAY_COUNT; i++) { - _relays.push_back((relay_t) {0, RELAY_TYPE_NORMAL,0,_delay_on[i], _delay_off[i]}); + #if DUMMY_RELAY_COUNT > 0 // TODO: this is yet hardcoded + + for (unsigned char index=0; index < DUMMY_RELAY_COUNT; index++) { + unsigned long delay_on = getSetting("rlyDelayOn", index, 0).toInt(); + unsigned long delay_off = getSetting("rlyDelayOff", index, 0).toInt(); + _relays.push_back((relay_t) {0, RELAY_TYPE_NORMAL, 0, delay_on, delay_off}); } #else - #if RELAY1_PIN != GPIO_NONE - _relays.push_back((relay_t) { RELAY1_PIN, RELAY1_TYPE, RELAY1_RESET_PIN, RELAY1_DELAY_ON, RELAY1_DELAY_OFF }); - #endif - #if RELAY2_PIN != GPIO_NONE - _relays.push_back((relay_t) { RELAY2_PIN, RELAY2_TYPE, RELAY2_RESET_PIN, RELAY2_DELAY_ON, RELAY2_DELAY_OFF }); - #endif - #if RELAY3_PIN != GPIO_NONE - _relays.push_back((relay_t) { RELAY3_PIN, RELAY3_TYPE, RELAY3_RESET_PIN, RELAY3_DELAY_ON, RELAY3_DELAY_OFF }); - #endif - #if RELAY4_PIN != GPIO_NONE - _relays.push_back((relay_t) { RELAY4_PIN, RELAY4_TYPE, RELAY4_RESET_PIN, RELAY4_DELAY_ON, RELAY4_DELAY_OFF }); - #endif - #if RELAY5_PIN != GPIO_NONE - _relays.push_back((relay_t) { RELAY5_PIN, RELAY5_TYPE, RELAY5_RESET_PIN, RELAY5_DELAY_ON, RELAY5_DELAY_OFF }); - #endif - #if RELAY6_PIN != GPIO_NONE - _relays.push_back((relay_t) { RELAY6_PIN, RELAY6_TYPE, RELAY6_RESET_PIN, RELAY6_DELAY_ON, RELAY6_DELAY_OFF }); - #endif - #if RELAY7_PIN != GPIO_NONE - _relays.push_back((relay_t) { RELAY7_PIN, RELAY7_TYPE, RELAY7_RESET_PIN, RELAY7_DELAY_ON, RELAY7_DELAY_OFF }); - #endif - #if RELAY8_PIN != GPIO_NONE - _relays.push_back((relay_t) { RELAY8_PIN, RELAY8_TYPE, RELAY8_RESET_PIN, RELAY8_DELAY_ON, RELAY8_DELAY_OFF }); - #endif + unsigned char index = 0; + while (index < MAX_COMPONENTS) { + + unsigned char pin = getSetting("rlyGPIO", index, GPIO_NONE).toInt(); + if (GPIO_NONE == pin) break; + unsigned char type = getSetting("rlyType", index, 0).toInt(); + unsigned char reset = getSetting("rlyResetGPIO", index, GPIO_NONE).toInt(); + if (((type & RELAY_TYPE_LATCHED) == RELAY_TYPE_LATCHED) && (GPIO_NONE == reset)) break; + + unsigned long delay_on = getSetting("rlyDelayOn", index, 0).toInt(); + unsigned long delay_off = getSetting("rlyDelayOff", index, 0).toInt(); + + _relays.push_back((relay_t) { pin, type, reset, delay_on, delay_off }); + ++index; + + } #endif diff --git a/code/espurna/ssdp.ino b/code/espurna/ssdp.ino index e788626e..7927f380 100644 --- a/code/espurna/ssdp.ino +++ b/code/espurna/ssdp.ino @@ -56,7 +56,7 @@ void ssdpSetup() { APP_NAME, // modelName APP_VERSION, // modelNumber APP_WEBSITE, // modelURL - DEVICE_NAME, // manufacturer + getDevice(), // manufacturer "", // manufacturerURL chipId // UUID ); diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 04cd4deb..06f4f03d 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -34,14 +34,34 @@ String getPassword() { return getSetting("adminPass", ADMIN_PASS); } -void setBoardName() { +void loadBoard() { #ifndef ESPURNA_CORE - setSetting("boardName", DEVICE_NAME); + char buffer[device_config_len+1]; + strncpy_P(buffer, (const char *) device_config, device_config_len); + buffer[device_config_len] = 0; + DynamicJsonBuffer jsonBuffer; + JsonObject& json = jsonBuffer.parseObject(buffer); + json["app"] = APP_NAME; + settingsRestoreJson(json); #endif } +String getManufacturer() { + String device = getDevice(); + uint8_t pos = device.indexOf("_"); + if (pos > 0) return device.substring(0, pos); + return String(); +} + String getBoardName() { - return getSetting("boardName", DEVICE_NAME); + String device = getDevice(); + uint8_t pos = device.indexOf("_"); + if (pos > 0) return device.substring(pos+1); + return device; +} + +String getDevice() { + return getSetting("device", "GENERIC_CUSTOM"); } String getCoreVersion() { diff --git a/code/espurna/web.ino b/code/espurna/web.ino index e578ed7e..011360b2 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -67,7 +67,7 @@ void _onDiscover(AsyncWebServerRequest *request) { root["app"] = APP_NAME; root["version"] = APP_VERSION; root["hostname"] = getHostname(); - root["device"] = getBoardName(); + root["device"] = getDevice(); root.printTo(*response); request->send(response); diff --git a/code/espurna/ws.ino b/code/espurna/ws.ino index 357523de..cfa962d1 100644 --- a/code/espurna/ws.ino +++ b/code/espurna/ws.ino @@ -311,12 +311,12 @@ void _wsOnStart(JsonObject& root) { root["app_version"] = APP_VERSION; root["app_build"] = buildTime(); root["app_revision"] = APP_REVISION; - root["manufacturer"] = MANUFACTURER; + root["manufacturer"] = getManufacturer(); root["chipid"] = String(chipid); root["mac"] = WiFi.macAddress(); root["bssid"] = String(bssid_str); root["channel"] = WiFi.channel(); - root["device"] = DEVICE; + root["device"] = getBoardName(); root["hostname"] = getHostname(); root["network"] = getNetwork(); root["deviceip"] = getIP(); diff --git a/code/lib/readme.txt b/code/lib/readme.txt deleted file mode 100644 index 607a92af..00000000 --- a/code/lib/readme.txt +++ /dev/null @@ -1,38 +0,0 @@ - -This directory is intended for the project specific (private) libraries. -PlatformIO will compile them to static libraries and link to executable file. - -The source code of each library should be placed in separate directory, like -"lib/private_lib/[here are source files]". - -For example, see how can be organized `Foo` and `Bar` libraries: - -|--lib -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| |--Foo -| | |- Foo.c -| | |- Foo.h -| |- readme.txt --> THIS FILE -|- platformio.ini -|--src - |- main.c - -Then in `src/main.c` you should use: - -#include -#include - -// rest H/C/CPP code - -PlatformIO will find your libraries automatically, configure preprocessor's -include paths and build them. - -See additional options for PlatformIO Library Dependency Finder `lib_*`: - -http://docs.platformio.org/en/latest/projectconf.html#lib-install -