Skip to content

Commit 336d5dd

Browse files
committed
Fix config
1 parent be94002 commit 336d5dd

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/ConfigEntry.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ class ConfigEntry : public MqttEntry {
5454
int pos = line.indexOf("=");
5555
String key = line.substring(0, pos);
5656
String value = line.substring(pos+1);
57-
key.replace(".", "/");
58-
get(key).setValue(value);
57+
set(key, value);
5958
}
6059
f.close();
6160
}

src/EasyMqtt.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ class EasyMqtt : public MqttEntry {
2323
*/
2424
void connect() {
2525
if(WiFi.status() != WL_CONNECTED) {
26-
const char* ssid = config().getCString("wifi.ssid", "");
27-
const char* password = config().getCString("wifi.password", "");
26+
String ssid = config().getString("wifi.ssid", "");
27+
String password = config().getString("wifi.password", "");
28+
debug("Connecting to wifi: " + ssid);
2829
WiFi.mode(WIFI_STA);
29-
WiFi.begin(ssid, password);
30+
WiFi.begin(ssid.c_str(), password.c_str());
3031

3132
int timer = 0;
32-
while (WiFi.status() != WL_CONNECTED && timer < 10) {
33+
while ((WiFi.status() != WL_CONNECTED) && timer < 10) {
3334
delay(500);
3435
timer++;
3536
// ToDo: handle timeout, and create AP
@@ -44,22 +45,23 @@ class EasyMqtt : public MqttEntry {
4445
debug("devideId", deviceId);
4546
webPortal.setup(*this);
4647
}
48+
String host = config().getString("mqtt.host", "");
49+
int port = config().getInt("mqtt.port", 1883);
4750
if(mqttClient.state() == MQTT_DISCONNECTED) {
4851
// Setup MQTT
49-
const char* host = config().getCString("mqtt.host", "");
50-
int port = config().getInt("mqtt.port", 1883);
5152
mqttClient.setClient(wifiClient);
5253
mqttClient.setCallback([&](const char* topic, uint8_t* payload, unsigned int length) {
5354
each([=](MqttEntry* entry){
5455
entry->callback(topic, payload, length);
5556
});
5657
});
57-
mqttClient.setServer(host, port);
58+
mqttClient.setServer(host.c_str(), port);
5859
}
5960
if (!mqttClient.connected()) {
60-
const char* username = config().getCString("mqtt.username", "");
61-
const char* password = config().getCString("mqtt.password", "");
62-
if (mqttClient.connect(deviceId.c_str(), username, password)) {
61+
String username = config().getString("mqtt.username", "");
62+
String password = config().getString("mqtt.password", "");
63+
debug("Connecting to MQTT: " + host + " on port " + String(port));
64+
if (mqttClient.connect(deviceId.c_str(), username.c_str(), password.c_str())) {
6365
debug("Connected to MQTT");
6466
debug("Topic", getTopic());
6567
each([&](MqttEntry* entry){
@@ -68,8 +70,8 @@ class EasyMqtt : public MqttEntry {
6870
}
6971
});
7072
} else {
71-
debug("failed, rc", String(mqttClient.state()));
72-
delay(5000);
73+
debug("Connection to MQTT failed, rc", String(mqttClient.state()));
74+
delay(500);
7375
}
7476
}
7577
}

src/MqttEntry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class MqttEntry {
7474
void update() {
7575
if (isIn()) {
7676
unsigned long time = millis();
77-
if (time >= (lastUpdate + (getInterval() * 1000))) {
77+
if (time >= (lastUpdate + (getInterval() * 1000)) || lastUpdate == 0) {
7878
force++;
7979
lastUpdate = time;
8080
String value = inFunction();

0 commit comments

Comments
 (0)