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

+10
View File
@@ -267,6 +267,16 @@ void MqttPublisher::onTrunkDown(const std::string& section,
}
void MqttPublisher::onRxUpdate(const std::string& callsign,
const Json::Value& rx_json)
{
Json::StreamWriterBuilder wb;
wb["indentation"] = "";
string topic = "client/" + callsign + "/rx";
publish(topic, Json::writeString(wb, rx_json));
}
void MqttPublisher::publishFullStatus(const Json::Value& status)
{
Json::StreamWriterBuilder wb;
+3
View File
@@ -32,6 +32,9 @@ class MqttPublisher
const std::string& host, uint16_t port);
void onTrunkDown(const std::string& section, const std::string& direction);
// RX status update (per-client, all receivers)
void onRxUpdate(const std::string& callsign, const Json::Value& rx_json);
// Periodic full status
void publishFullStatus(const Json::Value& status);
+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)
{
+2
View File
@@ -254,6 +254,7 @@ class Reflector : public sigc::trackable
const std::vector<uint8_t>& audio);
void forwardFlushToSatellitesExcept(SatelliteLink* except, uint32_t tg);
void publishRxUpdate(ReflectorClient* client);
void onClientAuthenticated(const std::string& callsign, uint32_t tg,
const std::string& ip);
void onTrunkStateChanged(const std::string& section,
@@ -351,6 +352,7 @@ class Reflector : public sigc::trackable
void cfgUpdated(const std::string& section, const std::string& tag);
void onTrunkTalkerUpdated(uint32_t tg, std::string old_cs,
std::string new_cs);
void refreshStatus(void);
void initTrunkLinks(void);
void initTrunkServer(void);
void trunkClientConnected(Async::FramedTcpConnection* con);
@@ -1044,6 +1044,7 @@ void ReflectorClient::handleMsgSignalStrengthValues(std::istream& is)
setRxSqlOpen(rx.id(), rx.sqlOpen());
setRxActive(rx.id(), rx.active());
}
m_reflector->publishRxUpdate(this);
} /* ReflectorClient::handleMsgSignalStrengthValues */
+11
View File
@@ -463,6 +463,17 @@ class ReflectorClient : public sigc::trackable
}
return ids;
}
Json::Value rxStatusJson(void) const
{
Json::Value rx_json(Json::objectValue);
for (const auto& rx : m_json_rx_map)
{
std::string key(1, rx.first);
rx_json[key] = rx.second;
}
return rx_json;
}
void setRxSiglev(char id, uint8_t siglev)
{
setRxParam(id, "siglev", siglev);