diff --git a/README.md b/README.md index cf2085b..046f71b 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,8 @@ automatically. - **HTTP `/status` endpoint** — JSON status with trunk state, active talkers, satellite connections, and static configuration - **MQTT publishing** — real-time event-driven updates (talker, client, - trunk state) to an external MQTT broker, plus configurable periodic - full status dumps + trunk state, receiver signal levels) to an external MQTT broker, plus + configurable periodic full status dumps - SvxLink client nodes are **unmodified** — they connect to their local reflector as normal and are unaware of the trunk diff --git a/docs/MQTT.md b/docs/MQTT.md index 5c27300..6c0ff11 100644 --- a/docs/MQTT.md +++ b/docs/MQTT.md @@ -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 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 | |-------|-----|--------| | `talker/...` | 0 | No | -| `client/...` | 0 | No | +| `client/.../connected` | 0 | No | +| `client/.../disconnected` | 0 | No | +| `client/.../rx` | 0 | No | | `trunk/...` | 0 | No | | `status` | 0 | **Yes** | diff --git a/src/svxlink/reflector/MqttPublisher.cpp b/src/svxlink/reflector/MqttPublisher.cpp index 387e077..343f1a1 100644 --- a/src/svxlink/reflector/MqttPublisher.cpp +++ b/src/svxlink/reflector/MqttPublisher.cpp @@ -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; diff --git a/src/svxlink/reflector/MqttPublisher.h b/src/svxlink/reflector/MqttPublisher.h index 8499374..734a634 100644 --- a/src/svxlink/reflector/MqttPublisher.h +++ b/src/svxlink/reflector/MqttPublisher.h @@ -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); diff --git a/src/svxlink/reflector/Reflector.cpp b/src/svxlink/reflector/Reflector.cpp index bab7dfc..9c71f83 100644 --- a/src/svxlink/reflector/Reflector.cpp +++ b/src/svxlink/reflector/Reflector.cpp @@ -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) { diff --git a/src/svxlink/reflector/Reflector.h b/src/svxlink/reflector/Reflector.h index 15ef8cb..12b5e50 100644 --- a/src/svxlink/reflector/Reflector.h +++ b/src/svxlink/reflector/Reflector.h @@ -254,6 +254,7 @@ class Reflector : public sigc::trackable const std::vector& 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); diff --git a/src/svxlink/reflector/ReflectorClient.cpp b/src/svxlink/reflector/ReflectorClient.cpp index 6896404..b39491b 100644 --- a/src/svxlink/reflector/ReflectorClient.cpp +++ b/src/svxlink/reflector/ReflectorClient.cpp @@ -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 */ diff --git a/src/svxlink/reflector/ReflectorClient.h b/src/svxlink/reflector/ReflectorClient.h index 337c433..e0f819b 100644 --- a/src/svxlink/reflector/ReflectorClient.h +++ b/src/svxlink/reflector/ReflectorClient.h @@ -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);