From 56bc66119b28975f208a05b374ed19e285fb0c13 Mon Sep 17 00:00:00 2001 From: Magnus Date: Mon, 28 Aug 2023 10:13:06 +0200 Subject: [PATCH 1/5] Updated dependecies --- example/platformio.ini | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/example/platformio.ini b/example/platformio.ini index b11b604..80b0295 100644 --- a/example/platformio.ini +++ b/example/platformio.ini @@ -26,11 +26,11 @@ build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS lib_deps = https://github.com/mp-se/Arduino-Log#1.1.1 - https://github.com/mp-se/ArduinoJson#v6.18.5 + https://github.com/mp-se/ArduinoJson#v6.21.3 https://github.com/mp-se/arduino-mqtt#v2.5.1 [env:esplib-debug] -platform = espressif8266 @ 4.1.0 +platform = espressif8266 @ 4.2.1 board = d1_mini framework = arduino board_build.filesystem = ${common_env_data.board_build.filesystem} @@ -46,7 +46,7 @@ lib_deps = monitor_filters = esp8266_exception_decoder [env:esplibasync-debug] -platform = espressif8266 @ 4.1.0 +platform = espressif8266 @ 4.2.1 board = d1_mini framework = arduino board_build.filesystem = ${common_env_data.board_build.filesystem} @@ -67,7 +67,7 @@ build_type = release monitor_filters = esp8266_exception_decoder [env:esplib32-debug] -platform = espressif32 @ 5.3.0 +platform = espressif32 @ 6.3.2 framework = arduino board = featheresp32 board_build.filesystem = ${common_env_data.board_build.filesystem} @@ -91,7 +91,7 @@ board_build.embed_txtfiles = html/ws.min.htm [env:esplib32-c3-debug] -platform = espressif32 @ 5.3.0 +platform = espressif32 @ 6.3.2 framework = arduino board = lolin_c3_mini debug_tool = custom @@ -123,7 +123,7 @@ board_build.embed_txtfiles = html/ws.min.htm [env:esplib32-s2-debug] -platform = espressif32 @ 5.3.0 +platform = espressif32 @ 6.3.2 framework = arduino board = lolin_s2_mini board_build.filesystem = ${common_env_data.board_build.filesystem} @@ -147,7 +147,7 @@ board_build.embed_txtfiles = html/ws.min.htm [env:esplib32async-s2-debug] -platform = espressif32 @ 5.3.0 +platform = espressif32 @ 6.3.2 framework = arduino board = lolin_s2_mini board_build.filesystem = ${common_env_data.board_build.filesystem} From f61e53bf45b1b109cdb8b65775ea38d0135dda68 Mon Sep 17 00:00:00 2001 From: Magnus Date: Fri, 1 Sep 2023 16:31:42 +0200 Subject: [PATCH 2/5] Static wifi setting have priority over config --- src/wificonnection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wificonnection.cpp b/src/wificonnection.cpp index 8d9d1ae..eff5b44 100644 --- a/src/wificonnection.cpp +++ b/src/wificonnection.cpp @@ -82,8 +82,8 @@ void WifiConnection::writeReset() { } } bool WifiConnection::hasConfig() { - if (strlen(_wifiConfig->getWifiSSID(0))) return true; if (_userSSID.length()) return true; + if (strlen(_wifiConfig->getWifiSSID(0))) return true; // Check if there are stored WIFI Settings we can use #if defined(ESP8266) From 122fe89cc877669bc00e07c51fe72a2b933c409b Mon Sep 17 00:00:00 2001 From: Magnus Date: Sun, 3 Sep 2023 21:09:10 +0200 Subject: [PATCH 3/5] Added support for wokwi emulator --- .gitignore | 7 ++- example/platformio.ini | 94 ++++++++++++++++---------------- example/script/merge_firmware.py | 40 ++++++++++++++ example/wokwi.toml | 8 +++ src/baseasyncwebhandler.hpp | 2 +- src/baseconfig.cpp | 12 ++++ src/espframework.hpp | 12 ++-- src/log.cpp | 3 +- src/log.hpp | 2 +- src/serialws.hpp | 2 +- 10 files changed, 127 insertions(+), 55 deletions(-) create mode 100644 example/script/merge_firmware.py create mode 100644 example/wokwi.toml diff --git a/.gitignore b/.gitignore index 6315779..85676ad 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,12 @@ .vscode/* example/test/__pycache__ # These files are under examples and should not be checked in. +script/* src/demo*.* platformio.ini html/* -test/* \ No newline at end of file +test/* +diagram.json +wokwi.toml +partitions.csv +output.map diff --git a/example/platformio.ini b/example/platformio.ini index 80b0295..757d627 100644 --- a/example/platformio.ini +++ b/example/platformio.ini @@ -28,6 +28,13 @@ lib_deps = https://github.com/mp-se/Arduino-Log#1.1.1 https://github.com/mp-se/ArduinoJson#v6.21.3 https://github.com/mp-se/arduino-mqtt#v2.5.1 +html_files = + html/upload.min.htm + html/config.min.htm + html/about.min.htm + html/index.min.htm + html/test.min.htm + html/ws.min.htm [env:esplib-debug] platform = espressif8266 @ 4.2.1 @@ -37,10 +44,9 @@ board_build.filesystem = ${common_env_data.board_build.filesystem} upload_speed = ${common_env_data.upload_speed} monitor_speed = ${common_env_data.monitor_speed} build_unflags = ${common_env_data.build_unflags} -build_flags = - ${common_env_data.build_flags} +build_flags = ${common_env_data.build_flags} lib_deps = - https://github.com/mp-se/incbin#v1.0.0 + https://github.com/mp-se/incbin#v1.0.0 ${common_env_data.lib_deps} build_type = debug monitor_filters = esp8266_exception_decoder @@ -57,9 +63,9 @@ build_unflags = ${common_env_data.build_unflags} build_flags = -D USE_ASYNC_WEB - ${common_env_data.build_flags} + ${common_env_data.build_flags} lib_deps = - https://github.com/mp-se/incbin#v1.0.0 + https://github.com/mp-se/incbin#v1.0.0 https://github.com/mp-se/ESPAsyncWebServer https://github.com/mp-se/ESPAsyncTCP ${common_env_data.lib_deps} @@ -78,17 +84,10 @@ build_flags = -D CORE_DEBUG_LEVEL=0 # -D USE_SERIAL_PINS ${common_env_data.build_flags} -lib_deps = - ${common_env_data.lib_deps} +lib_deps = ${common_env_data.lib_deps} build_type = debug monitor_filters = esp32_exception_decoder -board_build.embed_txtfiles = - html/upload.min.htm - html/config.min.htm - html/about.min.htm - html/index.min.htm - html/test.min.htm - html/ws.min.htm +board_build.embed_txtfiles = ${common_env_data.html_files} [env:esplib32-c3-debug] platform = espressif32 @ 6.3.2 @@ -107,20 +106,13 @@ monitor_speed = ${common_env_data.monitor_speed} build_unflags = ${common_env_data.build_unflags} build_flags = -D CORE_DEBUG_LEVEL=0 - -D ESP32C3 + -D ESP32C3 -D ARDUINO_ESP32C3_DEV -D USE_SERIAL_PINS - ${common_env_data.build_flags} -lib_deps = - ${common_env_data.lib_deps} + ${common_env_data.build_flags} +lib_deps = ${common_env_data.lib_deps} build_type = debug -board_build.embed_txtfiles = - html/upload.min.htm - html/config.min.htm - html/about.min.htm - html/index.min.htm - html/test.min.htm - html/ws.min.htm +board_build.embed_txtfiles = ${common_env_data.html_files} [env:esplib32-s2-debug] platform = espressif32 @ 6.3.2 @@ -131,20 +123,13 @@ upload_speed = ${common_env_data.upload_speed} monitor_speed = ${common_env_data.monitor_speed} build_unflags = ${common_env_data.build_unflags} build_flags = - -D ESP32S2 + -D ESP32S2 -D ARDUINO_ESP32S2_DEV #-D USE_SERIAL_PINS - ${common_env_data.build_flags} -lib_deps = - ${common_env_data.lib_deps} + ${common_env_data.build_flags} +lib_deps = ${common_env_data.lib_deps} build_type = debug -board_build.embed_txtfiles = - html/upload.min.htm - html/config.min.htm - html/about.min.htm - html/index.min.htm - html/test.min.htm - html/ws.min.htm +board_build.embed_txtfiles = ${common_env_data.html_files} [env:esplib32async-s2-debug] platform = espressif32 @ 6.3.2 @@ -155,20 +140,37 @@ upload_speed = ${common_env_data.upload_speed} monitor_speed = ${common_env_data.monitor_speed} build_unflags = ${common_env_data.build_unflags} build_flags = - -D ESP32S2 + -D ESP32S2 -D ARDUINO_ESP32S2_DEV - #-D USE_SERIAL_PINS - ${common_env_data.build_flags} + # -D USE_SERIAL_PINS + -D USE_ASYNC_WEB + ${common_env_data.build_flags} +lib_deps = + https://github.com/mp-se/ESPAsyncWebServer + https://github.com/mp-se/AsyncTCP + ${common_env_data.lib_deps} +build_type = debug +board_build.partitions = partitions.csv +board_build.embed_txtfiles = ${common_env_data.html_files} + +[env:esplib32async-wokwi] +platform = espressif32 @ 6.3.2 +framework = arduino +board = esp32dev +board_build.filesystem = ${common_env_data.board_build.filesystem} +upload_speed = ${common_env_data.upload_speed} +monitor_speed = ${common_env_data.monitor_speed} +build_unflags = ${common_env_data.build_unflags} +extra_scripts = script/merge_firmware.py +build_flags = + -D ESP32 + -D USE_SERIAL_PINS -D USE_ASYNC_WEB + ${common_env_data.build_flags} lib_deps = https://github.com/mp-se/ESPAsyncWebServer https://github.com/mp-se/AsyncTCP ${common_env_data.lib_deps} build_type = debug -board_build.embed_txtfiles = - html/upload.min.htm - html/config.min.htm - html/about.min.htm - html/index.min.htm - html/test.min.htm - html/ws.min.htm +board_build.partitions = partitions.csv +board_build.embed_txtfiles = ${common_env_data.html_files} diff --git a/example/script/merge_firmware.py b/example/script/merge_firmware.py new file mode 100644 index 0000000..9e543df --- /dev/null +++ b/example/script/merge_firmware.py @@ -0,0 +1,40 @@ +Import("env") + +APP_BIN = "$BUILD_DIR/${PROGNAME}.bin" +MERGED_BIN = "$BUILD_DIR/${PROGNAME}_merged.bin" +BOARD_CONFIG = env.BoardConfig() + + +def merge_bin(source, target, env): + # The list contains all extra images (bootloader, partitions, eboot) and + # the final application binary + flash_images = env.Flatten(env.get("FLASH_EXTRA_IMAGES", [])) + ["$ESP32_APP_OFFSET", APP_BIN] + + # Run esptool to merge images into a single binary + env.Execute( + " ".join( + [ + "$PYTHONEXE", + "$OBJCOPY", + "--chip", + BOARD_CONFIG.get("build.mcu", "esp32"), + "merge_bin", + "--fill-flash-size", + BOARD_CONFIG.get("upload.flash_size", "4MB"), + "-o", + MERGED_BIN, + ] + + flash_images + ) + ) + +# Add a post action that runs esptoolpy to merge available flash images +env.AddPostAction(APP_BIN , merge_bin) + +# Patch the upload command to flash the merged binary at address 0x0 +env.Replace( + UPLOADERFLAGS=[ + ] + + ["0x0", MERGED_BIN], + UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS', +) \ No newline at end of file diff --git a/example/wokwi.toml b/example/wokwi.toml new file mode 100644 index 0000000..cc447a8 --- /dev/null +++ b/example/wokwi.toml @@ -0,0 +1,8 @@ +[wokwi] +version = 1 +firmware = '.pio/build/esplib32async-wokwi/firmware_merged.bin' +elf = '.pio/build/esplib32async-wokwi/firmware.elf' + +[[net.forward]] +from = "localhost:8180" +to = "target:80" diff --git a/src/baseasyncwebhandler.hpp b/src/baseasyncwebhandler.hpp index 7ac9063..a6185ad 100644 --- a/src/baseasyncwebhandler.hpp +++ b/src/baseasyncwebhandler.hpp @@ -25,7 +25,7 @@ SOFTWARE. #define SRC_BASEASYNCWEBHANDLER_HPP_ #if defined(ESP32) -#include +#include #endif #if defined(ESP8266) diff --git a/src/baseconfig.cpp b/src/baseconfig.cpp index be5d48f..98d8932 100644 --- a/src/baseconfig.cpp +++ b/src/baseconfig.cpp @@ -287,6 +287,7 @@ void BaseConfig::checkFileSystem() { #if LOG_LEVEL == 6 Log.verbose(F("CFG : Checking if filesystem is valid." CR)); #endif +#ifdef ESP8266 if (LittleFS.begin()) { #if LOG_LEVEL == 6 Log.verbose(F("CFG : Filesystem mounted." CR)); @@ -294,7 +295,18 @@ void BaseConfig::checkFileSystem() { } else { Log.error(F("CFG : Unable to mount file system, formatting..." CR)); LittleFS.format(); + LittleFS.begin(); } +#else + if (LittleFS.begin(true)) { +#if LOG_LEVEL == 6 + Log.verbose(F("CFG : Filesystem mounted." CR)); +#endif + } else { + Log.error(F("CFG : Unable to mount/format file system..." CR)); + } +#endif + } // EOF diff --git a/src/espframework.hpp b/src/espframework.hpp index 31d8931..0a79414 100644 --- a/src/espframework.hpp +++ b/src/espframework.hpp @@ -24,14 +24,18 @@ SOFTWARE. #ifndef SRC_ESPFRAMEWORK_HPP_ #define SRC_ESPFRAMEWORK_HPP_ -#define ESPFWK_VER "0.6.3" +#define ESPFWK_VER "0.6.4" #if defined(ESP8266) -#define ESP_RESET ESP.reset -#define PIN_LED 2 + #define ESP_RESET ESP.reset + #define PIN_LED 2 #elif defined(ESP32) #define ESP_RESET ESP.restart -#define PIN_LED LED_BUILTIN + #if defined(LED_BUILTIN) + #define PIN_LED LED_BUILTIN + #else + #define PIN_LED 2 + #endif #endif #endif // SRC_ESPFRAMEWORK_HPP_ diff --git a/src/log.cpp b/src/log.cpp index 395df4c..9122340 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -73,7 +73,8 @@ SerialDebug::SerialDebug(const uint32_t serialSpeed) { #elif defined(ESP8266) EspSerial.begin(serialSpeed); #elif defined(USE_SERIAL_PINS) && defined(ESP32C3) - EspSerial.begin(115200L, SERIAL_8N1, 20, 21); + //EspSerial.begin(115200L, SERIAL_8N1, 20, 21); + EspSerial.begin(115200L); #elif defined(ESP32C3) EspSerial.begin(115200L); #elif defined(USE_SERIAL_PINS) && defined(ESP32S2) diff --git a/src/log.hpp b/src/log.hpp index 6e30aec..2796484 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -44,7 +44,7 @@ void writeErrorLog(const char* format, ...); void dumpErrorLog1(); void dumpErrorLog2(); -#if defined(USE_SERIAL_PINS) && defined(ESP32) +#if defined(USE_SERIAL_PINS) && defined(ESP32) && !defined(ARDUINO_USB_CDC_ON_BOOT) #define EspSerial Serial0 #else #define EspSerial Serial diff --git a/src/serialws.hpp b/src/serialws.hpp index b8a4170..0829920 100644 --- a/src/serialws.hpp +++ b/src/serialws.hpp @@ -30,7 +30,7 @@ SOFTWARE. #include #if defined(ESP32) -#include +#include #endif #if defined(ESP8266) From 7b3fe48fbfd6d002f1bc2cddee9b41387125e8c7 Mon Sep 17 00:00:00 2001 From: Magnus Date: Sun, 3 Sep 2023 21:10:46 +0200 Subject: [PATCH 4/5] Added missing files --- example/diagram.json | 21 +++++++++++++++++++++ example/partitions.csv | 7 +++++++ 2 files changed, 28 insertions(+) create mode 100644 example/diagram.json create mode 100644 example/partitions.csv diff --git a/example/diagram.json b/example/diagram.json new file mode 100644 index 0000000..81a41a0 --- /dev/null +++ b/example/diagram.json @@ -0,0 +1,21 @@ +{ + "version": 1, + "author": "mp-se", + "editor": "wokwi", + "parts": [ + { + "type": "wokwi-esp32-devkit-v1", + "id": "esp", + "top": 46.17, + "left": -11.69, + "rotate": 90, + "attrs": { "psramSize": "2", "firmwareOffset": "0" } + } + ], + "connections": [ + [ "esp:TX0", "$serialMonitor:RX", "", [] ], + [ "esp:RX0", "$serialMonitor:TX", "", [] ] + ], + "serialMonitor": { "display": "always", "newline": "lf", "convertEol": false }, + "dependencies": {} +} \ No newline at end of file diff --git a/example/partitions.csv b/example/partitions.csv new file mode 100644 index 0000000..db29d7d --- /dev/null +++ b/example/partitions.csv @@ -0,0 +1,7 @@ +# Name,Type,SubType,Offset,Size,Flags +nvs,data,nvs,0x9000,0x5000 +otadata,data,ota,0xe000,0x2000 +app0,app,ota_0,0x10000,0x1c0000 +app1,app,ota_1,0x1d0000,0x1c0000 +spiffs,data,spiffs,0x390000,0x60000 +coredump,data,coredump,0x3F0000,0x10000 From 7c0700e0d276f404afedd965271197ce539c311d Mon Sep 17 00:00:00 2001 From: Magnus Date: Sun, 3 Sep 2023 21:11:03 +0200 Subject: [PATCH 5/5] Fixed paths --- .gitignore | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 85676ad..64750d9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ src/demo*.* platformio.ini html/* test/* -diagram.json -wokwi.toml -partitions.csv -output.map +/diagram.json +/wokwi.toml +/partitions.csv +/output.map