From e0283d98caa9de778bbf4647f33c40346fb4ddcf Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Thu, 9 May 2024 01:02:40 +0200 Subject: [PATCH] Use own data source for price and block data --- data | 2 +- src/lib/block_notify.cpp | 13 +++++++++---- src/lib/block_notify.hpp | 4 ++-- src/lib/price_notify.cpp | 6 +++++- src/lib/price_notify.hpp | 2 +- src/lib/webserver.cpp | 4 ++-- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/data b/data index e47fc06..6ecb482 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit e47fc066b0608132c44a35f7041be80b263adcff +Subproject commit 6ecb4826000e4a34f22d98541d28448f844340f7 diff --git a/src/lib/block_notify.cpp b/src/lib/block_notify.cpp index d01b3d6..cc927bc 100644 --- a/src/lib/block_notify.cpp +++ b/src/lib/block_notify.cpp @@ -87,6 +87,11 @@ void setupBlockNotify() xQueueSend(workQueue, &blockUpdate, portMAX_DELAY); } + if (preferences.getBool("ownDataSource", true)) + { + return; + } + // std::strcpy(wsServer, String("wss://" + mempoolInstance + // "/api/v1/ws").c_str()); @@ -99,11 +104,11 @@ void setupBlockNotify() blockNotifyClient = esp_websocket_client_init(&config); esp_websocket_register_events(blockNotifyClient, WEBSOCKET_EVENT_ANY, - onWebsocketEvent, blockNotifyClient); + onWebsocketBlockEvent, blockNotifyClient); esp_websocket_client_start(blockNotifyClient); } -void onWebsocketEvent(void *handler_args, esp_event_base_t base, +void onWebsocketBlockEvent(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) { esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data; @@ -124,7 +129,7 @@ void onWebsocketEvent(void *handler_args, esp_event_base_t base, break; case WEBSOCKET_EVENT_DATA: - onWebsocketMessage(data); + onWebsocketBlockMessage(data); break; case WEBSOCKET_EVENT_ERROR: Serial.println(F("Mempool.space WS Connnection error")); @@ -135,7 +140,7 @@ void onWebsocketEvent(void *handler_args, esp_event_base_t base, } } -void onWebsocketMessage(esp_websocket_event_data_t *event_data) +void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data) { JsonDocument doc; diff --git a/src/lib/block_notify.hpp b/src/lib/block_notify.hpp index b44060f..c233b2e 100644 --- a/src/lib/block_notify.hpp +++ b/src/lib/block_notify.hpp @@ -17,9 +17,9 @@ void setupBlockNotify(); -void onWebsocketEvent(void *handler_args, esp_event_base_t base, +void onWebsocketBlockEvent(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data); -void onWebsocketMessage(esp_websocket_event_data_t *event_data); +void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data); void setBlockHeight(uint newBlockHeight); uint getBlockHeight(); diff --git a/src/lib/price_notify.cpp b/src/lib/price_notify.cpp index 0fe80d2..bcd091a 100644 --- a/src/lib/price_notify.cpp +++ b/src/lib/price_notify.cpp @@ -45,7 +45,7 @@ void setupPriceNotify() { // currentPrice = preferences.get("lastPrice", 30000); - if (preferences.getBool("ownPriceSource", true)) + if (preferences.getBool("ownDataSource", true)) { config = {.uri = wsOwnServerPrice, .user_agent = USER_AGENT}; @@ -76,6 +76,10 @@ void onWebsocketPriceEvent(void *handler_args, esp_event_base_t base, break; case WEBSOCKET_EVENT_DATA: onWebsocketPriceMessage(data); + if (preferences.getBool("ownDataSource", true)) + { + onWebsocketBlockMessage(data); + } break; case WEBSOCKET_EVENT_ERROR: Serial.println(F("Price WS Connnection error")); diff --git a/src/lib/price_notify.hpp b/src/lib/price_notify.hpp index 0382a8c..44c343d 100644 --- a/src/lib/price_notify.hpp +++ b/src/lib/price_notify.hpp @@ -3,7 +3,7 @@ #include #include #include - +#include "block_notify.hpp" #include #include "lib/screen_handler.hpp" diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 5e6877b..371f17b 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -329,7 +329,7 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) { String boolSettings[] = {"fetchEurPrice", "ledTestOnPower", "ledFlashOnUpd", "mdnsEnabled", "otaEnabled", "stealFocus", "mcapBigChar", "useSatsSymbol", "useBlkCountdown", - "suffixPrice", "disableLeds", "ownPriceSource", "flAlwaysOn"}; + "suffixPrice", "disableLeds", "ownDataSource", "flAlwaysOn"}; for (String setting : boolSettings) { if (settings.containsKey(setting)) { @@ -425,7 +425,7 @@ void onApiSettingsGet(AsyncWebServerRequest *request) { root["hostname"] = getMyHostname(); root["ip"] = WiFi.localIP(); root["txPower"] = WiFi.getTxPower(); - root["ownPriceSource"] = preferences.getBool("ownPriceSource", true); + root["ownDataSource"] = preferences.getBool("ownDataSource", true); #ifdef HAS_FRONTLIGHT root["hasFrontlight"] = true;