Add Nostr Relay connection status

This commit is contained in:
Djuri Baars 2024-07-15 16:36:51 +02:00
parent 60593de785
commit 19559727c9
5 changed files with 32 additions and 4 deletions

2
data

@ -1 +1 @@
Subproject commit ee4d6d88c76fa279e643faabf4216c88145e0b2c
Subproject commit e7b52b7367f0585e87e16ceaf22d9a2339a1fd04

View File

@ -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

View File

@ -3,13 +3,14 @@
std::vector<nostr::NostrPool *> 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<nostr::NostrRelay *> *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;
}

View File

@ -14,4 +14,6 @@
void setupNostrNotify();
void nostrTask(void *pvParameters);
void setupNostrTask();
void setupNostrTask();
boolean nostrConnected();

View File

@ -229,6 +229,7 @@ JsonDocument getStatusObject()
JsonObject conStatus = root["connectionStatus"].to<JsonObject>();
conStatus["price"] = isPriceNotifyConnected();
conStatus["blocks"] = isBlockNotifyConnected();
conStatus["nostr"] = nostrConnected();
root["rssi"] = WiFi.RSSI();