Add MQTT RX status events and fix periodic status publishing

Periodic MQTT status was missing dynamic fields (trunks, cluster_tgs,
local_prefix, etc.) because they were only rebuilt during HTTP requests.
Extract status-building into refreshStatus() called from both paths.

Add per-client RX status MQTT events (client/{callsign}/rx) published on
every signal strength update, supporting multiple receivers per node.
This commit is contained in:
Audric committed 2026-04-09 12:59:52 +02:00
1 parent 4a9cba6edb
commit a2eefac1f2
8 files changed
+86 -18

No files matched your search

+32 -15
View File
@@ -497,6 +497,7 @@ bool Reflector::initialize(Async::Config &cfg)
m_mqtt_status_timer.expired.connect(
[this](Async::Timer*)
{
refreshStatus();
m_mqtt->publishFullStatus(m_status);
m_mqtt_status_timer.setEnable(true);
});
@@ -1472,6 +1473,7 @@ void Reflector::udpDatagramReceived(const IpAddress& addr, uint16_t port,
client->setRxSqlOpen(rx.id(), rx.sqlOpen());
client->setRxActive(rx.id(), rx.active());
}
publishRxUpdate(client);
}
break;
}
@@ -1603,7 +1605,26 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
return;
}
// Build trunk status fresh on each request (live state)
refreshStatus();
std::ostringstream os;
Json::StreamWriterBuilder builder;
builder["commentStyle"] = "None";
builder["indentation"] = ""; //The JSON document is written on a single line
Json::StreamWriter* writer = builder.newStreamWriter();
writer->write(m_status, &os);
delete writer;
res.setContent("application/json", os.str());
res.setSendContent(req.method == "GET");
res.setCode(200);
con->write(res);
} /* Reflector::requestReceived */
void Reflector::refreshStatus(void)
{
// Build trunk status fresh (live state)
Json::Value trunks(Json::objectValue);
for (auto* link : m_trunk_links)
{
@@ -1699,20 +1720,7 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
m_status["satellite_server"] = sat_srv;
}
}
std::ostringstream os;
Json::StreamWriterBuilder builder;
builder["commentStyle"] = "None";
builder["indentation"] = ""; //The JSON document is written on a single line
Json::StreamWriter* writer = builder.newStreamWriter();
writer->write(m_status, &os);
delete writer;
res.setContent("application/json", os.str());
res.setSendContent(req.method == "GET");
res.setCode(200);
con->write(res);
} /* Reflector::requestReceived */
} /* Reflector::refreshStatus */
void Reflector::httpClientConnected(Async::HttpServerConnection *con)
@@ -2579,6 +2587,15 @@ void Reflector::onTrunkTalkerUpdated(uint32_t tg,
} /* Reflector::onTrunkTalkerUpdated */
void Reflector::publishRxUpdate(ReflectorClient* client)
{
if (m_mqtt != nullptr && !client->callsign().empty())
{
m_mqtt->onRxUpdate(client->callsign(), client->rxStatusJson());
}
} /* Reflector::publishRxUpdate */
void Reflector::onClientAuthenticated(const std::string& callsign,
uint32_t tg, const std::string& ip)
{