From 9fdef7f95a1ea4e3b742ddcb97c777ddb7df4dd5 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 17 Mar 2025 12:22:07 +0000 Subject: [PATCH] Change the MQTT connection name to be random. --- MQTTConnection.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MQTTConnection.cpp b/MQTTConnection.cpp index 2e7c8c6..f3b993d 100644 --- a/MQTTConnection.cpp +++ b/MQTTConnection.cpp @@ -21,6 +21,7 @@ #include #include #include +#include CMQTTConnection::CMQTTConnection(const std::string& host, unsigned short port, const std::string& name, const bool authEnabled, const std::string& username, const std::string& password, const std::vector>& subs, unsigned int keepalive, MQTT_QOS qos) : @@ -51,7 +52,12 @@ CMQTTConnection::~CMQTTConnection() bool CMQTTConnection::open() { - m_mosq = ::mosquitto_new(nullptr, true, this); + char name[50U]; + ::sprintf(name, "MMDVM.%lld", ::time(nullptr)); + + ::fprintf(stdout, "MMDVMHost (%s) connecting to MQTT as %s\n", m_name.c_str(), name); + + m_mosq = ::mosquitto_new(name, true, this); if (m_mosq == nullptr) { ::fprintf(stderr, "MQTT Error newing: Out of memory.\n"); return false;