From 49b6d351d99a1fc7c4c4ed7acb100edb933fa5d2 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Tue, 7 Apr 2020 21:48:43 +0300 Subject: [PATCH] PIO/hardware.h: Update naming (#2214) * update platformio.ini comments * espurna-base -> espurna-core-webui * esp8266---base -> esp8266---base * clean-up ESPURNA_CORE detection, use boards function --- .travis.yml | 4 +- code/espurna/board.h | 3 +- code/espurna/board.ino | 12 ++- code/espurna/config/arduino.h | 2 +- code/espurna/config/hardware.h | 6 +- code/espurna/telnet.ino | 32 +++----- code/espurna/utils.ino | 6 +- code/ota.py | 7 +- code/platformio.ini | 142 +++++++++++++++++++++------------ 9 files changed, 124 insertions(+), 90 deletions(-) diff --git a/.travis.yml b/.travis.yml index 92ddff24..4927fea7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,9 +30,9 @@ jobs: - stage: Test WebUI - stage: Test PlatformIO Build env: TEST_ENV=esp8266-4m-base - - env: TEST_ENV=esp8266-latest-4m-base + - env: TEST_ENV=esp8266-4m-latest-base - env: >- - TEST_ENV=esp8266-git-4m-base TEST_EXTRA_ARGS="-a + TEST_ENV=esp8266-4m-git-base TEST_EXTRA_ARGS="-a test/build/extra/secure_client.h" - stage: Release env: BUILDER_THREAD=0 diff --git a/code/espurna/board.h b/code/espurna/board.h index a9fe2b9c..222c6a41 100644 --- a/code/espurna/board.h +++ b/code/espurna/board.h @@ -14,5 +14,6 @@ String getEspurnaSensors(); String getEspurnaWebUI(); -int getBoardId(); +bool isEspurnaCore(); +int getBoardId(); diff --git a/code/espurna/board.ino b/code/espurna/board.ino index 4139b435..85e319ae 100644 --- a/code/espurna/board.ino +++ b/code/espurna/board.ino @@ -324,6 +324,14 @@ String getEspurnaWebUI() { return FPSTR(espurna_webui); } +bool isEspurnaCore() { + #if defined(ESPURNA_CORE) || defined(ESPURNA_CORE_WEBUI) + return true; + #else + return false; + #endif +} + bool haveRelaysOrSensors() { bool result = false; result = (relayCount() > 0); @@ -334,10 +342,8 @@ bool haveRelaysOrSensors() { } int getBoardId() { - #if defined(ESPURNA_CORE) + #if defined(ESPURNA_CORE) || defined(ESPURNA_CORE_WEBUI) return 0; - #elif defined(ESPURNA_BASE) - return 1; #elif defined(NODEMCU_LOLIN) return 2; #elif defined(NODEMCU_BASIC) diff --git a/code/espurna/config/arduino.h b/code/espurna/config/arduino.h index 6e5a9040..635c8abf 100644 --- a/code/espurna/config/arduino.h +++ b/code/espurna/config/arduino.h @@ -37,8 +37,8 @@ //#define EHOMEDIY_WT02 //#define EHOMEDIY_WT03 //#define ELECTRODRAGON_WIFI_IOT -//#define ESPURNA_BASE //#define ESPURNA_CORE +//#define ESPURNA_CORE_WEBUI //#define ETEKCITY_ESW01_USA //#define EUROMATE_WIFI_STECKER_SCHUKO //#define EUROMATE_WIFI_STECKER_SCHUKO_V2 diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 2993a25d..b13c7b62 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -50,7 +50,7 @@ // Info #define MANUFACTURER "ESPURNA" - #define DEVICE "ESPURNA_CORE" + #define DEVICE "CORE" // Disable non-core modules #define ALEXA_SUPPORT 0 @@ -79,14 +79,14 @@ //#define TELNET_SUPPORT 0 // when only using espota.py //#define TERMINAL_SUPPORT 0 // -#elif defined(ESPURNA_BASE) +#elif defined(ESPURNA_CORE_WEBUI) // This is a special device with no specific hardware // with the basics to easily upgrade it to a device-specific image // Info #define MANUFACTURER "ESPURNA" - #define DEVICE "ESPURNA_BASE" + #define DEVICE "CORE_WEBUI" // Disable non-core modules #define ALEXA_SUPPORT 0 diff --git a/code/espurna/telnet.ino b/code/espurna/telnet.ino index be4b8b1c..1c093288 100644 --- a/code/espurna/telnet.ino +++ b/code/espurna/telnet.ino @@ -18,6 +18,7 @@ Updated to use WiFiServer and support reverse connections by Niek van der Maas < #if TELNET_SUPPORT #include +#include "board.h" #include "telnet.h" TTelnetServer _telnetServer(TELNET_PORT); @@ -272,11 +273,7 @@ void _telnetData(unsigned char clientId, char * data, size_t len) { } // Password prompt (disable on CORE variant) - #ifdef ESPURNA_CORE - const bool authenticated = true; - #else - const bool authenticated = _telnetClientsAuth[clientId]; - #endif + const bool authenticated = isEspurnaCore() ? true : _telnetClientsAuth[clientId]; if (_telnetAuth && !authenticated) { String password = getAdminPass(); @@ -310,9 +307,7 @@ void _telnetNotifyConnected(unsigned char i) { #endif #endif - #ifdef ESPURNA_CORE - _telnetClientsAuth[i] = true; - #else + if (!isEspurnaCore()) { _telnetClientsAuth[i] = !_telnetAuth; if (_telnetAuth) { if (getAdminPass().length()) { @@ -321,7 +316,9 @@ void _telnetNotifyConnected(unsigned char i) { _telnetClientsAuth[i] = true; } } - #endif + } else { + _telnetClientsAuth[i] = true; + } wifiReconnectCheck(); @@ -340,13 +337,8 @@ void _telnetLoop() { if (_telnetClients[i]->localIP() != WiFi.softAPIP()) { // Telnet is always available for the ESPurna Core image - #ifdef ESPURNA_CORE - bool telnetSTA = true; - #else - bool telnetSTA = getSetting("telnetSTA", 1 == TELNET_STA); - #endif - - if (!telnetSTA) { + const bool can_connect = isEspurnaCore() ? true : getSetting("telnetSTA", 1 == TELNET_STA); + if (!can_connect) { DEBUG_MSG_P(PSTR("[TELNET] Rejecting - Only local connections\n")); _telnetDisconnect(i); return; @@ -412,13 +404,9 @@ void _telnetSetupClient(unsigned char i, AsyncClient *client) { void _telnetNewClient(AsyncClient* client) { if (client->localIP() != WiFi.softAPIP()) { // Telnet is always available for the ESPurna Core image - #ifdef ESPURNA_CORE - bool telnetSTA = true; - #else - bool telnetSTA = getSetting("telnetSTA", 1 == TELNET_STA); - #endif + const bool can_connect = isEspurnaCore() ? true : getSetting("telnetSTA", 1 == TELNET_STA); - if (!telnetSTA) { + if (!can_connect) { DEBUG_MSG_P(PSTR("[TELNET] Rejecting - Only local connections\n")); client->onDisconnect([](void *s, AsyncClient *c) { delete c; diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index c07a9867..c1bd63ae 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -10,6 +10,7 @@ Copyright (C) 2017-2019 by Xose PĂ©rez #include "config/buildtime.h" +#include "board.h" #include "mqtt.h" #include "ntp.h" #include "utils.h" @@ -37,7 +38,6 @@ PROGMEM const char* const custom_reset_string[] = { custom_reset_factory }; - void setDefaultHostname() { if (strlen(HOSTNAME) > 0) { setSetting("hostname", HOSTNAME); @@ -47,9 +47,9 @@ void setDefaultHostname() { } void setBoardName() { - #ifndef ESPURNA_CORE + if (!isEspurnaCore()) { setSetting("boardName", DEVICE_NAME); - #endif + } } String getBoardName() { diff --git a/code/ota.py b/code/ota.py index 6310b71b..3541fcbb 100755 --- a/code/ota.py +++ b/code/ota.py @@ -402,14 +402,15 @@ def discover_devices(args): def get_platformio_env(arduino_core, size): # todo: eventually 2_3_0 is dropped # todo: naming - env_prefix = "esp8266" + prefix = "esp8266" if not size in [1, 2, 4]: raise ValueError( "Board memory size can only be one of: 1 for 1M, 2 for 2M, 4 for 4M" ) + core = "" if arduino_core != "2_3_0": - env_prefix = "{}-{}".format(env_prefix, arduino_core) - return "{env_prefix}-{size:d}m-base".format(env_prefix=env_prefix, size=size) + core = "-{}".format(arduino_core) + return "{prefix}-{size:d}m{core}-base".format(prefix=prefix, core=core, size=size) def main(args): diff --git a/code/platformio.ini b/code/platformio.ini index 4aeba611..212fbd90 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -37,57 +37,80 @@ platform_2_3_0 = espressif8266@1.5.0 platform_latest = espressif8266@2.4.0 # ------------------------------------------------------------------------------ -# FLAGS: DEBUG -# +# FLASH SIZE: +# configurations for 512k/1m/... ESP's are different because we use Linker Scripts to adjust flash split +# board_512k, ldscript_512k ( 512 KB) = 487 KB sketch, 4 KB eeprom, 16 KB reserved +# board_512k, ldscript_1m0m (1024 KB) = 999 KB sketch, 4 KB eeprom, 16 KB reserved +# board_512k, ldscript_2m1m (2048 KB) = 1019 KB sketch, 16 KB eeprom, 992 KB spiffs, 16 KB reserved +# board_512k, ldscript_4m1m (4096 KB) = 1019 KB sketch, 16 KB eeprom, 992 KB spiffs, 16 KB reserved, 2048 KB empty/ota? +# board_512k, ldscript_4m3m (4096 KB) = 1019 KB sketch, 16 KB eeprom, 3040 KB spiffs, 16 KB reserved # ------------------------------------------------------------------------------ +board_512k = esp01 +ldscript_512k = eagle.flash.512k0m1s.ld + +board_1m = esp01_1m +ldscript_1m = eagle.flash.1m0m1s.ld + +board_2m = esp_wroom_02 +ldscript_2m = eagle.flash.2m1m4s.ld -debug_flags = -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM -#if needed (for memleaks etc) also add; -DDEBUG_ESP_OOM -include "umm_malloc/umm_malloc_cfg.h" +board_4m = esp12e +ldscript_4m = eagle.flash.4m1m4s.ld # ------------------------------------------------------------------------------ -# FLAGS: build flags -# build flags for 512k/1m ESP's are different because we use Linker Scripts to adjust flash split -# build_flags_512k ( 512 KB) = 487 KB sketch, 4 KB eeprom, 16 KB reserved -# build_flags_1m0m (1024 KB) = 999 KB sketch, 4 KB eeprom, 16 KB reserved -# build_flags_2m1m (2048 KB) = 1019 KB sketch, 16 KB eeprom, 992 KB spiffs, 16 KB reserved -# build_flags_4m1m (4096 KB) = 1019 KB sketch, 16 KB eeprom, 992 KB spiffs, 16 KB reserved, 2048 KB empty/ota? -# build_flags_4m3m (4096 KB) = 1019 KB sketch, 16 KB eeprom, 3040 KB spiffs, 16 KB reserved +# GLOBAL BUILD FLAGS: # # Available lwIP variants (macros): -# -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH = v1.4 Higher Bandwidth (default) -# -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY = v2 Lower Memory -# -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH = v2 Higher Bandwidth -# -# BearSSL performance: -# When building with -DSECURE_CLIENT=SECURE_CLIENT_BEARSSL, please add `board_build.f_cpu = 160000000` to the environment configuration +# -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH = v2 Higher Bandwidth (default) +# -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY = v2 Lower Memory (TCP MSS set to 536, MSS * 2 send buffer) +# -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH = v1.4 Higher Bandwidth (deprecated, **not recommended**) # -# BearSSL ciphers: -# When building on core >= 2.5, you can add the build flag -DBEARSSL_SSL_BASIC in order to build BearSSL with a limited set of ciphers: +# BearSSL: +# When building with -DSECURE_CLIENT=SECURE_CLIENT_BEARSSL, you can add the build flag -DBEARSSL_SSL_BASIC in order to build BearSSL with a limited set of ciphers: # TLS_RSA_WITH_AES_128_CBC_SHA256 / AES128-SHA256 # TLS_RSA_WITH_AES_256_CBC_SHA256 / AES256-SHA256 # TLS_RSA_WITH_AES_128_CBC_SHA / AES128-SHA # TLS_RSA_WITH_AES_256_CBC_SHA / AES256-SHA -# This reduces the OTA size with ~45KB, so it's especially useful on low memory boards (512k/1m). +# This reduces total .bin size by about ~45KB, so it's especially useful on low memory boards (512k/1m). +# +# It is **recommended** to add `board_build.f_cpu = 160000000` to the environment configuration +# (either in `[env]` to set globally or `[env:...]` to use with the specific environment). +# # ------------------------------------------------------------------------------ - build_flags = -g -w -DNO_GLOBAL_EEPROM -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH -board_512k = esp01 -ldscript_512k = eagle.flash.512k0m1s.ld - -board_1m = esp01_1m -ldscript_1m = eagle.flash.1m0m1s.ld - -board_2m = esp_wroom_02 -ldscript_2m = eagle.flash.2m1m4s.ld +# ------------------------------------------------------------------------------ +# DEBUG BUILD FLAGS +# build flags for the Core, must be set as global build_flag +# (src_build_flags would not work) +# +# [env:nodemcu-lolin-debug] +# extends = env:nodemcu-lolin +# build_flags = ${common.build_flags} ${common.debug_flags} +# +# ------------------------------------------------------------------------------ +debug_flags = + -DDEBUG_ESP_CORE + -DDEBUG_ESP_WIFI + -DDEBUG_ESP_HTTP_CLIENT + -DDEBUG_ESP_HTTP_SERVER + -DDEBUG_ESP_HTTP_UPDATE + -DDEBUG_ESP_UPDATER + -DDEBUG_ESP_OTA + -DDEBUG_ESP_SSL + -DDEBUG_ESP_UPDATER + -DDEBUG_TLS_MEM + -DDEBUG_ESP_MDNS + +# For memleaks etc, add: +# -DDEBUG_ESP_OOM +# -DDEBUG_ESP_TLS_MEM -board_4m = esp12e -ldscript_4m = eagle.flash.4m1m4s.ld shared_libdeps_dir = libraries/ # ------------------------------------------------------------------------------ -# COMMON SETTINGS: +# COMMON ENVIRONMENT SETTINGS: # ------------------------------------------------------------------------------ [env] platform = ${common.platform_2_3_0} @@ -137,6 +160,13 @@ lib_deps = lib_ignore = AsyncTCP +# ------------------------------------------------------------------------------ +# Base enrivonments, -DMANUFACTURER=..., -DDEVICE=... must be set: +# - by using specific hardware.h entry, like -DITEAD_SONOFF_BASIC +# - by setting PLATFORMIO_SRC_BUILD_FLAGS=... environment variable +# - by setting ESPURNA_FLAGS=... environment variable +# ------------------------------------------------------------------------------ + [env:esp8266-512k-base] board = ${common.board_512k} board_build.ldscript = ${common.ldscript_512k} @@ -153,36 +183,36 @@ board_build.ldscript = ${common.ldscript_2m} board = ${common.board_4m} board_build.ldscript = ${common.ldscript_4m} -[env:esp8266-latest-1m-base] +[env:esp8266-1m-latest-base] platform = ${common.platform_latest} board = ${common.board_1m} board_build.ldscript = ${common.ldscript_1m} -[env:esp8266-latest-2m-base] +[env:esp8266-2m-latest-base] platform = ${common.platform_latest} board = ${common.board_2m} board_build.ldscript = ${common.ldscript_2m} -[env:esp8266-latest-4m-base] +[env:esp8266-4m-latest-base] platform = ${common.platform_latest} board = ${common.board_4m} board_build.ldscript = ${common.ldscript_4m} -[env:esp8266-git-1m-base] +[env:esp8266-1m-git-base] platform = ${common.platform_latest} board = ${common.board_1m} platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git board_build.ldscript = ${common.ldscript_1m} -[env:esp8266-git-2m-base] +[env:esp8266-2m-git-base] platform = ${common.platform_latest} board = ${common.board_2m} platform_packages = framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git board_build.ldscript = ${common.ldscript_2m} -[env:esp8266-git-4m-base] +[env:esp8266-4m-git-base] platform = ${common.platform_latest} board = ${common.board_4m} platform_packages = @@ -190,7 +220,7 @@ platform_packages = board_build.ldscript = ${common.ldscript_4m} # ------------------------------------------------------------------------------ -# ESPURNA CORE BUILDS +# ESPURNA CORE BUILDS (2-step OTA) # ------------------------------------------------------------------------------ [env:espurna-core-1MB] @@ -236,12 +266,20 @@ src_build_flags = -DESPURNA_CORE build_flags = ${common.build_flags} -DJUSTWIFI_ENABLE_WPS=1 # ------------------------------------------------------------------------------ -# ESPURNA BASE BUILD (CORE with WebUI, tuya-convert) +# ESPURNA CORE with WebUI # ------------------------------------------------------------------------------ -[env:espurna-base-1MB] +[env:espurna-core-webui-1MB] extends = env:esp8266-1m-base -src_build_flags = -DESPURNA_BASE +src_build_flags = -DESPURNA_CORE_WEB + +[env:espurna-core-webui-2MB] +extends = env:esp8266-2m-base +src_build_flags = -DESPURNA_CORE_WEB + +[env:espurna-core-webui-4MB] +extends = env:esp8266-4m-base +src_build_flags = -DESPURNA_CORE_WEB # ------------------------------------------------------------------------------ # DEVELOPMENT BOARDS @@ -262,16 +300,16 @@ extends = env:esp8266-4m-base src_build_flags = -DNODEMCU_LOLIN -DNOWSAUTH [env:nodemcu-lolin-latest] -extends = env:esp8266-latest-4m-base +extends = env:esp8266-4m-latest-base src_build_flags = -DNODEMCU_LOLIN -DNOWSAUTH [env:nodemcu-lolin-secure-client-asynctcp] -extends = env:esp8266-latest-4m-base +extends = env:esp8266-4m-latest-base build_flags = ${common.build_flags} -DASYNC_TCP_SSL_ENABLED=1 src_build_flags = -DNODEMCU_LOLIN -DNOWSAUTH [env:nodemcu-lolin-secure-client] -extends = env:esp8266-latest-4m-base +extends = env:esp8266-4m-latest-base board_build.f_cpu = 160000000 src_build_flags = -DNODEMCU_LOLIN -DNOWSAUTH @@ -284,23 +322,23 @@ src_build_flags = # ------------------------------------------------------------------------------ [env:tinkerman-espurna-h06] -extends = env:esp8266-latest-4m-base +extends = env:esp8266-4m-latest-base src_build_flags = -DTINKERMAN_ESPURNA_H06 [env:tinkerman-espurna-h08] -extends = env:esp8266-latest-4m-base +extends = env:esp8266-4m-latest-base src_build_flags = -DTINKERMAN_ESPURNA_H08 [env:tinkerman-espurna-switch] -extends = env:esp8266-latest-4m-base +extends = env:esp8266-4m-latest-base src_build_flags = -DTINKERMAN_ESPURNA_SWITCH [env:wemos-d1-tarpunashield] -extends = env:esp8266-latest-4m-base +extends = env:esp8266-4m-latest-base src_build_flags = -DWEMOS_D1_TARPUNA_SHIELD [env:tinkerman-rfm69gw] -extends = env:esp8266-latest-4m-base +extends = env:esp8266-4m-latest-base board = esp12e src_build_flags = -DTINKERMAN_RFM69GW -DNOWSAUTH @@ -339,11 +377,11 @@ extends = env:esp8266-1m-base src_build_flags = -DGENERIC_ESP01S_DS18B20_V10 [env:generic-esp01s-pzem004t] -extends = env:esp8266-latest-1m-base +extends = env:esp8266-1m-latest-base src_build_flags = -DGENERIC_PZEM004T -DDISABLE_POSTMORTEM_STACKDUMP [env:generic-esp12e-pzem004t] -extends = env:esp8266-latest-4m-base +extends = env:esp8266-4m-latest-base src_build_flags = -DGENERIC_PZEM004T -DDISABLE_POSTMORTEM_STACKDUMP # ------------------------------------------------------------------------------