@@ -9,11 +9,12 @@ extern EmbUI embui;
9
9
void EmbUI::connectToMqtt () {
10
10
LOG (println, PSTR (" UI: Connecting to MQTT..." ));
11
11
12
- // String m_pref=param(FPSTR(P_m_pref));
13
- String m_host=param (FPSTR (P_m_host));
14
- String m_port=param (FPSTR (P_m_port));
15
- String m_user=param (FPSTR (P_m_user));
16
- String m_pass=param (FPSTR (P_m_pass));
12
+ m_pref=param (FPSTR (P_m_pref));
13
+ m_host=param (FPSTR (P_m_host));
14
+ m_port=param (FPSTR (P_m_port));
15
+ m_user=param (FPSTR (P_m_user));
16
+ m_pass=param (FPSTR (P_m_pass));
17
+
17
18
IPAddress ip;
18
19
bool isIP = ip.fromString (m_host);
19
20
mqttClient.setCredentials (m_user.c_str (), m_pass.c_str ());
@@ -22,11 +23,13 @@ void EmbUI::connectToMqtt() {
22
23
else
23
24
mqttClient.setServer (m_host.c_str (), m_port.toInt ());
24
25
26
+ mqttClient.setClientId (m_pref.isEmpty () ? mc : m_pref.c_str ());
27
+
25
28
mqttClient.connect ();
26
29
}
27
30
28
31
String EmbUI::id (const String &topic){
29
- String ret = param ( FPSTR (P_m_pref)) ;
32
+ String ret = m_pref ;
30
33
if (ret.isEmpty ()) return topic;
31
34
32
35
ret += ' /' ; ret += topic;
@@ -56,11 +59,11 @@ void EmbUI::mqtt(const String &pref, const String &host, int port, const String
56
59
LOG (println, PSTR (" UI: MQTT host is empty - disabled!" ));
57
60
return ; // выходим если host не задан
58
61
}
59
- String m_pref=param (FPSTR (P_m_pref));
60
- String m_host=param (FPSTR (P_m_host));
61
- String m_port=param (FPSTR (P_m_port));
62
- String m_user=param (FPSTR (P_m_user));
63
- String m_pass=param (FPSTR (P_m_pass));
62
+ m_pref=param (FPSTR (P_m_pref));
63
+ m_host=param (FPSTR (P_m_host));
64
+ m_port=param (FPSTR (P_m_port));
65
+ m_user=param (FPSTR (P_m_user));
66
+ m_pass=param (FPSTR (P_m_pass));
64
67
IPAddress ip;
65
68
bool isIP = ip.fromString (m_host);
66
69
@@ -81,6 +84,7 @@ void EmbUI::mqtt(const String &pref, const String &host, int port, const String
81
84
mqttClient.onUnsubscribe (onMqttUnsubscribe);
82
85
mqttClient.onMessage (onMqttMessage);
83
86
mqttClient.onPublish (onMqttPublish);
87
+ mqttClient.setClientId (m_pref.isEmpty () ? mc : m_pref.c_str ());
84
88
mqttClient.setCredentials (m_user.c_str (), m_pass.c_str ());
85
89
if (isIP)
86
90
mqttClient.setServer (ip, m_port.toInt ());
0 commit comments