diff --git a/src/lib/config.cpp b/src/lib/config.cpp index 4c7303c..38fba9e 100644 --- a/src/lib/config.cpp +++ b/src/lib/config.cpp @@ -284,6 +284,22 @@ void setupPreferences() setBlockHeight(preferences.getUInt("blockHeight", INITIAL_BLOCK_HEIGHT)); setPrice(preferences.getUInt("lastPrice", INITIAL_LAST_PRICE), CURRENCY_USD); + if (!preferences.isKey("enableDebugLog")) { + preferences.putBool("enableDebugLog", DEFAULT_ENABLE_DEBUG_LOG); + } + + if (!preferences.isKey("ceEnabled")) { + preferences.putBool("ceEnabled", DEFAULT_CUSTOM_ENDPOINT_ENABLED); + } + + if (!preferences.isKey("ceEndpoint")) { + preferences.putString("ceEndpoint", DEFAULT_CUSTOM_ENDPOINT); + } + + if (!preferences.isKey("ceDisableSSL")) { + preferences.putBool("ceDisableSSL", DEFAULT_CUSTOM_ENDPOINT_DISABLE_SSL); + } + if (preferences.getBool("ownDataSource", DEFAULT_OWN_DATA_SOURCE)) ScreenHandler::setCurrentCurrency(preferences.getUChar("lastCurrency", CURRENCY_USD)); else @@ -767,3 +783,8 @@ const char* getWebUiFilename() { return "littlefs_4MB.bin"; } } + +bool debugLogEnabled() +{ + return preferences.getBool("enableDebugLog", DEFAULT_ENABLE_DEBUG_LOG); +} diff --git a/src/lib/config.hpp b/src/lib/config.hpp index 2c001cd..806497c 100644 --- a/src/lib/config.hpp +++ b/src/lib/config.hpp @@ -77,6 +77,8 @@ String getHwRev(); bool isWhiteVersion(); String getFsRev(); +bool debugLogEnabled(); + void addScreenMapping(int value, const char* name); // void addScreenMapping(int value, const String& name); // void addScreenMapping(int value, const std::string& name); diff --git a/src/lib/defaults.hpp b/src/lib/defaults.hpp index d880f2d..da4d405 100644 --- a/src/lib/defaults.hpp +++ b/src/lib/defaults.hpp @@ -17,7 +17,9 @@ #define DEFAULT_DISABLE_LEDS false #define DEFAULT_DISABLE_FL false #define DEFAULT_OWN_DATA_SOURCE true -#define DEFAULT_STAGING_SOURCE false +#define DEFAULT_CUSTOM_SOURCE false +#define DEFAULT_CUSTOM_EP "ws-staging.btclock.dev" +#define DEFAULT_CUSTOM_SSL true #define DEFAULT_MOW_MODE false #define DEFAULT_SUFFIX_SHARE_DOT false @@ -77,3 +79,12 @@ #define DEFAULT_VERTICAL_DESC true #define DEFAULT_MINING_POOL_LOGOS_URL "https://git.btclock.dev/btclock/mining-pool-logos/raw/branch/main" + +#define DEFAULT_ENABLE_DEBUG_LOG false + +#define DEFAULT_DISABLE_FL false +#define DEFAULT_OWN_DATA_SOURCE true +#define DEFAULT_CUSTOM_ENDPOINT_ENABLED false +#define DEFAULT_CUSTOM_ENDPOINT "ws-staging.btclock.dev" +#define DEFAULT_CUSTOM_ENDPOINT_DISABLE_SSL false +#define DEFAULT_MOW_MODE false diff --git a/src/lib/mining_pool_stats_fetch.cpp b/src/lib/mining_pool_stats_fetch.cpp index 9687e03..a35a00e 100644 --- a/src/lib/mining_pool_stats_fetch.cpp +++ b/src/lib/mining_pool_stats_fetch.cpp @@ -36,6 +36,10 @@ void taskMiningPoolStatsFetch(void *pvParameters) poolInterface->setPoolUser(poolUser); std::string apiUrl = poolInterface->getApiUrl(); http.begin(apiUrl.c_str()); + if (debugLogEnabled()) + { + Serial.printf("Fetching mining pool stats from %s\r\n", apiUrl.c_str()); + } poolInterface->prepareRequest(http); int httpCode = http.GET(); if (httpCode == 200) @@ -44,10 +48,20 @@ void taskMiningPoolStatsFetch(void *pvParameters) JsonDocument doc; deserializeJson(doc, payload); + if (debugLogEnabled()) + { + Serial.printf("Mining pool stats response: %s\r\n", payload.c_str()); + } + PoolStats stats = poolInterface->parseResponse(doc); miningPoolStatsHashrate = stats.hashrate; + if (debugLogEnabled()) + { + Serial.printf("Mining pool stats parsed hashrate: %s\r\n", stats.hashrate.c_str()); + } + if (stats.dailyEarnings) { miningPoolStatsDailyEarnings = *stats.dailyEarnings; diff --git a/src/lib/nostr_notify.cpp b/src/lib/nostr_notify.cpp index 20bdd01..46c6ecf 100644 --- a/src/lib/nostr_notify.cpp +++ b/src/lib/nostr_notify.cpp @@ -267,7 +267,10 @@ void handleNostrZapCallback(const String &subId, nostr::SignedNostrEvent *event) std::array textEpdContent = parseZapNotify(zapAmount, preferences.getBool("useSatsSymbol", DEFAULT_USE_SATS_SYMBOL)); - Serial.printf("Got a zap of %llu sats for %s\n", zapAmount, zapPubkey.c_str()); + if (debugLogEnabled()) + { + Serial.printf("Got a zap of %llu sats for %s\n", zapAmount, zapPubkey.c_str()); + } uint64_t timerPeriod = 0; if (isTimerActive()) diff --git a/src/lib/v2_notify.cpp b/src/lib/v2_notify.cpp index e0b5966..5c30ad2 100644 --- a/src/lib/v2_notify.cpp +++ b/src/lib/v2_notify.cpp @@ -8,25 +8,36 @@ namespace V2Notify TaskHandle_t v2NotifyTaskHandle; + String currentHostname; + void setupV2Notify() { String hostname = "ws.btclock.dev"; - if (preferences.getBool("stagingSource", DEFAULT_STAGING_SOURCE)) + if (preferences.getBool("ceEnabled", DEFAULT_CUSTOM_ENDPOINT_ENABLED)) { - Serial.println(F("Connecting to V2 staging source")); - hostname = "ws-staging.btclock.dev"; + Serial.println(F("Connecting to custom source")); + hostname = preferences.getString("ceEndpoint", DEFAULT_CUSTOM_ENDPOINT); + bool useSSL = !preferences.getBool("ceDisableSSL", DEFAULT_CUSTOM_ENDPOINT_DISABLE_SSL); + + if (useSSL) { + webSocket.beginSSL(hostname, 443, "/api/v2/ws"); + } else { + webSocket.begin(hostname, 80, "/api/v2/ws"); + } } else { Serial.println(F("Connecting to V2 source")); + webSocket.beginSSL(hostname, 443, "/api/v2/ws"); } - webSocket.beginSSL(hostname, 443, "/api/v2/ws"); webSocket.onEvent(V2Notify::onWebsocketV2Event); webSocket.setReconnectInterval(5000); webSocket.enableHeartbeat(15000, 3000, 2); V2Notify::setupV2NotifyTask(); + + currentHostname = hostname; } void onWebsocketV2Event(WStype_t type, uint8_t *payload, size_t length) @@ -38,7 +49,9 @@ namespace V2Notify break; case WStype_CONNECTED: { - Serial.print(F("[WSc] Connected to url:")); + Serial.print(F("[WSc] Connected to ")); + Serial.print(currentHostname); + Serial.print(F(": ")); Serial.println((char *)payload); JsonDocument response; diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 4a8a8f5..2571505 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -3,7 +3,7 @@ static const char* JSON_CONTENT = "application/json"; static const char *const PROGMEM strSettings[] = { - "hostnamePrefix", "mempoolInstance", "nostrPubKey", "nostrRelay", "bitaxeHostname", "miningPoolName", "miningPoolUser", "nostrZapPubkey", "httpAuthUser", "httpAuthPass", "gitReleaseUrl", "poolLogosUrl"}; + "hostnamePrefix", "mempoolInstance", "nostrPubKey", "nostrRelay", "bitaxeHostname", "miningPoolName", "miningPoolUser", "nostrZapPubkey", "httpAuthUser", "httpAuthPass", "gitReleaseUrl", "poolLogosUrl", "ceEndpoint"}; static const char *const PROGMEM uintSettings[] = {"minSecPriceUpd", "fullRefreshMin", "ledBrightness", "flMaxBrightness", "flEffectDelay", "luxLightToggle", "wpTimeout", "srcV2Currency"}; @@ -15,7 +15,8 @@ static const char *const PROGMEM boolSettings[] = {"fetchEurPrice", "ledTestOnPo "flAlwaysOn", "flDisable", "flFlashOnUpd", "mempoolSecure", "useNostr", "bitaxeEnabled", "miningPoolStats", "verticalDesc", - "nostrZapNotify", "stagingSource", "httpAuthEnabled"}; + "nostrZapNotify", "ceEnabled", "httpAuthEnabled", + "enableDebugLog", "ceDisableSSL"}; AsyncWebServer server(80); AsyncEventSource events("/events"); @@ -458,25 +459,22 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) bool settingsChanged = true; - if (settings["fgColor"].is()) + if (settings["invertedColor"].is()) { - String fgColor = settings["fgColor"].as(); - uint32_t color = strtol(fgColor.c_str(), NULL, 16); - preferences.putUInt("fgColor", color); - setFgColor(color); - Serial.print(F("Setting foreground color to ")); - Serial.println(color); - settingsChanged = true; - } - if (settings["bgColor"].is()) - { - String bgColor = settings["bgColor"].as(); - - uint32_t color = strtol(bgColor.c_str(), NULL, 16); - preferences.putUInt("bgColor", color); - setBgColor(color); - Serial.print(F("Setting background color to ")); - Serial.println(bgColor.c_str()); + bool inverted = settings["invertedColor"].as(); + preferences.putBool("invertedColor", inverted); + if (inverted) { + preferences.putUInt("fgColor", GxEPD_WHITE); + preferences.putUInt("bgColor", GxEPD_BLACK); + setFgColor(GxEPD_WHITE); + setBgColor(GxEPD_BLACK); + } else { + preferences.putUInt("fgColor", GxEPD_BLACK); + preferences.putUInt("bgColor", GxEPD_WHITE); + setFgColor(GxEPD_BLACK); + setBgColor(GxEPD_WHITE); + } + Serial.printf("Setting invertedColor to %d\r\n", inverted); settingsChanged = true; } @@ -627,8 +625,7 @@ void onApiSettingsGet(AsyncWebServerRequest *request) JsonDocument root; root["numScreens"] = NUM_SCREENS; - root["fgColor"] = getFgColor(); - root["bgColor"] = getBgColor(); + root["invertedColor"] = preferences.getBool("invertedColor", getFgColor() == GxEPD_WHITE); root["timerSeconds"] = getTimerSeconds(); root["timerRunning"] = isTimerActive(); root["minSecPriceUpd"] = preferences.getUInt( @@ -657,13 +654,13 @@ void onApiSettingsGet(AsyncWebServerRequest *request) root["verticalDesc"] = preferences.getBool("verticalDesc", DEFAULT_VERTICAL_DESC); root["suffixShareDot"] = preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT); + root["enableDebugLog"] = preferences.getBool("enableDebugLog", DEFAULT_ENABLE_DEBUG_LOG); root["hostnamePrefix"] = preferences.getString("hostnamePrefix", DEFAULT_HOSTNAME_PREFIX); root["hostname"] = getMyHostname(); root["ip"] = WiFi.localIP(); root["txPower"] = WiFi.getTxPower(); root["ownDataSource"] = preferences.getBool("ownDataSource", DEFAULT_OWN_DATA_SOURCE); - root["stagingSource"] = preferences.getBool("stagingSource", DEFAULT_STAGING_SOURCE); root["srcV2Currency"] = preferences.getChar("srcV2Currency", DEFAULT_V2_SOURCE_CURRENCY); root["nostrPubKey"] = preferences.getString("nostrPubKey", DEFAULT_NOSTR_NPUB); @@ -734,6 +731,10 @@ void onApiSettingsGet(AsyncWebServerRequest *request) root["poolLogosUrl"] = preferences.getString("poolLogosUrl", DEFAULT_MINING_POOL_LOGOS_URL); + root["ceEnabled"] = preferences.getBool("ceEnabled", DEFAULT_CUSTOM_ENDPOINT_ENABLED); + root["ceEndpoint"] = preferences.getString("ceEndpoint", DEFAULT_CUSTOM_ENDPOINT); + root["ceDisableSSL"] = preferences.getBool("ceDisableSSL", DEFAULT_CUSTOM_ENDPOINT_DISABLE_SSL); + AsyncResponseStream *response = request->beginResponseStream(JSON_CONTENT); serializeJson(root, *response);