From cc28df888b9d662e6f9382cdab6e0c2633f19c1f Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Sat, 7 Oct 2023 20:37:47 +0200 Subject: [PATCH] Make mempool.space instance configurable, change ntp server to global pool --- data/src/index.html | 6 ++++++ data/src/js/script.ts | 15 +++++++++++++-- src/config.h | 3 ++- src/lib/webserver.cpp | 12 ++++++++++++ src/tasks/blocknotify.cpp | 3 +-- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/data/src/index.html b/data/src/index.html index f59c60d..2d8f163 100644 --- a/data/src/index.html +++ b/data/src/index.html @@ -171,6 +171,12 @@ +
+ +
+ +
+
diff --git a/data/src/js/script.ts b/data/src/js/script.ts index bf03ca3..207b59f 100644 --- a/data/src/js/script.ts +++ b/data/src/js/script.ts @@ -10,7 +10,10 @@ getBcStatus = () => { .then(jsonData => { var source = document.getElementById("entry-template").innerHTML; var template = Handlebars.compile(source); - var context = { currentScreen: jsonData.currentScreen, rendered: jsonData.rendered, data: jsonData.data, screens: screens, ledStatus: jsonData.ledStatus ? jsonData.ledStatus.map((t) => (t).toString(16)) : [] }; + + var context = { timerRunning: jsonData.timerRunning, currentScreen: jsonData.currentScreen, rendered: jsonData.rendered, data: jsonData.data, screens: screens, ledStatus: jsonData.ledStatus ? jsonData.ledStatus.map((t) => (t).toString(16)) : [] }; + + document.getElementById('output').innerHTML = template(context); }) .catch(err => { @@ -54,7 +57,7 @@ fetch('/api/settings', { document.getElementById('ledBrightness').value = jsonData.ledBrightness; document.getElementById('fullRefreshMin').value = jsonData.fullRefreshMin; document.getElementById('wpTimeout').value = jsonData.wpTimeout; - + document.getElementById('mempoolInstance').value = jsonData.mempoolInstance; if (jsonData.gitRev) document.getElementById('gitRev').innerHTML = "Version: " + jsonData.gitRev; @@ -143,4 +146,12 @@ changeScreen = (id) => { .catch(err => { //error block }); +} + +toggleTimer = (currentStatus) => { + if (currentStatus) { + fetch('/api/action/pause'); + } else { + fetch('/api/action/timer_restart'); + } } \ No newline at end of file diff --git a/src/config.h b/src/config.h index 03e3404..2e2928f 100644 --- a/src/config.h +++ b/src/config.h @@ -1,6 +1,7 @@ #pragma once -#define NTP_SERVER "nl.pool.ntp.org" +#define NTP_SERVER "pool.ntp.org" +#define DEFAULT_MEMPOOL_INSTANCE "mempool.bitcoin.nl" #define FONT_SMALL Antonio_SemiBold20pt7b #define FONT_BIG Antonio_SemiBold90pt7b diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 70c6a9c..ecc8f57 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -154,6 +154,8 @@ void onApiSettingsGet(AsyncWebServerRequest *request) root["rpcPort"] = preferences.getUInt("rpcPort", BITCOIND_PORT); root["rpcUser"] = preferences.getString("rpcUser", BITCOIND_RPC_USER); root["rpcHost"] = preferences.getString("rpcHost", BITCOIND_HOST); + root["mempoolInstance"] = preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE); + #ifdef IS_BW root["epdColors"] = 2; #else @@ -222,6 +224,16 @@ void onApiSettingsPost(AsyncWebServerRequest *request) settingsChanged = true; } + if (request->hasParam("mempoolInstance", true)) + { + AsyncWebParameter *mempoolInstance = request->getParam("mempoolInstance", true); + + preferences.putString("mempoolInstance", mempoolInstance->value().c_str()); + Serial.print("Setting mempool instance to "); + Serial.println(mempoolInstance->value().c_str()); + settingsChanged = true; + } + if (request->hasParam("ledBrightness", true)) { AsyncWebParameter *ledBrightness = request->getParam("ledBrightness", true); diff --git a/src/tasks/blocknotify.cpp b/src/tasks/blocknotify.cpp index 72f61e8..54caca3 100644 --- a/src/tasks/blocknotify.cpp +++ b/src/tasks/blocknotify.cpp @@ -20,7 +20,6 @@ void checkBitcoinBlock(void *pvParameters) int blockHeight = preferences.getUInt("blockHeight", currentBlockHeight); HTTPClient http; - http.setReuse(true); useBitcoind = preferences.getBool("useNode", false) && wifiClientInsecure.connect(preferences.getString("rpcHost", BITCOIND_HOST).c_str(), preferences.getUInt("rpcPort", BITCOIND_PORT)); if (useBitcoind) Serial.println("bitcoind node is reachable, using this for blocks."); @@ -58,7 +57,7 @@ void checkBitcoinBlock(void *pvParameters) } else { - http.begin("https://mempool.bitcoin.nl/api/blocks/tip/height"); + http.begin("https://" + preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE) + "/api/blocks/tip/height"); http.addHeader("User-Agent", "BTClock/1.0"); int httpCode = http.GET();