Skip to content

Commit 1d3bbfb

Browse files
committed
Make debug public and add device name
1 parent 610f6ba commit 1d3bbfb

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/EasyMqtt.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class EasyMqtt : public MqttEntry {
3030
String sSsid = config().getString("wifi.ssid", "");
3131
char ssid[sSsid.length() + 1];
3232
strcpy(ssid, sSsid.c_str());
33+
34+
String name = config().getString("device.name", deviceId);
35+
//WiFi.hostname("WebPool"); // Set the name of the device
3336

3437
String sPass = config().getString("wifi.password", "");
3538
char pass[sPass.length() + 1];
@@ -110,34 +113,23 @@ class EasyMqtt : public MqttEntry {
110113
}
111114
}
112115

113-
void debug(String msg) {
114-
#ifdef DEBUG
115-
Serial.println(msg);
116-
#endif
117-
if(mqttClient.connected()) {
118-
get("system/debug").publish(msg);
119-
}
120-
}
121-
122-
void debug(String key, String value) {
123-
debug(key + " = " + value);
124-
}
125-
126116
public:
127117
EasyMqtt() : MqttEntry("easyMqtt", mqttClient) {
128118
#ifdef DEBUG
129119
Serial.begin(115200);
130120
#endif
131121
deviceId = String(ESP.getChipId());
132122

133-
debug("test");
134123
configEntry = new ConfigEntry(mqttClient, *this);
135124
addChild(configEntry);
136125

137126
get("system").setInterval(30);
138127
get("system")["deviceId"] << [this]() {
139128
return deviceId;
140129
};
130+
get("system")["name"] << [this]() {
131+
return config().getString("device.name", deviceId);
132+
};
141133
get("system")["mem"]["heap"] << []() {
142134
return String(ESP.getFreeHeap());
143135
};
@@ -169,6 +161,19 @@ class EasyMqtt : public MqttEntry {
169161
};
170162
}
171163

164+
void debug(String msg) {
165+
#ifdef DEBUG
166+
Serial.println(msg);
167+
#endif
168+
if(mqttClient.connected()) {
169+
get("system/debug").publish(msg);
170+
}
171+
}
172+
173+
void debug(String key, String value) {
174+
debug(key + " = " + value);
175+
}
176+
172177
ConfigEntry & config() {
173178
return *configEntry;
174179
}

0 commit comments

Comments
 (0)