@@ -20,6 +20,7 @@ namespace HydroFloat {
2020 pinMode (FACTORY_RESET_PIN, INPUT_PULLUP);
2121 pinMode (WIFI_STATUS_PIN, OUTPUT);
2222 _oled.begin ();
23+ _oled.update (0 , off);
2324 EEPROM.begin (EEPROM_SIZE);
2425 if (digitalRead (FACTORY_RESET_PIN) == LOW)
2526 {
@@ -82,11 +83,11 @@ namespace HydroFloat {
8283 _webSocket.onEvent ([this ](uint8_t num, WStype_t type, uint8_t *payload, size_t length)
8384 {
8485 if (type == WStype_DISCONNECTED) {
85- logi (" [%u] Home Page Disconnected!\n " , num);
86+ logi (" [%u] Home Page Disconnected!" , num);
8687 _networkStatus = APMode;
8788 }
8889 else if (type == WStype_CONNECTED) {
89- logi (" [%u] Home Page Connected!\n " , num);
90+ logi (" [%u] Home Page Connected!" , num);
9091 _lastWaterLevel = -1 ; // force a broadcast
9192 _networkStatus = WSMode;
9293 }
@@ -102,12 +103,14 @@ namespace HydroFloat {
102103 });
103104
104105 _asyncServer.onNotFound ([this ](AsyncWebServerRequest *request) {
105- logd (" Not found: %s" , request->url ().c_str ());
106- String page = redirect_html;
107- page.replace (" {n}" , _SSID);
108- IPAddress IP = WiFi.softAPIP ();
109- page.replace (" {ip}" , IP.toString ().c_str ());
110- request->send (200 , " text/html" , page);
106+ if (APMode == _networkStatus) {
107+ logd (" Redirecting from: %s" , request->url ().c_str ());
108+ String page = redirect_html;
109+ page.replace (" {n}" , _SSID);
110+ IPAddress IP = WiFi.softAPIP ();
111+ page.replace (" {ip}" , IP.toString ().c_str ());
112+ request->send (200 , " text/html" , page);
113+ }
111114 });
112115
113116 _asyncServer.on (" /settings" , HTTP_GET, [this ](AsyncWebServerRequest *request) {
@@ -215,7 +218,7 @@ namespace HydroFloat {
215218 serializeJson (doc, s);
216219 _webSocket.broadcastTXT (s);
217220 _oled.update (waterLevel, s4 ? overflow : s3 ? slag : s2 ? slead : s1 ? stop : off);
218- logd (" Water Level: %f JSON: %s" , waterLevel , s.c_str ());
221+ logd (" broadcast JSON: %s" , s.c_str ());
219222 }
220223 _webSocket.loop ();
221224 _dnsServer.processNextRequest ();
0 commit comments