From 5425ea7fbfafa66a3c83e047f30b250e7abbc089 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 10 Sep 2024 11:12:14 +0200 Subject: [PATCH] Improve setup-WiFi password generation --- src/lib/config.cpp | 34 ++++++++++++++++++++++++---------- src/lib/config.hpp | 5 +++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/lib/config.cpp b/src/lib/config.cpp index 7a19abe..4acc5d3 100644 --- a/src/lib/config.cpp +++ b/src/lib/config.cpp @@ -62,7 +62,7 @@ void setup() } } - tryImprovSetup(); + setupWifi(); setupWebserver(); @@ -105,7 +105,7 @@ void setup() forceFullRefresh(); } -void tryImprovSetup() +void setupWifi() { WiFi.onEvent(WiFiEvent); WiFi.setAutoConnect(true); @@ -140,10 +140,10 @@ void tryImprovSetup() String softAP_SSID = String("BTClock" + String(mac[5], 16) + String(mac[1], 16)); WiFi.setHostname(softAP_SSID.c_str()); - String softAP_password = + String softAP_password = replaceAmbiguousChars( base64::encode(String(mac[2], 16) + String(mac[4], 16) + String(mac[5], 16) + String(mac[1], 16)) - .substring(2, 10); + .substring(2, 10)); wm.setConfigPortalTimeout(preferences.getUInt("wpTimeout", DEFAULT_WP_TIMEOUT)); wm.setWiFiAutoReconnect(false); @@ -274,9 +274,8 @@ void setupPreferences() else setCurrentCurrency(CURRENCY_USD); - addScreenMapping(SCREEN_BLOCK_HEIGHT, "Block Height"); - + addScreenMapping(SCREEN_TIME, "Time"); addScreenMapping(SCREEN_HALVING_COUNTDOWN, "Halving countdown"); addScreenMapping(SCREEN_BLOCK_FEE_RATE, "Block Fee Rate"); @@ -285,7 +284,6 @@ void setupPreferences() addScreenMapping(SCREEN_BTC_TICKER, "Ticker"); addScreenMapping(SCREEN_MARKET_CAP, "Market Cap"); - // addScreenMapping(SCREEN_SATS_PER_CURRENCY_USD, "Sats per USD"); // addScreenMapping(SCREEN_BTC_TICKER_USD, "Ticker USD"); // addScreenMapping(SCREEN_MARKET_CAP_USD, "Market Cap USD"); @@ -302,7 +300,7 @@ void setupPreferences() // screenNameMap[SCREEN_HALVING_COUNTDOWN] = "Halving countdown"; // screenNameMap[SCREEN_MARKET_CAP] = "Market Cap"; - //addCurrencyMappings(getActiveCurrencies()); + // addCurrencyMappings(getActiveCurrencies()); if (preferences.getBool("bitaxeEnabled", DEFAULT_BITAXE_ENABLED)) { @@ -311,6 +309,19 @@ void setupPreferences() } } +String replaceAmbiguousChars(String input) +{ + const char *ambiguous = "1IlO0"; + const char *replacements = "LKQM8"; + + for (int i = 0; i < strlen(ambiguous); i++) + { + input.replace(ambiguous[i], replacements[i]); + } + + return input; +} + // void addCurrencyMappings(const std::vector& currencies) // { // for (const auto& currency : currencies) @@ -375,9 +386,12 @@ void setupPreferences() void setupWebsocketClients(void *pvParameters) { - if (preferences.getBool("ownDataSource", DEFAULT_OWN_DATA_SOURCE)) { + if (preferences.getBool("ownDataSource", DEFAULT_OWN_DATA_SOURCE)) + { setupV2Notify(); - } else { + } + else + { setupBlockNotify(); setupPriceNotify(); } diff --git a/src/lib/config.hpp b/src/lib/config.hpp index 8b7434a..e615431 100644 --- a/src/lib/config.hpp +++ b/src/lib/config.hpp @@ -44,7 +44,7 @@ uint getLastTimeSync(); void setupPreferences(); void setupWebsocketClients(void *pvParameters); void setupHardware(); -void tryImprovSetup(); +void setupWifi(); void setupTimers(); void finishSetup(); void setupMcp(); @@ -81,4 +81,5 @@ void addScreenMapping(int value, const char* name); // void addScreenMapping(int value, const String& name); // void addScreenMapping(int value, const std::string& name); -int findScreenIndexByValue(int value); \ No newline at end of file +int findScreenIndexByValue(int value); +String replaceAmbiguousChars(String input); \ No newline at end of file