diff --git a/Conf.cpp b/Conf.cpp index 3693133..ebf2876 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -123,8 +123,8 @@ m_mqttPort(1883), m_mqttKeepalive(60U), m_mqttName("mmdvm"), m_mqttAuthEnabled(false), -m_mqttUser("mqttuser"), -m_mqttPass("mqttpass"), +m_mqttUsername(), +m_mqttPassword(), m_cwIdEnabled(false), m_cwIdTime(10U), m_cwIdCallsign(), @@ -612,13 +612,12 @@ bool CConf::read() m_mqttKeepalive = (unsigned int)::atoi(value); else if (::strcmp(key, "Name") == 0) m_mqttName = value; - else if (::strcmp(key, "Auth") == 0) - m_mqttAuthEnabled = ::atoi(value) == 1; - else if (::strcmp(key, "User") == 0) - m_mqttUser = value; - else if (::strcmp(key, "Pass") == 0) - m_mqttPass = value; - + else if (::strcmp(key, "Auth") == 0) + m_mqttAuthEnabled = ::atoi(value) == 1; + else if (::strcmp(key, "Username") == 0) + m_mqttUsername = value; + else if (::strcmp(key, "Password") == 0) + m_mqttPassword = value; } else if (section == SECTION_CWID) { if (::strcmp(key, "Enable") == 0) m_cwIdEnabled = ::atoi(value) == 1; @@ -1337,14 +1336,14 @@ bool CConf::getMQTTAuthEnabled() const return m_mqttAuthEnabled; } -std::string CConf::getMQTTUser() const +std::string CConf::getMQTTUsername() const { - return m_mqttUser; + return m_mqttUsername; } -std::string CConf::getMQTTPass() const +std::string CConf::getMQTTPassword() const { - return m_mqttPass; + return m_mqttPassword; } bool CConf::getCWIdEnabled() const diff --git a/Conf.h b/Conf.h index 6c4e695..d6186b1 100644 --- a/Conf.h +++ b/Conf.h @@ -58,8 +58,8 @@ public: unsigned int getMQTTKeepalive() const; std::string getMQTTName() const; bool getMQTTAuthEnabled() const; - std::string getMQTTUser() const; - std::string getMQTTPass() const; + std::string getMQTTUsername() const; + std::string getMQTTPassword() const; // The CW ID section bool getCWIdEnabled() const; @@ -412,8 +412,8 @@ private: unsigned int m_mqttKeepalive; std::string m_mqttName; bool m_mqttAuthEnabled; - std::string m_mqttUser; - std::string m_mqttPass; + std::string m_mqttUsername; + std::string m_mqttPassword; bool m_cwIdEnabled; unsigned int m_cwIdTime; diff --git a/MMDVM.ini b/MMDVM.ini index 3a74f6a..81496c7 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -29,8 +29,8 @@ DisplayLevel=1 Host=127.0.0.1 Port=1883 Auth=0 -User=mmdvm -Pass=mmdvm +Username=mmdvm +Password=mmdvm Keepalive=60 Name=mmdvm diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index c16b73a..3b8ae26 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -368,7 +368,7 @@ int CMMDVMHost::run() subscriptions.push_back(std::make_pair("ax25-in", CMMDVMHost::onAX25)); #endif - m_mqtt = new CMQTTConnection(m_conf.getMQTTHost(), m_conf.getMQTTPort(), m_conf.getMQTTName(), m_conf.getMQTTAuthEnabled(), m_conf.getMQTTUser(), m_conf.getMQTTPass(), subscriptions, m_conf.getMQTTKeepalive()); + m_mqtt = new CMQTTConnection(m_conf.getMQTTHost(), m_conf.getMQTTPort(), m_conf.getMQTTName(), m_conf.getMQTTAuthEnabled(), m_conf.getMQTTUsername(), m_conf.getMQTTPassword(), subscriptions, m_conf.getMQTTKeepalive()); ret = m_mqtt->open(); if (!ret) { ::fprintf(stderr, "MMDVMHost: unable to start the MQTT Publisher\n"); diff --git a/MQTTConnection.cpp b/MQTTConnection.cpp index 7a2ca58..41f4789 100644 --- a/MQTTConnection.cpp +++ b/MQTTConnection.cpp @@ -23,13 +23,13 @@ #include -CMQTTConnection::CMQTTConnection(const std::string& host, unsigned short port, const std::string& name, const bool authEnabled, const std::string& user, const std::string& pass, const std::vector>& subs, unsigned int keepalive, MQTT_QOS qos) : +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) : m_host(host), m_port(port), m_name(name), m_authEnabled(authEnabled), -m_user(user), -m_pass(pass), +m_username(username), +m_password(password), m_subs(subs), m_keepalive(keepalive), m_qos(qos), @@ -52,14 +52,14 @@ CMQTTConnection::~CMQTTConnection() bool CMQTTConnection::open() { m_mosq = ::mosquitto_new(m_name.c_str(), true, this); - if (m_mosq == NULL){ + if (m_mosq == NULL) { ::fprintf(stderr, "MQTT Error newing: Out of memory.\n"); return false; } - if (m_authEnabled) { - ::mosquitto_username_pw_set(m_mosq, m_user.c_str(), m_pass.c_str()); - } + if (m_authEnabled) + ::mosquitto_username_pw_set(m_mosq, m_username.c_str(), m_password.c_str()); + ::mosquitto_connect_callback_set(m_mosq, onConnect); ::mosquitto_subscribe_callback_set(m_mosq, onSubscribe); ::mosquitto_message_callback_set(m_mosq, onMessage); diff --git a/MQTTConnection.h b/MQTTConnection.h index 1ae1e15..0e985df 100644 --- a/MQTTConnection.h +++ b/MQTTConnection.h @@ -32,7 +32,7 @@ enum MQTT_QOS { class CMQTTConnection { public: - CMQTTConnection(const std::string& host, unsigned short port, const std::string& name, const bool authEnabled, const std::string& user, const std::string& pass, const std::vector>& subs, unsigned int keepalive, MQTT_QOS qos = MQTT_QOS_EXACTLY_ONCE); + 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 = MQTT_QOS_EXACTLY_ONCE); ~CMQTTConnection(); bool open(); @@ -48,8 +48,8 @@ private: unsigned short m_port; std::string m_name; bool m_authEnabled; - std::string m_user; - std::string m_pass; + std::string m_username; + std::string m_password; std::vector> m_subs; unsigned int m_keepalive; MQTT_QOS m_qos;