diff --git a/data b/data index ee4d6d8..e7b52b7 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit ee4d6d88c76fa279e643faabf4216c88145e0b2c +Subproject commit e7b52b7367f0585e87e16ceaf22d9a2339a1fd04 diff --git a/platformio.ini b/platformio.ini index f4cb6e5..14818ad 100644 --- a/platformio.ini +++ b/platformio.ini @@ -41,7 +41,7 @@ lib_deps = https://github.com/dsbaars/universal_pin https://github.com/dsbaars/GxEPD2#universal_pin https://github.com/tzapu/WiFiManager.git#v2.0.17 - rblb/Nostrduino@^1.2.7 + rblb/Nostrduino@^1.2.8 [env:lolin_s3_mini] extends = btclock_base diff --git a/src/lib/nostr_notify.cpp b/src/lib/nostr_notify.cpp index a2784d6..68e84a3 100644 --- a/src/lib/nostr_notify.cpp +++ b/src/lib/nostr_notify.cpp @@ -3,13 +3,14 @@ std::vector pools; nostr::Transport *transport; TaskHandle_t nostrTaskHandle = NULL; +boolean nostrIsConnected = false; void setupNostrNotify() { nostr::esp32::ESP32Platform::initNostr(false); time_t now; time(&now); - struct tm* utcTimeInfo; + struct tm *utcTimeInfo; utcTimeInfo = gmtime(&now); time_t utcNow = mktime(utcTimeInfo); time_t timestamp60MinutesAgo = utcNow - 3600; @@ -98,6 +99,25 @@ void setupNostrNotify() // EOSE Serial.println("Subscription EOSE: " + subId); }); + + std::vector *relays = pool->getConnectedRelays(); + for (nostr::NostrRelay *relay : *relays) + { + Serial.println("Registering to connection events of: " + relay->getUrl()); + relay->getConnection()->addConnectionStatusListener([&](const nostr::ConnectionStatus &status) + { + String sstatus="UNKNOWN"; + if(status==nostr::ConnectionStatus::CONNECTED){ + nostrIsConnected = true; + sstatus="CONNECTED"; + }else if(status==nostr::ConnectionStatus::DISCONNECTED){ + nostrIsConnected = false; + sstatus="DISCONNECTED"; + }else if(status==nostr::ConnectionStatus::ERROR){ + sstatus = "ERROR"; + } + Serial.println("Connection status changed: " + sstatus); }); + } } catch (const std::exception &e) { @@ -125,4 +145,9 @@ void nostrTask(void *pvParameters) void setupNostrTask() { xTaskCreate(nostrTask, "nostrTask", 16384, NULL, 10, &nostrTaskHandle); +} + +boolean nostrConnected() +{ + return nostrIsConnected; } \ No newline at end of file diff --git a/src/lib/nostr_notify.hpp b/src/lib/nostr_notify.hpp index e76c87b..65e1f19 100644 --- a/src/lib/nostr_notify.hpp +++ b/src/lib/nostr_notify.hpp @@ -14,4 +14,6 @@ void setupNostrNotify(); void nostrTask(void *pvParameters); -void setupNostrTask(); \ No newline at end of file +void setupNostrTask(); + +boolean nostrConnected(); \ No newline at end of file diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 175d8f0..c257a70 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -229,6 +229,7 @@ JsonDocument getStatusObject() JsonObject conStatus = root["connectionStatus"].to(); conStatus["price"] = isPriceNotifyConnected(); conStatus["blocks"] = isBlockNotifyConnected(); + conStatus["nostr"] = nostrConnected(); root["rssi"] = WiFi.RSSI();