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:
1 parent
4a9cba6edb
commit
a2eefac1f2
8 files changed
+86
-18
No files matched your search
@@ -55,8 +55,8 @@ automatically.
|
|||||||
- **HTTP `/status` endpoint** — JSON status with trunk state,
|
- **HTTP `/status` endpoint** — JSON status with trunk state,
|
||||||
active talkers, satellite connections, and static configuration
|
active talkers, satellite connections, and static configuration
|
||||||
- **MQTT publishing** — real-time event-driven updates (talker, client,
|
- **MQTT publishing** — real-time event-driven updates (talker, client,
|
||||||
trunk state) to an external MQTT broker, plus configurable periodic
|
trunk state, receiver signal levels) to an external MQTT broker, plus
|
||||||
full status dumps
|
configurable periodic full status dumps
|
||||||
- SvxLink client nodes are **unmodified** — they connect to their local
|
- SvxLink client nodes are **unmodified** — they connect to their local
|
||||||
reflector as normal and are unaware of the trunk
|
reflector as normal and are unaware of the trunk
|
||||||
|
|
||||||
|
|||||||
+25
-1
@@ -87,6 +87,28 @@ Disconnected payload:
|
|||||||
{}
|
{}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Receiver (RX) status events
|
||||||
|
|
||||||
|
Published on every signal strength update from a connected node. Each node can
|
||||||
|
have multiple receivers — the payload contains all of them keyed by receiver ID.
|
||||||
|
|
||||||
|
```
|
||||||
|
{TOPIC_PREFIX}/client/{callsign}/rx
|
||||||
|
```
|
||||||
|
|
||||||
|
Payload:
|
||||||
|
```json
|
||||||
|
{"A":{"name":"Rx1","siglev":42,"enabled":true,"sql_open":true,"active":true},"B":{"name":"Rx2","siglev":0,"enabled":true,"sql_open":false,"active":false}}
|
||||||
|
```
|
||||||
|
|
||||||
|
| Field | Type | Description |
|
||||||
|
|-------|------|-------------|
|
||||||
|
| `name` | string | Receiver name from the node's QTH configuration |
|
||||||
|
| `siglev` | integer | Signal level (0–100) |
|
||||||
|
| `enabled` | boolean | Whether the receiver is enabled |
|
||||||
|
| `sql_open` | boolean | Whether the squelch is open |
|
||||||
|
| `active` | boolean | Whether the receiver is actively selected |
|
||||||
|
|
||||||
### Trunk events
|
### Trunk events
|
||||||
|
|
||||||
Published when a trunk link's outbound or inbound connection goes up or down.
|
Published when a trunk link's outbound or inbound connection goes up or down.
|
||||||
@@ -127,7 +149,9 @@ subscribers immediately receive the last known state.
|
|||||||
| Topic | QoS | Retain |
|
| Topic | QoS | Retain |
|
||||||
|-------|-----|--------|
|
|-------|-----|--------|
|
||||||
| `talker/...` | 0 | No |
|
| `talker/...` | 0 | No |
|
||||||
| `client/...` | 0 | No |
|
| `client/.../connected` | 0 | No |
|
||||||
|
| `client/.../disconnected` | 0 | No |
|
||||||
|
| `client/.../rx` | 0 | No |
|
||||||
| `trunk/...` | 0 | No |
|
| `trunk/...` | 0 | No |
|
||||||
| `status` | 0 | **Yes** |
|
| `status` | 0 | **Yes** |
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
void MqttPublisher::publishFullStatus(const Json::Value& status)
|
||||||
{
|
{
|
||||||
Json::StreamWriterBuilder wb;
|
Json::StreamWriterBuilder wb;
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ class MqttPublisher
|
|||||||
const std::string& host, uint16_t port);
|
const std::string& host, uint16_t port);
|
||||||
void onTrunkDown(const std::string& section, const std::string& direction);
|
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
|
// Periodic full status
|
||||||
void publishFullStatus(const Json::Value& status);
|
void publishFullStatus(const Json::Value& status);
|
||||||
|
|
||||||
|
|||||||
@@ -497,6 +497,7 @@ bool Reflector::initialize(Async::Config &cfg)
|
|||||||
m_mqtt_status_timer.expired.connect(
|
m_mqtt_status_timer.expired.connect(
|
||||||
[this](Async::Timer*)
|
[this](Async::Timer*)
|
||||||
{
|
{
|
||||||
|
refreshStatus();
|
||||||
m_mqtt->publishFullStatus(m_status);
|
m_mqtt->publishFullStatus(m_status);
|
||||||
m_mqtt_status_timer.setEnable(true);
|
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->setRxSqlOpen(rx.id(), rx.sqlOpen());
|
||||||
client->setRxActive(rx.id(), rx.active());
|
client->setRxActive(rx.id(), rx.active());
|
||||||
}
|
}
|
||||||
|
publishRxUpdate(client);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1603,7 +1605,26 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
|||||||
return;
|
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);
|
Json::Value trunks(Json::objectValue);
|
||||||
for (auto* link : m_trunk_links)
|
for (auto* link : m_trunk_links)
|
||||||
{
|
{
|
||||||
@@ -1699,20 +1720,7 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
|||||||
m_status["satellite_server"] = sat_srv;
|
m_status["satellite_server"] = sat_srv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} /* Reflector::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::httpClientConnected(Async::HttpServerConnection *con)
|
void Reflector::httpClientConnected(Async::HttpServerConnection *con)
|
||||||
@@ -2579,6 +2587,15 @@ void Reflector::onTrunkTalkerUpdated(uint32_t tg,
|
|||||||
} /* Reflector::onTrunkTalkerUpdated */
|
} /* 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,
|
void Reflector::onClientAuthenticated(const std::string& callsign,
|
||||||
uint32_t tg, const std::string& ip)
|
uint32_t tg, const std::string& ip)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ class Reflector : public sigc::trackable
|
|||||||
const std::vector<uint8_t>& audio);
|
const std::vector<uint8_t>& audio);
|
||||||
void forwardFlushToSatellitesExcept(SatelliteLink* except, uint32_t tg);
|
void forwardFlushToSatellitesExcept(SatelliteLink* except, uint32_t tg);
|
||||||
|
|
||||||
|
void publishRxUpdate(ReflectorClient* client);
|
||||||
void onClientAuthenticated(const std::string& callsign, uint32_t tg,
|
void onClientAuthenticated(const std::string& callsign, uint32_t tg,
|
||||||
const std::string& ip);
|
const std::string& ip);
|
||||||
void onTrunkStateChanged(const std::string& section,
|
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 cfgUpdated(const std::string& section, const std::string& tag);
|
||||||
void onTrunkTalkerUpdated(uint32_t tg, std::string old_cs,
|
void onTrunkTalkerUpdated(uint32_t tg, std::string old_cs,
|
||||||
std::string new_cs);
|
std::string new_cs);
|
||||||
|
void refreshStatus(void);
|
||||||
void initTrunkLinks(void);
|
void initTrunkLinks(void);
|
||||||
void initTrunkServer(void);
|
void initTrunkServer(void);
|
||||||
void trunkClientConnected(Async::FramedTcpConnection* con);
|
void trunkClientConnected(Async::FramedTcpConnection* con);
|
||||||
|
|||||||
@@ -1044,6 +1044,7 @@ void ReflectorClient::handleMsgSignalStrengthValues(std::istream& is)
|
|||||||
setRxSqlOpen(rx.id(), rx.sqlOpen());
|
setRxSqlOpen(rx.id(), rx.sqlOpen());
|
||||||
setRxActive(rx.id(), rx.active());
|
setRxActive(rx.id(), rx.active());
|
||||||
}
|
}
|
||||||
|
m_reflector->publishRxUpdate(this);
|
||||||
} /* ReflectorClient::handleMsgSignalStrengthValues */
|
} /* ReflectorClient::handleMsgSignalStrengthValues */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -463,6 +463,17 @@ class ReflectorClient : public sigc::trackable
|
|||||||
}
|
}
|
||||||
return ids;
|
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)
|
void setRxSiglev(char id, uint8_t siglev)
|
||||||
{
|
{
|
||||||
setRxParam(id, "siglev", siglev);
|
setRxParam(id, "siglev", siglev);
|
||||||
|
|||||||
Reference in new issue
Block a user