Skip to content

Commit e06381b

Browse files
author
Bjarne Loft
committed
Fix identation
1 parent 9934066 commit e06381b

File tree

4 files changed

+46
-41
lines changed

4 files changed

+46
-41
lines changed

src/ConfigEntry.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ void ConfigEntry::save() {
3838
File f = SPIFFS.open("/config.cfg", "w");
3939
if (f) {
4040
each([&](Entry* entry) {
41-
if(entry->getTopic() != getTopic()) {
42-
f.print(getKey(entry));
43-
f.print("=");
44-
f.println(entry->getValue());
45-
debug(getKey(entry), entry->getValue());
46-
}
47-
});
41+
if(entry->getTopic() != getTopic()) {
42+
f.print(getKey(entry));
43+
f.print("=");
44+
f.println(entry->getValue());
45+
debug(getKey(entry), entry->getValue());
46+
}
47+
});
4848
f.close();
4949
} else {
5050
debug("Failed to save config");

src/EasyMqtt.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
/**
12-
Handle connections to mqtt
12+
* Handle connections to mqtt
1313
*/
1414
void EasyMqtt::connectWiFi() {
1515
if(WiFi.status() != WL_CONNECTED) {
@@ -59,29 +59,29 @@ void EasyMqtt::connectMqtt() {
5959
debug("Connecting to MQTT");
6060
mqttClient.setClient(wifiClient);
6161
mqttClient.setCallback([&](const char* topic, uint8_t* payload, unsigned int length) {
62-
each([=](Entry* entry){
63-
entry->callback(topic, payload, length);
64-
});
65-
});
62+
each([=](Entry* entry){
63+
entry->callback(topic, payload, length);
64+
});
65+
});
6666

6767
mqttClient.setServer(mqtt_host, mqtt_port);
6868

6969
if (mqttClient.connect(deviceId.c_str(), mqtt_username, mqtt_password), get("$system")["online"].getTopic().c_str(), 1, 1, "OFF") {
7070
debug("Connected to MQTT");
7171

7272
setPublishFunction([&](Entry* entry, String message){
73-
if(mqttClient.connected()) {
74-
mqttClient.publish(entry->getTopic().c_str(), message.c_str(), true);
75-
}
76-
});
73+
if(mqttClient.connected()) {
74+
mqttClient.publish(entry->getTopic().c_str(), message.c_str(), true);
75+
}
76+
});
7777

7878
debug("Topic", getTopic());
7979

8080
each([&](Entry* entry){
81-
if (entry->isOut()) {
81+
if (entry->isOut()) {
8282
mqttClient.subscribe(entry->getTopic().c_str());
83-
}
84-
});
83+
}
84+
});
8585
mqttDelay = 0;
8686
} else {
8787
debug("Connection to MQTT failed, rc", mqttClient.state());
@@ -224,7 +224,7 @@ void EasyMqtt::loop() {
224224
}
225225
webPortal.loop();
226226
each([](Entry* entry){
227-
entry->update();
228-
});
227+
entry->update();
228+
});
229229
}
230230
}

src/Entry.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,27 @@ void Entry::setPublishFunction(std::function<void(Entry*, String)> function) {
5656
}
5757

5858
void Entry::debug(String key, bool value) {
59+
#ifdef DEBUG
5960
debug(key + " = " + (value ? "true" : "false"));
61+
#endif
6062
}
6163

6264
void Entry::debug(String key, int value) {
65+
#ifdef DEBUG
6366
debug(key + " = " + value);
67+
#endif
6468
}
6569

6670
void Entry::debug(String key, String value) {
71+
#ifdef DEBUG
6772
debug(key + " = " + value);
73+
#endif
6874
}
6975

7076
void Entry::debug(String msg) {
7177
#ifdef DEBUG
7278
Serial.println(msg);
7379
#endif
74-
getRoot()->get("$system")["debug"].publish(msg);
7580
}
7681

7782
void Entry::callback(const char* topic, uint8_t* payload, unsigned int length) {

src/WebPortal.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ void WebPortal::setup(Entry& mqttEntry, ConfigEntry& config, NTPClient& ntpClien
2727
webServer->on("/", std::bind(&WebPortal::handleRoot, this));
2828
webServer->on("/save", std::bind(&WebPortal::handleSaveConfig, this));
2929
mqtt->each([&](Entry* entry) {
30-
if(entry->isIn() || entry->isOut()) {
30+
if(entry->isIn() || entry->isOut()) {
3131
webServer->on(getRestPath(entry).c_str(), std::bind(&WebPortal::handleRest, this));
32-
}
33-
});
32+
}
33+
});
3434
webServer->onNotFound(std::bind(&WebPortal::handleNotFound, this));
3535
webServer->begin();
3636
}
3737

3838
void WebPortal::handleRoot() {
39-
if(!auth()) return;
39+
if(!auth()) return;
4040
webServer->send(200, "text/html", "");
4141

4242
webServer->sendContent_P(HTML_MAIN1);
@@ -147,14 +147,14 @@ void WebPortal::handleRest() {
147147
void WebPortal::handleSaveConfig() {
148148
if(!auth()) return;
149149
config->each([&](Entry* entry) {
150-
String name = getName(entry);
151-
name = name.substring(9);
152-
name.replace("/", ".");
153-
entry->setValue(webServer->arg(name.c_str()));
154-
Serial.print(name);
155-
Serial.print(" = ");
156-
Serial.println(webServer->arg(name.c_str()));
157-
});
150+
String name = getName(entry);
151+
name = name.substring(9);
152+
name.replace("/", ".");
153+
entry->setValue(webServer->arg(name.c_str()));
154+
Serial.print(name);
155+
Serial.print(" = ");
156+
Serial.println(webServer->arg(name.c_str()));
157+
});
158158
config->save();
159159
webServer->sendHeader("Location", String("/"), true);
160160
webServer->send(302, "text/plain", "");
@@ -191,11 +191,11 @@ String WebPortal::time(long time) {
191191
}
192192

193193
bool WebPortal::auth() {
194-
char pass[32];
195-
config->getCString("password", "", pass);
196-
if (strlen(pass) > 0 && !webServer->authenticate("admin", pass)) {
197-
webServer->requestAuthentication();
198-
return false;
199-
}
200-
return true;
194+
char pass[32];
195+
config->getCString("password", "", pass);
196+
if (strlen(pass) > 0 && !webServer->authenticate("admin", pass)) {
197+
webServer->requestAuthentication();
198+
return false;
199+
}
200+
return true;
201201
}

0 commit comments

Comments
 (0)