From be937da6b9f798757e4be2c89ba5d14fc085ba55 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Mon, 30 Oct 2023 22:20:19 +0100 Subject: [PATCH] Fix connecting to node --- src/lib/pin/mcp23017_pin.cpp | 0 src/lib/pin/mcp23017_pin.hpp | 6 ------ src/lib/pin/native_pin.cpp | 0 src/lib/pin/native_pin.hpp | 6 ------ src/lib/pin/pcf8575_pin.cpp | 0 src/lib/pin/pcf8575_pin.hpp | 6 ------ src/lib/pin/universal_pin.cpp | 5 ----- src/lib/pin/universal_pin.hpp | 12 ------------ src/lib/webserver.cpp | 2 +- src/main.cpp | 2 +- src/screens/halvingcountdown.cpp | 19 ++++++------------- src/screens/time.cpp | 9 +++++---- src/shared.hpp | 2 +- src/tasks/blocknotify.cpp | 20 +++++++++++--------- src/tasks/minute.cpp | 2 +- 15 files changed, 26 insertions(+), 65 deletions(-) delete mode 100644 src/lib/pin/mcp23017_pin.cpp delete mode 100644 src/lib/pin/mcp23017_pin.hpp delete mode 100644 src/lib/pin/native_pin.cpp delete mode 100644 src/lib/pin/native_pin.hpp delete mode 100644 src/lib/pin/pcf8575_pin.cpp delete mode 100644 src/lib/pin/pcf8575_pin.hpp delete mode 100644 src/lib/pin/universal_pin.cpp delete mode 100644 src/lib/pin/universal_pin.hpp diff --git a/src/lib/pin/mcp23017_pin.cpp b/src/lib/pin/mcp23017_pin.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/pin/mcp23017_pin.hpp b/src/lib/pin/mcp23017_pin.hpp deleted file mode 100644 index a9e5c0e..0000000 --- a/src/lib/pin/mcp23017_pin.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "universal_pin.hpp" - -class MCP23017_Pin : public UniversalPin -{ - -}; \ No newline at end of file diff --git a/src/lib/pin/native_pin.cpp b/src/lib/pin/native_pin.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/pin/native_pin.hpp b/src/lib/pin/native_pin.hpp deleted file mode 100644 index 3b2c5f3..0000000 --- a/src/lib/pin/native_pin.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "universal_pin.hpp" - -class Native_Pin : public UniversalPin -{ - -}; \ No newline at end of file diff --git a/src/lib/pin/pcf8575_pin.cpp b/src/lib/pin/pcf8575_pin.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/pin/pcf8575_pin.hpp b/src/lib/pin/pcf8575_pin.hpp deleted file mode 100644 index 9795fae..0000000 --- a/src/lib/pin/pcf8575_pin.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "universal_pin.hpp" - -class PCF8575_Pin : public UniversalPin -{ - -}; \ No newline at end of file diff --git a/src/lib/pin/universal_pin.cpp b/src/lib/pin/universal_pin.cpp deleted file mode 100644 index b64aa72..0000000 --- a/src/lib/pin/universal_pin.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "universal_pin.hpp" - -UniversalPin::UniversalPin(uint pinNumber) { - this->pinNumber = pinNumber; -} \ No newline at end of file diff --git a/src/lib/pin/universal_pin.hpp b/src/lib/pin/universal_pin.hpp deleted file mode 100644 index e673632..0000000 --- a/src/lib/pin/universal_pin.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -class UniversalPin -{ - public: - UniversalPin(uint pinNumber); - virtual void pinMode(uint8_t mode); - virtual uint8_t digitalRead(); - virtual void digitalWrite(uint8_t value); - protected: - uint pinNumber; -}; \ No newline at end of file diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 1a4782d..f1fb48e 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -75,7 +75,7 @@ void onApiStatus(AsyncWebServerRequest *request) StaticJsonDocument<512> root; root["currentScreen"] = String(getCurrentScreen()); root["timerRunning"] = timerRunning; - + root["numScreens"] = NUM_SCREENS; JsonArray data = root.createNestedArray("data"); JsonArray rendered = root.createNestedArray("rendered"); String epdContent[7]; diff --git a/src/main.cpp b/src/main.cpp index b5208a1..3f3228f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,7 @@ #include "tasks/button.hpp" #include "tasks/led_handler.hpp" -//WiFiClient wifiClientInsecure; +WiFiClient wifiClientInsecure; WiFiClientSecure wifiClient; ESP32Time rtc(3600); diff --git a/src/screens/halvingcountdown.cpp b/src/screens/halvingcountdown.cpp index 5d8cf4d..9cb02b1 100644 --- a/src/screens/halvingcountdown.cpp +++ b/src/screens/halvingcountdown.cpp @@ -25,8 +25,7 @@ void HalvingCountdownScreen::init() for (int i = 0; i < NUM_SCREENS; i++) { epdContentP[i] = HalvingCountdownScreen::psramBuffer + i * maxStringLength; - // strcpy(epdContent[i], "x"); - strcpy(epdContentP[i], "x"); + strcpy(epdContentP[i], ""); } initialized = true; setupBlockNotify(); @@ -48,18 +47,12 @@ void HalvingCountdownScreen::showScreen() snprintf(HalvingCountdownScreen::epdContentP[0], maxStringLength, "BIT/COIN"); snprintf(HalvingCountdownScreen::epdContentP[1], maxStringLength, "HALV/ING"); - snprintf(HalvingCountdownScreen::epdContentP[2], maxStringLength, "%d/YRS", years); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-5)], maxStringLength, "%d/YRS", years); - snprintf(HalvingCountdownScreen::epdContentP[3], maxStringLength, "%d/DAYS", days); - snprintf(HalvingCountdownScreen::epdContentP[4], maxStringLength, "%d/HRS", hours); - snprintf(HalvingCountdownScreen::epdContentP[5], maxStringLength, "%d/MINS", mins); - snprintf(HalvingCountdownScreen::epdContentP[6], maxStringLength, "TO/GO"); - - // // strcpy(epdContent[2], sprintf(String(years) + "/YRS").c_str()); - // // snprintf(epdContent[2], sizeof(epdContent[2]), "%d/YRS", years); - // // strcpy(epdContent[3], String(days) + "/DAYS"); - // // strcpy(epdContent[4], String(hours) + "/HRS"); - // // strcpy(epdContent[5], String(mins) + "/MINS"); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-4)], maxStringLength, "%d/DAYS", days); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-3)], maxStringLength, "%d/HRS", hours); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-2)], maxStringLength, "%d/MINS", mins); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-1)], maxStringLength, "TO/GO"); } uint HalvingCountdownScreen::getNextHalvingBlockNr() diff --git a/src/screens/time.cpp b/src/screens/time.cpp index 9968a06..2d8717c 100644 --- a/src/screens/time.cpp +++ b/src/screens/time.cpp @@ -8,12 +8,13 @@ void TimeScreen::init() { } void TimeScreen::showScreen() { - // String(String(rtc.getDay()) + "/" + String(rtc.getMonth() + 1)).toCharArray(TimeScreen::dateString, 5); - // rtc.getTime("%H:%M").toCharArray(TimeScreen::timeString, 5); - std::string timeString = rtc.getTime("%H:%M").c_str(); timeString.insert(timeString.begin(), NUM_SCREENS - timeString.length(), ' '); - TimeScreen::epdContent[0] = String(rtc.getDay()) + "/" + String(rtc.getMonth() + 1); + char dateTmp[6]; + snprintf(dateTmp, 6, "%d/%d", rtc.getDay(), (rtc.getMonth() + 1)); + + TimeScreen::epdContent[0] = dateTmp; + for (uint i = 1; i < NUM_SCREENS; i++) { TimeScreen::epdContent[i] = timeString[i]; diff --git a/src/shared.hpp b/src/shared.hpp index 9fe97ff..e3af487 100644 --- a/src/shared.hpp +++ b/src/shared.hpp @@ -26,7 +26,7 @@ typedef std::function EventCallback; typedef std::function EventCallbackWithNumber; -//extern WiFiClient wifiClientInsecure; +extern WiFiClient wifiClientInsecure; extern WiFiClientSecure wifiClient; extern ESP32Time rtc; diff --git a/src/tasks/blocknotify.cpp b/src/tasks/blocknotify.cpp index b09e603..4614b85 100644 --- a/src/tasks/blocknotify.cpp +++ b/src/tasks/blocknotify.cpp @@ -18,20 +18,23 @@ bool useBitcoind = true; void checkBitcoinBlock(void *pvParameters) { uint blockHeight = preferences.getUInt("blockHeight", currentBlockHeight); - - - useBitcoind = preferences.getBool("useNode", false) && wifiClient.connect(preferences.getString("rpcHost", BITCOIND_HOST).c_str(), preferences.getUInt("rpcPort", BITCOIND_PORT)); + + useBitcoind = preferences.getBool("useNode", false) && wifiClientInsecure.connect(preferences.getString("rpcHost", BITCOIND_HOST).c_str(), preferences.getUInt("rpcPort", BITCOIND_PORT)); if (useBitcoind) Serial.println(F("bitcoind node is reachable, using this for blocks.")); else Serial.println(F("bitcoind node is not reachable, using mempool API instead.")); - IPAddress result; + if (!useBitcoind) + { + IPAddress result; - int err = WiFi.hostByName(preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE).c_str(), result) ; + int err = WiFi.hostByName(preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE).c_str(), result); - if (err != 1) { - flashTemporaryLights(255, 0, 0); + if (err != 1) + { + flashTemporaryLights(255, 0, 0); + } } for (;;) @@ -79,7 +82,6 @@ void checkBitcoinBlock(void *pvParameters) Serial.print(F("Error in HTTP request to mempool API: ")); Serial.print(httpCode); Serial.println(http->errorToString(httpCode)); - } http->end(); @@ -93,7 +95,7 @@ void checkBitcoinBlock(void *pvParameters) currentBlockHeight = blockHeight; preferences.putUInt("blockHeight", currentBlockHeight); } - delete http; + delete http; vTaskDelay(pdMS_TO_TICKS(BLOCKNOTIFY_WAIT_TIME)); // wait 1 minute before checking again } } diff --git a/src/tasks/minute.cpp b/src/tasks/minute.cpp index dc57bde..83fe04e 100644 --- a/src/tasks/minute.cpp +++ b/src/tasks/minute.cpp @@ -35,7 +35,7 @@ void minuteTask(void * parameter) { void setupMinuteEvent() { - xTaskCreate(minuteTask, "MinuteTask", 2048, NULL, 1, &minuteTaskHandle); // Create the FreeRTOS task + xTaskCreate(minuteTask, "MinuteTask", 4096, NULL, 1, &minuteTaskHandle); // Create the FreeRTOS task } void registerNewMinuteCallback(const EventCallback cb)