Improved code readability

pull/41/head
Hieromon Ikasamo 6 years ago
parent 62ae7adb08
commit 02dc8f292d
  1. 22
      examples/mqttRSSI/mqttRSSI.ino
  2. 22
      examples/mqttRSSI_FS/mqttRSSI_FS.ino

@ -315,8 +315,8 @@ void handleRoot() {
"</body>" "</body>"
"</html>"; "</html>";
WiFiWebServer& server = portal.host(); WiFiWebServer& webServer = portal.host();
server.send(200, "text/html", content); webServer.send(200, "text/html", content);
} }
// Clear channel using ThingSpeak's API. // Clear channel using ThingSpeak's API.
@ -339,11 +339,11 @@ void handleClearChannel() {
Serial.println(" failed"); Serial.println(" failed");
// Returns the redirect response. // Returns the redirect response.
WiFiWebServer& server = portal.host(); WiFiWebServer& webServer = portal.host();
server.sendHeader("Location", String("http://") + server.client().localIP().toString() + String("/")); webServer.sendHeader("Location", String("http://") + webServer.client().localIP().toString() + String("/"));
server.send(302, "text/plain", ""); webServer.send(302, "text/plain", "");
server.client().flush(); webServer.client().flush();
server.client().stop(); webServer.client().stop();
} }
void setup() { void setup() {
@ -387,12 +387,13 @@ void setup() {
} }
} }
WiFiWebServer& server = portal.host(); WiFiWebServer& webServer = portal.host();
server.on("/", handleRoot); webServer.on("/", handleRoot);
server.on(AUX_CLEAR_URI, handleClearChannel); webServer.on(AUX_CLEAR_URI, handleClearChannel);
} }
void loop() { void loop() {
portal.handleClient();
if (updateInterval > 0) { if (updateInterval > 0) {
if (millis() - lastPub > updateInterval) { if (millis() - lastPub > updateInterval) {
if (!mqttClient.connected()) { if (!mqttClient.connected()) {
@ -404,5 +405,4 @@ void loop() {
lastPub = millis(); lastPub = millis();
} }
} }
portal.handleClient();
} }

@ -173,8 +173,8 @@ void handleRoot() {
"</body>" "</body>"
"</html>"; "</html>";
WiFiWebServer& server = portal.host(); WiFiWebServer& webServer = portal.host();
server.send(200, "text/html", content); webServer.send(200, "text/html", content);
} }
// Clear channel using Thingspeak's API. // Clear channel using Thingspeak's API.
@ -198,11 +198,11 @@ void handleClearChannel() {
// Returns the redirect response. The page is reloaded and its contents // Returns the redirect response. The page is reloaded and its contents
// are updated to the state after deletion. // are updated to the state after deletion.
WiFiWebServer& server = portal.host(); WiFiWebServer& webServer = portal.host();
server.sendHeader("Location", String("http://") + server.client().localIP().toString() + String("/")); webServer.sendHeader("Location", String("http://") + webServer.client().localIP().toString() + String("/"));
server.send(302, "text/plain", ""); webServer.send(302, "text/plain", "");
server.client().flush(); webServer.client().flush();
server.client().stop(); webServer.client().stop();
} }
// Load AutoConnectAux JSON from SPIFFS. // Load AutoConnectAux JSON from SPIFFS.
@ -264,12 +264,13 @@ void setup() {
} }
} }
WiFiWebServer& server = portal.host(); WiFiWebServer& webServer = portal.host();
server.on("/", handleRoot); webServer.on("/", handleRoot);
server.on(AUX_MQTTCLEAR, handleClearChannel); webServer.on(AUX_MQTTCLEAR, handleClearChannel);
} }
void loop() { void loop() {
portal.handleClient();
if (updateInterval > 0) { if (updateInterval > 0) {
if (millis() - lastPub > updateInterval) { if (millis() - lastPub > updateInterval) {
if (!mqttClient.connected()) { if (!mqttClient.connected()) {
@ -281,5 +282,4 @@ void loop() {
lastPub = millis(); lastPub = millis();
} }
} }
portal.handleClient();
} }

Loading…
Cancel
Save