|
@@ -50,6 +50,7 @@ WebSocketsServer socket = WebSocketsServer(81);
|
50
|
50
|
SimpleUpdater updater;
|
51
|
51
|
unsigned long last_server_handle_time = 0;
|
52
|
52
|
unsigned long last_websocket_update_time = 0;
|
|
53
|
+int wifi_ok = 0;
|
53
|
54
|
|
54
|
55
|
String message_buffer_a;
|
55
|
56
|
String message_buffer_b;
|
|
@@ -259,8 +260,14 @@ void handleRoot() {
|
259
|
260
|
message += F("<title>Gieß-o-mat</title>\n");
|
260
|
261
|
|
261
|
262
|
message += F("<style type='text/css'>\n");
|
|
263
|
+ message += F(".head {\n");
|
|
264
|
+ message += F("text-align: center;\n");
|
|
265
|
+ message += F("}\n");
|
|
266
|
+
|
262
|
267
|
message += F(".container {\n");
|
263
|
268
|
message += F("display: flex;\n");
|
|
269
|
+ message += F("max-width: 1200px;\n");
|
|
270
|
+ message += F("margin: auto;\n");
|
264
|
271
|
message += F("}\n");
|
265
|
272
|
|
266
|
273
|
message += F(".ui {\n");
|
|
@@ -284,8 +291,8 @@ void handleRoot() {
|
284
|
291
|
message += F("width: max-content;\n");
|
285
|
292
|
message += F("border: 1px solid black;\n");
|
286
|
293
|
message += F("border-radius: 50%;\n");
|
287
|
|
- message += F("padding: 2em;\n");
|
288
|
|
- message += F("margin: 1em;\n");
|
|
294
|
+ message += F("padding: 1em;\n");
|
|
295
|
+ message += F("margin: 0.5em;\n");
|
289
|
296
|
message += F("}\n");
|
290
|
297
|
|
291
|
298
|
message += F(".info {\n");
|
|
@@ -299,7 +306,9 @@ void handleRoot() {
|
299
|
306
|
message += F(".log {\n");
|
300
|
307
|
message += F("max-height: 300px;\n");
|
301
|
308
|
message += F("padding: 0 1.0em;\n");
|
302
|
|
- message += F("margin: 1em 0;\n");
|
|
309
|
+ message += F("max-width: 1200px;\n");
|
|
310
|
+ message += F("margin: auto;\n");
|
|
311
|
+ message += F("margin-top: 1.5em;\n");
|
303
|
312
|
message += F("border: 1px dashed black;\n");
|
304
|
313
|
message += F("font-family: monospace;\n");
|
305
|
314
|
message += F("overflow-y: scroll;\n");
|
|
@@ -356,8 +365,8 @@ void handleRoot() {
|
356
|
365
|
message += F("</style>\n");
|
357
|
366
|
|
358
|
367
|
message += F("</head><body>\n");
|
359
|
|
- message += F("<h1>Gieß-o-mat</h1>\n");
|
360
|
|
-
|
|
368
|
+ message += F("<h1 class='head'>Gieß-o-mat</h1>\n");
|
|
369
|
+
|
361
|
370
|
message += F("<div class='container'>\n");
|
362
|
371
|
message += F("<div class='ui'>\n");
|
363
|
372
|
message += F("<pre class='lcd'>\n");
|
|
@@ -509,6 +518,9 @@ void handleRoot() {
|
509
|
518
|
message += F("\n</p><p>\n");
|
510
|
519
|
message += F("MAC: ");
|
511
|
520
|
message += WiFi.macAddress();
|
|
521
|
+ message += F("\n<br>\n");
|
|
522
|
+ message += F("IPv4: ");
|
|
523
|
+ message += WiFi.localIP().toString();
|
512
|
524
|
message += F("\n</p>\n");
|
513
|
525
|
|
514
|
526
|
#if defined(ARDUINO_ARCH_ESP8266)
|
|
@@ -597,7 +609,7 @@ void handleRoot() {
|
597
|
609
|
message += F( "}\n");
|
598
|
610
|
message += F( "var msg = JSON.parse(e.data);\n");
|
599
|
611
|
message += F( "var str = msg.a + '\\n' + msg.b + '\\n' + msg.c + '\\n' + msg.d;\n");
|
600
|
|
- message += F( "console.log(str);\n");
|
|
612
|
+ //message += F( "console.log(str);\n");
|
601
|
613
|
message += F( "var lcd = document.getElementsByClassName('lcd');\n");
|
602
|
614
|
message += F( "lcd[0].innerHTML = str;\n");
|
603
|
615
|
message += F( "var state = document.getElementById('state');\n");
|
|
@@ -696,6 +708,8 @@ void wifi_setup() {
|
696
|
708
|
// Build hostname string
|
697
|
709
|
String hostname = "giess-o-mat";
|
698
|
710
|
|
|
711
|
+ int ws = 0, connect_attempts = 0;
|
|
712
|
+
|
699
|
713
|
#if defined(ARDUINO_ARCH_ESP8266)
|
700
|
714
|
|
701
|
715
|
// Connect to WiFi AP
|
|
@@ -705,12 +719,15 @@ void wifi_setup() {
|
705
|
719
|
|
706
|
720
|
debug.print("WiFi: connecting");
|
707
|
721
|
WiFi.begin(WIFI_SSID, WIFI_PW);
|
708
|
|
- while (WiFi.status() != WL_CONNECTED) {
|
709
|
|
- debug.print(".");
|
|
722
|
+
|
|
723
|
+ while (((ws = WiFi.status()) != WL_CONNECTED) && (connect_attempts < MAX_WIFI_CONNECT_ATTEMPTS)) {
|
|
724
|
+ connect_attempts++;
|
|
725
|
+ debug.print(String(" ") + String(ws));
|
710
|
726
|
delay(LED_CONNECT_BLINK_INTERVAL);
|
711
|
727
|
digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
|
712
|
728
|
}
|
713
|
729
|
debug.println();
|
|
730
|
+ debug.println(String("WiFi: status=") + String(WiFi.status()));
|
714
|
731
|
|
715
|
732
|
#elif defined(ARDUINO_ARCH_ESP32)
|
716
|
733
|
|
|
@@ -736,14 +753,13 @@ void wifi_setup() {
|
736
|
753
|
WiFi.mode(WIFI_STA);
|
737
|
754
|
WiFi.begin(WIFI_SSID, WIFI_PW);
|
738
|
755
|
|
739
|
|
- int ws;
|
740
|
|
- while ((ws = WiFi.status()) != WL_CONNECTED) {
|
|
756
|
+ while (((ws = WiFi.status()) != WL_CONNECTED) && (connect_attempts < MAX_WIFI_CONNECT_ATTEMPTS)) {
|
|
757
|
+ connect_attempts++;
|
741
|
758
|
debug.print(String(" ") + String(ws));
|
742
|
759
|
delay(LED_CONNECT_BLINK_INTERVAL);
|
743
|
760
|
digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
|
744
|
761
|
}
|
745
|
762
|
debug.println();
|
746
|
|
-
|
747
|
763
|
debug.println(String("WiFi: status=") + String(WiFi.status()));
|
748
|
764
|
|
749
|
765
|
// Set hostname workaround
|
|
@@ -752,8 +768,16 @@ void wifi_setup() {
|
752
|
768
|
|
753
|
769
|
#endif
|
754
|
770
|
|
|
771
|
+ if ((connect_attempts >= MAX_WIFI_CONNECT_ATTEMPTS)
|
|
772
|
+ || (WiFi.status() != WL_CONNECTED)) {
|
|
773
|
+ debug.println("WiFi: init failed!");
|
|
774
|
+ wifi_ok = 0;
|
|
775
|
+ return;
|
|
776
|
+ }
|
|
777
|
+ wifi_ok = 1;
|
|
778
|
+
|
755
|
779
|
debug.print("WiFi: got IPv4: ");
|
756
|
|
- debug.println(WiFi.localIP());
|
|
780
|
+ debug.println(WiFi.localIP().toString());
|
757
|
781
|
|
758
|
782
|
#ifdef ENABLE_INFLUXDB_LOGGING
|
759
|
783
|
// Setup InfluxDB Client
|
|
@@ -781,6 +805,16 @@ void wifi_setup() {
|
781
|
805
|
}
|
782
|
806
|
|
783
|
807
|
void wifi_run() {
|
|
808
|
+ // reset ESP every 6h to be safe
|
|
809
|
+ if ((millis() >= (6UL * 60UL * 60UL * 1000UL)) && (sm_is_idle())) {
|
|
810
|
+ ESP.restart();
|
|
811
|
+ }
|
|
812
|
+
|
|
813
|
+ if (!wifi_ok) {
|
|
814
|
+ // nothing to handle
|
|
815
|
+ return;
|
|
816
|
+ }
|
|
817
|
+
|
784
|
818
|
if ((millis() - last_server_handle_time) >= SERVER_HANDLE_INTERVAL) {
|
785
|
819
|
last_server_handle_time = millis();
|
786
|
820
|
server.handleClient();
|
|
@@ -796,11 +830,6 @@ void wifi_run() {
|
796
|
830
|
wifi_send_status_broadcast();
|
797
|
831
|
}
|
798
|
832
|
|
799
|
|
- // reset ESP every 6h to be safe
|
800
|
|
- if ((millis() >= (6UL * 60UL * 60UL * 1000UL)) && (sm_is_idle())) {
|
801
|
|
- ESP.restart();
|
802
|
|
- }
|
803
|
|
-
|
804
|
833
|
#ifdef ENABLE_GPIO_TEST
|
805
|
834
|
if (runningGpioTest && ((millis() - lastGpioTime) >= GPIO_TEST_INTERVAL)) {
|
806
|
835
|
gpioTestState = !gpioTestState;
|