publishing: MQTT works in satellite mode + Redis publishes per-client status blob
- Move MQTT init above the satellite early-return in Reflector::initialize so satellite-mode reflectors publish to MQTT (client connect/disconnect, talker events, full status, etc.) just like full reflectors. - Add reflector-sat (SATELLITE_OF=reflector-a) to the default test compose so satellite mode is exercised end-to-end. New test_31 verifies MQTT client-connect/disconnect events under the satellite's own topic prefix. - Add RedisStore::pushClientStatus and Reflector::publishClientStatus to write the per-client status JSON (qth, rx siglev/sql_open/enabled/active, monitoredTGs, selected TG, ...) to live:client:<callsign>.status. Hooked from publishRxUpdate, handleNodeInfo, setMonitoredTGs, and setTg. - New Redis test_live_client_status_blob sends a synthetic MsgNodeInfoV2 with qth+rx and asserts the parsed blob contains the expected fields. 31/31 trunk + 10/10 twin + 14/14 redis pass.
This commit is contained in:
1 parent
6b7a1f0306
commit
688a62ec5b
10 files changed
+299
-33
No files matched your search
@@ -483,6 +483,35 @@ bool Reflector::initialize(Async::Config &cfg)
|
||||
// Parse CLUSTER_TGS — comma-separated list of TG numbers broadcast to all peers
|
||||
reloadClusterTgs();
|
||||
|
||||
// Initialize MQTT publisher if [MQTT] section is configured.
|
||||
// Done before the satellite early-return so satellites publish too.
|
||||
std::string mqtt_host;
|
||||
if (cfg.getValue("MQTT", "HOST", mqtt_host))
|
||||
{
|
||||
m_mqtt = new MqttPublisher(cfg);
|
||||
if (!m_mqtt->initialize())
|
||||
{
|
||||
cerr << "*** WARNING: MQTT publisher failed to initialize, continuing without MQTT" << endl;
|
||||
delete m_mqtt;
|
||||
m_mqtt = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set up periodic status publishing
|
||||
unsigned status_interval = 1000;
|
||||
cfg.getValue("MQTT", "STATUS_INTERVAL", status_interval);
|
||||
m_mqtt_status_timer.setTimeout(status_interval);
|
||||
m_mqtt_status_timer.setEnable(true);
|
||||
m_mqtt_status_timer.expired.connect(
|
||||
[this](Async::Timer*)
|
||||
{
|
||||
refreshStatus();
|
||||
m_mqtt->publishFullStatus(m_status);
|
||||
m_mqtt_status_timer.setEnable(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Satellite mode: connect to parent instead of joining the trunk mesh
|
||||
std::string satellite_of;
|
||||
if (cfg.getValue("GLOBAL", "SATELLITE_OF", satellite_of) &&
|
||||
@@ -518,34 +547,6 @@ bool Reflector::initialize(Async::Config &cfg)
|
||||
initTwinServer();
|
||||
initSatelliteServer();
|
||||
|
||||
// Initialize MQTT publisher if [MQTT] section is configured
|
||||
std::string mqtt_host;
|
||||
if (cfg.getValue("MQTT", "HOST", mqtt_host))
|
||||
{
|
||||
m_mqtt = new MqttPublisher(cfg);
|
||||
if (!m_mqtt->initialize())
|
||||
{
|
||||
cerr << "*** WARNING: MQTT publisher failed to initialize, continuing without MQTT" << endl;
|
||||
delete m_mqtt;
|
||||
m_mqtt = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set up periodic status publishing
|
||||
unsigned status_interval = 1000;
|
||||
cfg.getValue("MQTT", "STATUS_INTERVAL", status_interval);
|
||||
m_mqtt_status_timer.setTimeout(status_interval);
|
||||
m_mqtt_status_timer.setEnable(true);
|
||||
m_mqtt_status_timer.expired.connect(
|
||||
[this](Async::Timer*)
|
||||
{
|
||||
refreshStatus();
|
||||
m_mqtt->publishFullStatus(m_status);
|
||||
m_mqtt_status_timer.setEnable(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} /* Reflector::initialize */
|
||||
|
||||
@@ -2961,9 +2962,23 @@ void Reflector::publishRxUpdate(ReflectorClient* client)
|
||||
{
|
||||
m_mqtt->onRxUpdate(client->callsign(), client->rxStatusJson());
|
||||
}
|
||||
publishClientStatus(client);
|
||||
} /* Reflector::publishRxUpdate */
|
||||
|
||||
|
||||
void Reflector::publishClientStatus(ReflectorClient* client)
|
||||
{
|
||||
if (m_redis == nullptr || client == nullptr) return;
|
||||
const std::string& cs = client->callsign();
|
||||
if (cs.empty()) return;
|
||||
if (!m_status["nodes"].isMember(cs)) return;
|
||||
Json::StreamWriterBuilder wb;
|
||||
wb["indentation"] = "";
|
||||
m_redis->pushClientStatus(cs,
|
||||
Json::writeString(wb, m_status["nodes"][cs]));
|
||||
} /* Reflector::publishClientStatus */
|
||||
|
||||
|
||||
void Reflector::onClientAuthenticated(const std::string& callsign,
|
||||
uint32_t tg, const std::string& ip)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user