diff --git a/code/espurna/button.ino b/code/espurna/button.ino index ea550e1f..4d8afef5 100644 --- a/code/espurna/button.ino +++ b/code/espurna/button.ino @@ -10,6 +10,8 @@ Copyright (C) 2016-2018 by Xose Pérez // BUTTON // ----------------------------------------------------------------------------- +#if BUTTON_SUPPORT + #include #include @@ -266,3 +268,5 @@ void buttonLoop() { #endif } + +#endif // BUTTON_SUPPORT diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 395025bf..32e75298 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -201,6 +201,10 @@ // BUTTON //------------------------------------------------------------------------------ +#ifndef BUTTON_SUPPORT +#define BUTTON_SUPPORT 1 +#endif + #ifndef BUTTON_DEBOUNCE_DELAY #define BUTTON_DEBOUNCE_DELAY 50 // Debounce delay (ms) #endif @@ -217,6 +221,14 @@ #define BUTTON_LNGLNGCLICK_DELAY 10000 // Time in ms holding the button down to get a long-long click #endif +//------------------------------------------------------------------------------ +// LED +//------------------------------------------------------------------------------ + +#ifndef LED_SUPPORT +#define LED_SUPPORT 1 +#endif + //------------------------------------------------------------------------------ // RELAY //------------------------------------------------------------------------------ diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 62050eca..9a0226ff 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -37,9 +37,11 @@ // Disable non-core modules #define ALEXA_SUPPORT 0 #define BROKER_SUPPORT 0 + #define BUTTON_SUPPORT 0 #define DOMOTICZ_SUPPORT 0 #define HOMEASSISTANT_SUPPORT 0 #define I2C_SUPPORT 0 + #define MDNS_SERVER_SUPPORT 0 #define MQTT_SUPPORT 0 #define NTP_SUPPORT 0 #define SCHEDULER_SUPPORT 0 @@ -47,6 +49,14 @@ #define THINGSPEAK_SUPPORT 0 #define WEB_SUPPORT 0 + // Extra light-weight image + //#define DEBUG_SERIAL_SUPPORT 0 + //#define DEBUG_TELNET_SUPPORT 0 + //#define DEBUG_WEB_SUPPORT 0 + //#define LED_SUPPORT 0 + //#define TELNET_SUPPORT 0 + //#define TERMINAL_SUPPORT 0 + // ----------------------------------------------------------------------------- // Development boards // ----------------------------------------------------------------------------- diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 5673fd03..adc77fcf 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -99,8 +99,12 @@ void setup() { #endif relaySetup(); - buttonSetup(); - ledSetup(); + #if BUTTON_SUPPORT + buttonSetup(); + #endif + #if LED_SUPPORT + ledSetup(); + #endif #if MQTT_SUPPORT mqttSetup(); #endif diff --git a/code/espurna/led.ino b/code/espurna/led.ino index 06fac792..f71aa31b 100644 --- a/code/espurna/led.ino +++ b/code/espurna/led.ino @@ -10,6 +10,8 @@ Copyright (C) 2016-2018 by Xose Pérez // LED // ----------------------------------------------------------------------------- +#if LED_SUPPORT + typedef struct { unsigned char pin; bool reverse; @@ -290,3 +292,5 @@ void ledLoop() { _led_update = false; } + +#endif LED_SUPPORT diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 1c361a60..f738187e 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -194,7 +194,9 @@ void _relayProcess(bool mode) { #endif // Flag relay-based LEDs to update status - ledUpdate(true); + #if LED_SUPPORT + ledUpdate(true); + #endif _relays[id].report = false; _relays[id].group_report = false; diff --git a/code/espurna/settings.ino b/code/espurna/settings.ino index 89a2cd54..19013663 100644 --- a/code/espurna/settings.ino +++ b/code/espurna/settings.ino @@ -375,19 +375,30 @@ size_t settingsMaxSize() { bool settingsRestoreJson(JsonObject& data) { + // Check this is an ESPurna configuration file (must have "app":"ESPURNA") const char* app = data["app"]; - if (strcmp(app, APP_NAME) != 0) return false; + if (!app || strcmp(app, APP_NAME) != 0) { + DEBUG_MSG_P(PSTR("[SETTING] Wrong or missing 'app' key\n")); + return false; + } - for (unsigned int i = EEPROM_DATA_END; i < SPI_FLASH_SEC_SIZE; i++) { - EEPROMr.write(i, 0xFF); + // Clear settings + bool is_backup = data["backup"]; + if (is_backup) { + for (unsigned int i = EEPROM_DATA_END; i < SPI_FLASH_SEC_SIZE; i++) { + EEPROMr.write(i, 0xFF); + } } + // Dump settings to memory buffer for (auto element : data) { if (strcmp(element.key, "app") == 0) continue; if (strcmp(element.key, "version") == 0) continue; + if (strcmp(element.key, "backup") == 0) continue; setSetting(element.key, element.value.as()); } + // Persist to EEPROM saveSettings(); DEBUG_MSG_P(PSTR("[SETTINGS] Settings restored successfully\n")); diff --git a/code/espurna/web.ino b/code/espurna/web.ino index b26b64d3..7086bffd 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -88,14 +88,17 @@ void _onGetConfig(AsyncWebServerRequest *request) { response->addHeader("X-Content-Type-Options", "nosniff"); response->addHeader("X-Frame-Options", "deny"); - response->printf("{\n \"app\": \"%s\",\n \"version\": \"%s\"", APP_NAME, APP_VERSION); + response->printf("{\n\"app\": \"%s\"", APP_NAME); + response->printf(",\n\"version\": \"%s\"", APP_VERSION); + response->printf(",\n\"backup\": \"1\""); + response->printf(",\n\"timestamp\": \"%s\"", ntpDateTime().c_str()); // Write the keys line by line (not sorted) unsigned long count = settingsKeyCount(); for (unsigned int i=0; iprintf(",\n \"%s\": \"%s\"", key.c_str(), value.c_str()); + response->printf(",\n\"%s\": \"%s\"", key.c_str(), value.c_str()); } response->printf("\n}"); @@ -196,9 +199,9 @@ void _onHome(AsyncWebServerRequest *request) { response->addHeader("Content-Encoding", "gzip"); response->addHeader("Last-Modified", _last_modified); - response->addHeader("X-XSS-Protection", "1; mode=block"); - response->addHeader("X-Content-Type-Options", "nosniff"); - response->addHeader("X-Frame-Options", "deny"); + response->addHeader("X-XSS-Protection", "1; mode=block"); + response->addHeader("X-Content-Type-Options", "nosniff"); + response->addHeader("X-Frame-Options", "deny"); request->send(response); } diff --git a/code/gulpfile.js b/code/gulpfile.js index a6e6fa93..d9edbdbd 100644 --- a/code/gulpfile.js +++ b/code/gulpfile.js @@ -96,14 +96,14 @@ var buildHeaderFile = function() { cb(0, destination); - }); + }); } var htmllintReporter = function(filepath, issues) { - if (issues.length > 0) { - issues.forEach(function (issue) { - console.info( + if (issues.length > 0) { + issues.forEach(function (issue) { + console.info( '[gulp-htmllint] ' + filepath + ' [' + issue.line + ',' + @@ -111,9 +111,9 @@ var htmllintReporter = function(filepath, issues) { '(' + issue.code + ') ' + issue.msg ); - }); - process.exitCode = 1; - } + }); + process.exitCode = 1; + } }; var buildWebUI = function(module) { diff --git a/code/platformio.ini b/code/platformio.ini index 88bf2d9b..3203f89b 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -1416,7 +1416,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DEXS_WIFI_RELAY_V31 +build_flags = ${common.build_flags_4m1m} -DEXS_WIFI_RELAY_V31 monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -1427,7 +1427,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DEXS_WIFI_RELAY_V31 +build_flags = ${common.build_flags_4m1m} -DEXS_WIFI_RELAY_V31 upload_speed = ${common.upload_speed} upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} @@ -1730,7 +1730,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DEUROMATE_WIFI_STECKER_SCHUKO +build_flags = ${common.build_flags_1m0m} -DEUROMATE_WIFI_STECKER_SCHUKO monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -1741,7 +1741,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DEUROMATE_WIFI_STECKER_SCHUKO +build_flags = ${common.build_flags_1m0m} -DEUROMATE_WIFI_STECKER_SCHUKO upload_speed = ${common.upload_speed} upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} @@ -1754,7 +1754,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DTONBUX_POWERSTRIP02 +build_flags = ${common.build_flags_1m0m} -DTONBUX_POWERSTRIP02 monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -1765,7 +1765,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DTONBUX_POWERSTRIP02 +build_flags = ${common.build_flags_1m0m} -DTONBUX_POWERSTRIP02 upload_speed = ${common.upload_speed} upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} @@ -1778,7 +1778,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DLINGAN_SWA1 +build_flags = ${common.build_flags_1m0m} -DLINGAN_SWA1 monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -1789,7 +1789,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DLINGAN_SWA1 +build_flags = ${common.build_flags_1m0m} -DLINGAN_SWA1 upload_speed = ${common.upload_speed} upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} @@ -1967,11 +1967,11 @@ extra_scripts = ${common.extra_scripts} [env:arniex-swifitch] platform = ${common.platform} framework = ${common.framework} -board = ${common.board_1m} +board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DARNIEX_SWIFITCH +build_flags = ${common.build_flags_4m1m} -DARNIEX_SWIFITCH extra_scripts = ${common.extra_scripts} monitor_speed = ${common.monitor_speed} @@ -1982,7 +1982,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DARNIEX_SWIFITCH +build_flags = ${common.build_flags_4m1m} -DARNIEX_SWIFITCH upload_speed = ${common.upload_speed} upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} @@ -2020,7 +2020,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DLUANI_HVIO +build_flags = ${common.build_flags_4m1m} -DLUANI_HVIO monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -2031,7 +2031,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DZLUANI_HVIO +build_flags = ${common.build_flags_4m1m} -DLUANI_HVIO upload_speed = ${common.upload_speed} upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} @@ -2045,7 +2045,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DNEO_COOLCAM_NAS_WR01W +build_flags = ${common.build_flags_1m0m} -DNEO_COOLCAM_NAS_WR01W monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -2056,7 +2056,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DNEO_COOLCAM_NAS_WR01W +build_flags = ${common.build_flags_1m0m} -DNEO_COOLCAM_NAS_WR01W upload_speed = ${common.upload_speed} upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} @@ -2069,7 +2069,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DESTINK_WIFI_POWER_STRIP +build_flags = ${common.build_flags_1m0m} -DESTINK_WIFI_POWER_STRIP monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -2080,7 +2080,7 @@ board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_4m1m} -DESTINK_WIFI_POWER_STRIP +build_flags = ${common.build_flags_1m0m} -DESTINK_WIFI_POWER_STRIP upload_speed = ${common.upload_speed} upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} @@ -2217,7 +2217,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DALLNET_4DUINO_IOT_WLAN_RELAIS +build_flags = ${common.build_flags_4m1m} -DALLNET_4DUINO_IOT_WLAN_RELAIS monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -2228,7 +2228,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DALLNET_4DUINO_IOT_WLAN_RELAIS +build_flags = ${common.build_flags_4m1m} -DALLNET_4DUINO_IOT_WLAN_RELAIS upload_speed = ${common.upload_speed} upload_port = ${common.upload_port} upload_flags = ${common.upload_flags} @@ -2289,7 +2289,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DNODEMCU_BASIC -DGEIGER_SUPPORT=1 -DEVENTS_SUPPORT=0 -DINFLUXDB_SUPPORT=1 -DALEXA_SUPPORT=0 -DALEXA_ENABLED=0 +build_flags = ${common.build_flags_4m1m} -DNODEMCU_BASIC -DGEIGER_SUPPORT=1 -DEVENTS_SUPPORT=0 -DINFLUXDB_SUPPORT=1 -DALEXA_SUPPORT=0 -DALEXA_ENABLED=0 upload_speed = ${common.upload_speed_fast} monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -2301,7 +2301,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DNODEMCU_BASIC -DGEIGER_SUPPORT=1 -DEVENTS_SUPPORT=0 -DINFLUXDB_SUPPORT=1 -DALEXA_SUPPORT=0 -DALEXA_ENABLED=0 +build_flags = ${common.build_flags_4m1m} -DNODEMCU_BASIC -DGEIGER_SUPPORT=1 -DEVENTS_SUPPORT=0 -DINFLUXDB_SUPPORT=1 -DALEXA_SUPPORT=0 -DALEXA_ENABLED=0 upload_speed = ${common.upload_speed_fast} monitor_speed = ${common.monitor_speed} upload_port = ${common.upload_port} @@ -2341,7 +2341,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DBH_ONOFRE +build_flags = ${common.build_flags_4m1m} -DBH_ONOFRE upload_speed = ${common.upload_speed_fast} monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} @@ -2353,7 +2353,7 @@ board = ${common.board_4m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -build_flags = ${common.build_flags_1m0m} -DBH_ONOFRE +build_flags = ${common.build_flags_4m1m} -DBH_ONOFRE upload_speed = ${common.upload_speed_fast} monitor_speed = ${common.monitor_speed} upload_port = ${common.upload_port}