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.
63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
#ifndef MQTT_PUBLISHER_INCLUDED
|
|
#define MQTT_PUBLISHER_INCLUDED
|
|
|
|
#include <string>
|
|
#include <cstdint>
|
|
#include <json/json.h>
|
|
|
|
struct mosquitto;
|
|
|
|
namespace Async { class Config; }
|
|
|
|
class MqttPublisher
|
|
{
|
|
public:
|
|
MqttPublisher(Async::Config& cfg);
|
|
~MqttPublisher(void);
|
|
|
|
bool initialize(void);
|
|
void shutdown(void);
|
|
|
|
// Talker events (local clients and trunk peers)
|
|
void onTalkerStart(uint32_t tg, const std::string& callsign, bool is_trunk);
|
|
void onTalkerStop(uint32_t tg, const std::string& callsign, bool is_trunk);
|
|
|
|
// Client events
|
|
void onClientConnected(const std::string& callsign, uint32_t tg,
|
|
const std::string& ip);
|
|
void onClientDisconnected(const std::string& callsign);
|
|
|
|
// Trunk link events
|
|
void onTrunkUp(const std::string& section, const std::string& direction,
|
|
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);
|
|
|
|
private:
|
|
Async::Config& m_cfg;
|
|
struct mosquitto* m_mosq = nullptr;
|
|
std::string m_host;
|
|
uint16_t m_port = 1883;
|
|
std::string m_username;
|
|
std::string m_password;
|
|
std::string m_topic_prefix;
|
|
bool m_tls_enabled = false;
|
|
std::string m_tls_ca_cert;
|
|
std::string m_tls_client_cert;
|
|
std::string m_tls_client_key;
|
|
|
|
void publish(const std::string& topic_suffix, const std::string& payload,
|
|
bool retain = false);
|
|
|
|
MqttPublisher(const MqttPublisher&);
|
|
MqttPublisher& operator=(const MqttPublisher&);
|
|
|
|
}; /* class MqttPublisher */
|
|
|
|
#endif /* MQTT_PUBLISHER_INCLUDED */
|