From 18d4868554e1687ba71c1666f20b503135234291 Mon Sep 17 00:00:00 2001 From: bitmaker Date: Fri, 12 Sep 2025 00:16:24 +0200 Subject: [PATCH] add custom AP name support via SPIFFS - read custom AP name from /apname.txt if present - fallback to default AP name if file doesn't exist - initialize SPIFFS early for AP name reading - update WiFiManager calls to use custom/default name --- src/wManager.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/wManager.cpp b/src/wManager.cpp index 992845e..d956251 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -16,6 +16,10 @@ #include "mining.h" #include "timeconst.h" +#ifdef NVMEM_SPIFFS +#include +#endif + // Flag for saving data bool shouldSaveConfig = false; @@ -31,6 +35,23 @@ nvMemory nvMem; extern SDCard SDCrd; +String readCustomAPName() { +#ifdef NVMEM_SPIFFS + if (SPIFFS.exists("/apname.txt")) { + File file = SPIFFS.open("/apname.txt", "r"); + if (file) { + String name = file.readString(); + file.close(); + name.trim(); + if (name.length() > 0 && name.length() < 32) { + return name; + } + } + } +#endif + return ""; +} + void saveConfigCallback() // Callback notifying us of the need to save configuration { @@ -76,6 +97,19 @@ void init_WifiManager() Serial.begin(115200); #endif //MONITOR_SPEED //Serial.setTxTimeoutMs(10); + + // Initialize SPIFFS to read custom AP name +#ifdef NVMEM_SPIFFS + if (!SPIFFS.begin(false)) { + SPIFFS.begin(true); + } +#endif + + // Check for custom AP name, otherwise use default + String customAPName = readCustomAPName(); + const char* apName = customAPName.length() > 0 ? customAPName.c_str() : DEFAULT_SSID; + Serial.print("Using AP name: "); + Serial.println(apName); //Init pin 15 to eneble 5V external power (LilyGo bug) #ifdef PIN_ENABLE5V @@ -204,7 +238,7 @@ void init_WifiManager() wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware drawSetupScreen(); mMonitor.NerdStatus = NM_Connecting; - wm.startConfigPortal(DEFAULT_SSID, DEFAULT_WIFIPW); + wm.startConfigPortal(apName, DEFAULT_WIFIPW); if (shouldSaveConfig) { @@ -238,7 +272,7 @@ void init_WifiManager() wm.setConfigPortalBlocking(true); wm.setEnableConfigPortal(true); // if (!wm.autoConnect(Settings.WifiSSID.c_str(), Settings.WifiPW.c_str())) - if (!wm.autoConnect(DEFAULT_SSID, DEFAULT_WIFIPW)) + if (!wm.autoConnect(apName, DEFAULT_WIFIPW)) { Serial.println("Failed to connect to configured WIFI, and hit timeout"); if (shouldSaveConfig) {