Add Nostr Relay connection status
This commit is contained in:
parent
60593de785
commit
19559727c9
5 changed files with 32 additions and 4 deletions
2
data
2
data
|
@ -1 +1 @@
|
|||
Subproject commit ee4d6d88c76fa279e643faabf4216c88145e0b2c
|
||||
Subproject commit e7b52b7367f0585e87e16ceaf22d9a2339a1fd04
|
|
@ -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
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
std::vector<nostr::NostrPool *> pools;
|
||||
nostr::Transport *transport;
|
||||
TaskHandle_t nostrTaskHandle = NULL;
|
||||
boolean nostrIsConnected = false;
|
||||
|
||||
void setupNostrNotify()
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -126,3 +146,8 @@ void setupNostrTask()
|
|||
{
|
||||
xTaskCreate(nostrTask, "nostrTask", 16384, NULL, 10, &nostrTaskHandle);
|
||||
}
|
||||
|
||||
boolean nostrConnected()
|
||||
{
|
||||
return nostrIsConnected;
|
||||
}
|
|
@ -15,3 +15,5 @@ void setupNostrNotify();
|
|||
|
||||
void nostrTask(void *pvParameters);
|
||||
void setupNostrTask();
|
||||
|
||||
boolean nostrConnected();
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue