|
@@ -71,20 +71,23 @@ enum telegram_state {
|
71
|
71
|
|
72
|
72
|
enum telegram_state bot_state = BOT_IDLE;
|
73
|
73
|
String bot_lock = "";
|
74
|
|
-BoolField bot_plants(VALVE_COUNT - 1);
|
75
|
|
-BoolField bot_ferts(PUMP_COUNT);
|
76
|
74
|
|
77
|
75
|
#endif // TELEGRAM_TOKEN
|
78
|
76
|
|
79
|
77
|
#ifdef MQTT_HOST
|
|
78
|
+
|
80
|
79
|
#include <PubSubClient.h>
|
81
|
80
|
WiFiClient mqttClient;
|
82
|
81
|
PubSubClient mqtt(mqttClient);
|
83
|
82
|
unsigned long last_mqtt_reconnect_time = 0;
|
84
|
|
-BoolField mqtt_plants(VALVE_COUNT - 1);
|
85
|
|
-BoolField mqtt_ferts(PUMP_COUNT);
|
|
83
|
+
|
86
|
84
|
#endif // MQTT_HOST
|
87
|
85
|
|
|
86
|
+#if defined(TELEGRAM_TOKEN) || defined(MQTT_HOST)
|
|
87
|
+static BoolField bot_plants(VALVE_COUNT - 1);
|
|
88
|
+static BoolField bot_ferts(PUMP_COUNT);
|
|
89
|
+#endif // TELEGRAM_TOKEN || MQTT_HOST
|
|
90
|
+
|
88
|
91
|
UPDATE_WEB_SERVER server(80);
|
89
|
92
|
WebSocketsServer socket = WebSocketsServer(81);
|
90
|
93
|
SimpleUpdater updater;
|
|
@@ -112,12 +115,12 @@ Influxdb influx(INFLUXDB_HOST, INFLUXDB_PORT);
|
112
|
115
|
|
113
|
116
|
void runGpioTest(bool state) {
|
114
|
117
|
lastGpioTime = millis();
|
115
|
|
-
|
|
118
|
+
|
116
|
119
|
for (int i = 0; i < VALVE_COUNT; i++) {
|
117
|
120
|
get_plants()->getValves()->setPin(i, state);
|
118
|
121
|
delay(GPIO_TEST_DELAY);
|
119
|
122
|
}
|
120
|
|
-
|
|
123
|
+
|
121
|
124
|
for (int i = 0; i < PUMP_COUNT; i++) {
|
122
|
125
|
get_plants()->getPumps()->setPin(i, state);
|
123
|
126
|
if (i < (PUMP_COUNT - 1)) {
|
|
@@ -129,12 +132,12 @@ void runGpioTest(bool state) {
|
129
|
132
|
void handleGpioTest() {
|
130
|
133
|
runningGpioTest = !runningGpioTest;
|
131
|
134
|
gpioTestState = runningGpioTest;
|
132
|
|
-
|
|
135
|
+
|
133
|
136
|
String message = F("GPIOs turned ");
|
134
|
137
|
message += runningGpioTest ? "on" : "off";
|
135
|
138
|
|
136
|
139
|
server.send(200, "text/html", message);
|
137
|
|
-
|
|
140
|
+
|
138
|
141
|
runGpioTest(gpioTestState);
|
139
|
142
|
}
|
140
|
143
|
|
|
@@ -148,7 +151,8 @@ void wifi_broadcast_state_change(const char *s) {
|
148
|
151
|
#endif // TELEGRAM_TOKEN
|
149
|
152
|
|
150
|
153
|
#ifdef MQTT_HOST
|
151
|
|
- mqtt.publish("giessomat", s);
|
|
154
|
+ String payload = String("state: ") + s;
|
|
155
|
+ mqtt.publish("giessomat", payload.c_str());
|
152
|
156
|
#endif // MQTT_HOST
|
153
|
157
|
}
|
154
|
158
|
|
|
@@ -390,13 +394,22 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
390
|
394
|
debug.println("MQTT: user abort");
|
391
|
395
|
}
|
392
|
396
|
} else {
|
|
397
|
+ if (ps.substring(0, 6) == "state:") {
|
|
398
|
+ return;
|
|
399
|
+ }
|
|
400
|
+
|
393
|
401
|
if (ps.substring(0, 4) != "auto") {
|
394
|
402
|
debug.println("MQTT: invalid payload");
|
395
|
403
|
return;
|
396
|
404
|
}
|
397
|
405
|
|
398
|
|
- mqtt_ferts.clear();
|
399
|
|
- mqtt_plants.clear();
|
|
406
|
+ if (!sm_is_idle()) {
|
|
407
|
+ debug.println("MQTT: machine is in use");
|
|
408
|
+ return;
|
|
409
|
+ }
|
|
410
|
+
|
|
411
|
+ bot_ferts.clear();
|
|
412
|
+ bot_plants.clear();
|
400
|
413
|
|
401
|
414
|
String buff;
|
402
|
415
|
bool at_plants = false;
|
|
@@ -405,9 +418,9 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
405
|
418
|
if (buff != "none") {
|
406
|
419
|
int n = buff.toInt() - 1;
|
407
|
420
|
if (!at_plants) {
|
408
|
|
- mqtt_ferts.set(n);
|
|
421
|
+ bot_ferts.set(n);
|
409
|
422
|
} else {
|
410
|
|
- mqtt_plants.set(n);
|
|
423
|
+ bot_plants.set(n);
|
411
|
424
|
}
|
412
|
425
|
}
|
413
|
426
|
buff = "";
|
|
@@ -422,7 +435,7 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
422
|
435
|
|
423
|
436
|
String s = "MQTT: fertilizers:";
|
424
|
437
|
for (int i = 0; i < PUMP_COUNT; i++) {
|
425
|
|
- if (mqtt_ferts.isSet(i)) {
|
|
438
|
+ if (bot_ferts.isSet(i)) {
|
426
|
439
|
s += " " + String(i + 1);
|
427
|
440
|
}
|
428
|
441
|
}
|
|
@@ -430,25 +443,25 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
430
|
443
|
|
431
|
444
|
s = "MQTT: plants:";
|
432
|
445
|
for (int i = 0; i < (VALVE_COUNT - 1); i++) {
|
433
|
|
- if (mqtt_plants.isSet(i)) {
|
|
446
|
+ if (bot_plants.isSet(i)) {
|
434
|
447
|
s += " " + String(i + 1);
|
435
|
448
|
}
|
436
|
449
|
}
|
437
|
450
|
debug.println(s);
|
438
|
451
|
|
439
|
|
- if (mqtt_plants.countSet() <= 0) {
|
|
452
|
+ if (bot_plants.countSet() <= 0) {
|
440
|
453
|
debug.println("MQTT: no plants selected");
|
441
|
454
|
return;
|
442
|
455
|
}
|
443
|
456
|
|
444
|
457
|
#ifdef FULLAUTO_MIN_PLANT_COUNT
|
445
|
|
- if (mqtt_plants.countSet() < FULLAUTO_MIN_PLANT_COUNT) {
|
|
458
|
+ if (bot_plants.countSet() < FULLAUTO_MIN_PLANT_COUNT) {
|
446
|
459
|
debug.println("MQTT: not enough plants selected");
|
447
|
460
|
return;
|
448
|
461
|
}
|
449
|
462
|
#endif
|
450
|
463
|
|
451
|
|
- sm_bot_start_auto(mqtt_ferts, mqtt_plants);
|
|
464
|
+ sm_bot_start_auto(bot_ferts, bot_plants);
|
452
|
465
|
}
|
453
|
466
|
}
|
454
|
467
|
|
|
@@ -521,60 +534,60 @@ void wifi_send_status_broadcast(void) {
|
521
|
534
|
if (socket.connectedClients() <= 0) {
|
522
|
535
|
return;
|
523
|
536
|
}
|
524
|
|
-
|
|
537
|
+
|
525
|
538
|
String a = message_buffer_a ;
|
526
|
539
|
String b = message_buffer_b;
|
527
|
540
|
String c = message_buffer_c;
|
528
|
541
|
String d = message_buffer_d;
|
529
|
|
-
|
|
542
|
+
|
530
|
543
|
a.replace("\"", "'");
|
531
|
544
|
b.replace("\"", "'");
|
532
|
545
|
c.replace("\"", "'");
|
533
|
546
|
d.replace("\"", "'");
|
534
|
|
-
|
|
547
|
+
|
535
|
548
|
String ws = "{\n";
|
536
|
|
-
|
|
549
|
+
|
537
|
550
|
ws += "\"a\": \"" + a + "\",\n";
|
538
|
551
|
ws += "\"b\": \"" + b + "\",\n";
|
539
|
552
|
ws += "\"c\": \"" + c + "\",\n";
|
540
|
553
|
ws += "\"d\": \"" + d + "\",\n";
|
541
|
|
-
|
|
554
|
+
|
542
|
555
|
ws += "\"state\": \"" + String(control_state_name()) + "\",\n";
|
543
|
|
-
|
|
556
|
+
|
544
|
557
|
ws += F("\"valves\": [ ");
|
545
|
558
|
for (int i = 0; i < VALVE_COUNT; i++) {
|
546
|
559
|
ws += "\"";
|
547
|
560
|
ws += get_plants()->getValves()->getPin(i) ? "1" : "0";
|
548
|
561
|
ws += "\"";
|
549
|
|
-
|
|
562
|
+
|
550
|
563
|
if (i < (VALVE_COUNT - 1)) {
|
551
|
564
|
ws += ", ";
|
552
|
565
|
}
|
553
|
566
|
}
|
554
|
567
|
ws += " ],\n";
|
555
|
|
-
|
|
568
|
+
|
556
|
569
|
ws += F("\"pumps\": [ ");
|
557
|
570
|
for (int i = 0; i < PUMP_COUNT; i++) {
|
558
|
571
|
ws += "\"";
|
559
|
572
|
ws += get_plants()->getPumps()->getPin(i) ? "1" : "0";
|
560
|
573
|
ws += "\"";
|
561
|
|
-
|
|
574
|
+
|
562
|
575
|
if (i < (PUMP_COUNT - 1)) {
|
563
|
576
|
ws += ", ";
|
564
|
577
|
}
|
565
|
578
|
}
|
566
|
579
|
ws += " ],\n";
|
567
|
|
-
|
|
580
|
+
|
568
|
581
|
ws += F("\"switches\": [ ");
|
569
|
582
|
for (int i = 0; i < SWITCH_COUNT; i++) {
|
570
|
583
|
bool v = get_plants()->getSwitches()->getPin(i);
|
571
|
|
-
|
|
584
|
+
|
572
|
585
|
#ifdef INVERT_SENSOR_BOTTOM
|
573
|
586
|
if (i == 0) {
|
574
|
587
|
v = !v;
|
575
|
588
|
}
|
576
|
589
|
#endif // INVERT_SENSOR_BOTTOM
|
577
|
|
-
|
|
590
|
+
|
578
|
591
|
#ifdef INVERT_SENSOR_TOP
|
579
|
592
|
if (i == 1) {
|
580
|
593
|
v = !v;
|
|
@@ -584,7 +597,7 @@ void wifi_send_status_broadcast(void) {
|
584
|
597
|
ws += "\"";
|
585
|
598
|
ws += v ? "1" : "0";
|
586
|
599
|
ws += "\"";
|
587
|
|
-
|
|
600
|
+
|
588
|
601
|
if (i < (SWITCH_COUNT - 1)) {
|
589
|
602
|
ws += ", ";
|
590
|
603
|
}
|
|
@@ -614,7 +627,7 @@ void wifi_send_status_broadcast(void) {
|
614
|
627
|
}
|
615
|
628
|
}
|
616
|
629
|
ws += " ],\n";
|
617
|
|
-
|
|
630
|
+
|
618
|
631
|
ws += "\"switchstate\": \"";
|
619
|
632
|
Plants::Waterlevel wl = get_plants()->getWaterlevel();
|
620
|
633
|
if (wl == Plants::empty) {
|
|
@@ -628,7 +641,7 @@ void wifi_send_status_broadcast(void) {
|
628
|
641
|
}
|
629
|
642
|
ws += "\"\n";
|
630
|
643
|
ws += "}";
|
631
|
|
-
|
|
644
|
+
|
632
|
645
|
wifi_send_websocket(ws);
|
633
|
646
|
}
|
634
|
647
|
|
|
@@ -636,13 +649,72 @@ void wifi_send_websocket(String s) {
|
636
|
649
|
socket.broadcastTXT(s);
|
637
|
650
|
}
|
638
|
651
|
|
|
652
|
+#ifdef ARDUINO_ARCH_ESP32
|
|
653
|
+
|
|
654
|
+#include <rom/rtc.h>
|
|
655
|
+
|
|
656
|
+// https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/ResetReason/ResetReason.ino
|
|
657
|
+static const char *str_reset_reason(int reason) {
|
|
658
|
+ switch (reason) {
|
|
659
|
+ case 1:
|
|
660
|
+ return "POWERON_RESET";
|
|
661
|
+
|
|
662
|
+ case 3:
|
|
663
|
+ return "SW_RESET";
|
|
664
|
+
|
|
665
|
+ case 4:
|
|
666
|
+ return "OWDT_RESET";
|
|
667
|
+
|
|
668
|
+ case 5:
|
|
669
|
+ return "DEEPSLEEP_RESET";
|
|
670
|
+
|
|
671
|
+ case 6:
|
|
672
|
+ return "SDIO_RESET";
|
|
673
|
+
|
|
674
|
+ case 7:
|
|
675
|
+ return "TG0WDT_SYS_RESET";
|
|
676
|
+
|
|
677
|
+ case 8:
|
|
678
|
+ return "TG1WDT_SYS_RESET";
|
|
679
|
+
|
|
680
|
+ case 9:
|
|
681
|
+ return "RTCWDT_SYS_RESET";
|
|
682
|
+
|
|
683
|
+ case 10:
|
|
684
|
+ return "INTRUSION_RESET";
|
|
685
|
+
|
|
686
|
+ case 11:
|
|
687
|
+ return "TGWDT_CPU_RESET";
|
|
688
|
+
|
|
689
|
+ case 12:
|
|
690
|
+ return "SW_CPU_RESET";
|
|
691
|
+
|
|
692
|
+ case 13:
|
|
693
|
+ return "RTCWDT_CPU_RESET";
|
|
694
|
+
|
|
695
|
+ case 14:
|
|
696
|
+ return "EXT_CPU_RESET";
|
|
697
|
+
|
|
698
|
+ case 15:
|
|
699
|
+ return "RTCWDT_BROWN_OUT_RESET";
|
|
700
|
+
|
|
701
|
+ case 16:
|
|
702
|
+ return "RTCWDT_RTC_RESET";
|
|
703
|
+
|
|
704
|
+ default:
|
|
705
|
+ return "NO_MEAN";
|
|
706
|
+ }
|
|
707
|
+}
|
|
708
|
+
|
|
709
|
+#endif // ARDUINO_ARCH_ESP32
|
|
710
|
+
|
639
|
711
|
void handleRoot() {
|
640
|
712
|
String message = F("<!DOCTYPE html>\n");
|
641
|
713
|
message += F("<html><head>\n");
|
642
|
714
|
message += F("<meta charset='utf-8'/>\n");
|
643
|
715
|
message += F("<meta name='viewport' content='width=device-width, initial-scale=1'/>\n");
|
644
|
716
|
message += F("<title>Gieß-o-mat</title>\n");
|
645
|
|
-
|
|
717
|
+
|
646
|
718
|
message += F("<style type='text/css'>\n");
|
647
|
719
|
message += F(".head {\n");
|
648
|
720
|
message += F("text-align: center;\n");
|
|
@@ -653,7 +725,7 @@ void handleRoot() {
|
653
|
725
|
message += F("max-width: 1200px;\n");
|
654
|
726
|
message += F("margin: auto;\n");
|
655
|
727
|
message += F("}\n");
|
656
|
|
-
|
|
728
|
+
|
657
|
729
|
message += F(".ui {\n");
|
658
|
730
|
message += F("width: max-content;\n");
|
659
|
731
|
message += F("height: max-content;\n");
|
|
@@ -661,7 +733,7 @@ void handleRoot() {
|
661
|
733
|
message += F("padding: 0 1.0em;\n");
|
662
|
734
|
message += F("border: 1px dashed black;\n");
|
663
|
735
|
message += F("}\n");
|
664
|
|
-
|
|
736
|
+
|
665
|
737
|
message += F(".io {\n");
|
666
|
738
|
message += F("width: max-content;\n");
|
667
|
739
|
message += F("height: max-content;\n");
|
|
@@ -670,7 +742,7 @@ void handleRoot() {
|
670
|
742
|
message += F("border: 1px dashed black;\n");
|
671
|
743
|
message += F("font-family: monospace;\n");
|
672
|
744
|
message += F("}\n");
|
673
|
|
-
|
|
745
|
+
|
674
|
746
|
message += F(".ioelem {\n");
|
675
|
747
|
message += F("width: max-content;\n");
|
676
|
748
|
message += F("border: 1px solid black;\n");
|
|
@@ -678,7 +750,7 @@ void handleRoot() {
|
678
|
750
|
message += F("padding: 1em;\n");
|
679
|
751
|
message += F("margin: 0.5em;\n");
|
680
|
752
|
message += F("}\n");
|
681
|
|
-
|
|
753
|
+
|
682
|
754
|
message += F(".info {\n");
|
683
|
755
|
message += F("width: max-content;\n");
|
684
|
756
|
message += F("height: max-content;\n");
|
|
@@ -686,7 +758,7 @@ void handleRoot() {
|
686
|
758
|
message += F("border: 1px dashed black;\n");
|
687
|
759
|
message += F("font-family: monospace;\n");
|
688
|
760
|
message += F("}\n");
|
689
|
|
-
|
|
761
|
+
|
690
|
762
|
message += F(".log {\n");
|
691
|
763
|
message += F("max-height: 300px;\n");
|
692
|
764
|
message += F("padding: 0 1.0em;\n");
|
|
@@ -698,11 +770,11 @@ void handleRoot() {
|
698
|
770
|
message += F("overflow-y: scroll;\n");
|
699
|
771
|
message += F("word-break: break-all;\n");
|
700
|
772
|
message += F("}\n");
|
701
|
|
-
|
|
773
|
+
|
702
|
774
|
message += F("#logbuf {\n");
|
703
|
775
|
message += F("white-space: break-spaces;\n");
|
704
|
776
|
message += F("}\n");
|
705
|
|
-
|
|
777
|
+
|
706
|
778
|
message += F(".pad {\n");
|
707
|
779
|
message += F("background: black;\n");
|
708
|
780
|
message += F("border: 3px solid black;\n");
|
|
@@ -712,7 +784,7 @@ void handleRoot() {
|
712
|
784
|
message += F("margin-left: auto;\n");
|
713
|
785
|
message += F("margin-right: auto;\n");
|
714
|
786
|
message += F("}\n");
|
715
|
|
-
|
|
787
|
+
|
716
|
788
|
message += F(".pad input {\n");
|
717
|
789
|
message += F("background: #fff0cf;\n");
|
718
|
790
|
message += F("border-radius: 6px;\n");
|
|
@@ -722,7 +794,7 @@ void handleRoot() {
|
722
|
794
|
message += F("padding: 0.5em 1em;\n");
|
723
|
795
|
message += F("margin: 0.5em;\n");
|
724
|
796
|
message += F("}\n");
|
725
|
|
-
|
|
797
|
+
|
726
|
798
|
// https://codepen.io/hawkz/pres/RpPaGK
|
727
|
799
|
message += F(".lcd {\n");
|
728
|
800
|
//message += F("background: #9ea18c;\n");
|
|
@@ -742,7 +814,7 @@ void handleRoot() {
|
742
|
814
|
message += F("margin-left: auto;\n");
|
743
|
815
|
message += F("margin-right: auto;\n");
|
744
|
816
|
message += F("}\n");
|
745
|
|
-
|
|
817
|
+
|
746
|
818
|
message += F("#state {\n");
|
747
|
819
|
message += F("text-align: center;\n");
|
748
|
820
|
message += F("}\n");
|
|
@@ -788,7 +860,7 @@ void handleRoot() {
|
788
|
860
|
message += message_buffer_c + '\n';
|
789
|
861
|
message += message_buffer_d + '\n';
|
790
|
862
|
message += F("</pre>\n");
|
791
|
|
-
|
|
863
|
+
|
792
|
864
|
message += F("<form class='pad'>\n");
|
793
|
865
|
message += F("<input type='button' value='1'>");
|
794
|
866
|
message += F("<input type='button' value='2'>");
|
|
@@ -806,15 +878,15 @@ void handleRoot() {
|
806
|
878
|
message += F("<input type='button' value='0'>");
|
807
|
879
|
message += F("<input type='button' value='#'>");
|
808
|
880
|
message += F("</form>\n");
|
809
|
|
-
|
|
881
|
+
|
810
|
882
|
message += F("<p id='state'>\n");
|
811
|
883
|
message += F("State: ");
|
812
|
884
|
message += control_state_name();
|
813
|
885
|
message += F("</p></div>\n");
|
814
|
|
-
|
|
886
|
+
|
815
|
887
|
message += F("<div class='io'>\n");
|
816
|
888
|
message += F("Switches: <span id='switchstate'>");
|
817
|
|
-
|
|
889
|
+
|
818
|
890
|
Plants::Waterlevel wl = get_plants()->getWaterlevel();
|
819
|
891
|
if (wl == Plants::empty) {
|
820
|
892
|
message += F("tank empty");
|
|
@@ -826,24 +898,24 @@ void handleRoot() {
|
826
|
898
|
message += F("invalid sensor state");
|
827
|
899
|
}
|
828
|
900
|
message += F("</span>");
|
829
|
|
-
|
|
901
|
+
|
830
|
902
|
message += F("<div class='container'>\n");
|
831
|
903
|
for (int i = 0; i < SWITCH_COUNT; i++) {
|
832
|
904
|
message += F("<div class='ioelem switch' style='background-color: ");
|
833
|
905
|
bool v = get_plants()->getSwitches()->getPin(i);
|
834
|
|
-
|
|
906
|
+
|
835
|
907
|
#ifdef INVERT_SENSOR_BOTTOM
|
836
|
908
|
if (i == 0) {
|
837
|
909
|
v = !v;
|
838
|
910
|
}
|
839
|
911
|
#endif // INVERT_SENSOR_BOTTOM
|
840
|
|
-
|
|
912
|
+
|
841
|
913
|
#ifdef INVERT_SENSOR_TOP
|
842
|
914
|
if (i == 1) {
|
843
|
915
|
v = !v;
|
844
|
916
|
}
|
845
|
917
|
#endif // INVERT_SENSOR_TOP
|
846
|
|
-
|
|
918
|
+
|
847
|
919
|
if (v) {
|
848
|
920
|
message += F("red");
|
849
|
921
|
} else {
|
|
@@ -869,7 +941,7 @@ void handleRoot() {
|
869
|
941
|
message += F("</div>");
|
870
|
942
|
}
|
871
|
943
|
message += F("</div><hr>\n");
|
872
|
|
-
|
|
944
|
+
|
873
|
945
|
message += F("Valves:\n");
|
874
|
946
|
message += F("<div class='container'>\n");
|
875
|
947
|
for (int i = 0; i < VALVE_COUNT; i++) {
|
|
@@ -884,7 +956,7 @@ void handleRoot() {
|
884
|
956
|
message += F("</div>");
|
885
|
957
|
}
|
886
|
958
|
message += F("</div><hr>\n");
|
887
|
|
-
|
|
959
|
+
|
888
|
960
|
message += F("Pumps:\n");
|
889
|
961
|
message += F("<div class='container'>\n");
|
890
|
962
|
for (int i = 0; i < PUMP_COUNT; i++) {
|
|
@@ -918,7 +990,7 @@ void handleRoot() {
|
918
|
990
|
message += F("Green means valve is closed / pump is off / switch is not submersed.\n");
|
919
|
991
|
message += F("<br>\n");
|
920
|
992
|
message += F("Red means valve is open / pump is running / switch is submersed.</div>\n");
|
921
|
|
-
|
|
993
|
+
|
922
|
994
|
message += F("<div class='info'><p>\n");
|
923
|
995
|
message += F("Version: ");
|
924
|
996
|
message += FIRMWARE_VERSION;
|
|
@@ -937,7 +1009,7 @@ void handleRoot() {
|
937
|
1009
|
message += F("\n</p>\n");
|
938
|
1010
|
|
939
|
1011
|
#if defined(ARDUINO_ARCH_ESP8266)
|
940
|
|
-
|
|
1012
|
+
|
941
|
1013
|
message += F("\n<p>\n");
|
942
|
1014
|
message += F("Reset reason: ");
|
943
|
1015
|
message += ESP.getResetReason();
|
|
@@ -960,12 +1032,17 @@ void handleRoot() {
|
960
|
1032
|
message += (ESP.getFlashChipSize());
|
961
|
1033
|
message += F(") does not match!");
|
962
|
1034
|
}
|
963
|
|
-
|
|
1035
|
+
|
964
|
1036
|
message += F("\n</p>\n");
|
965
|
|
-
|
|
1037
|
+
|
966
|
1038
|
#elif defined(ARDUINO_ARCH_ESP32)
|
967
|
1039
|
|
968
|
1040
|
message += F("\n<p>\n");
|
|
1041
|
+ message += F("Reset reason: ");
|
|
1042
|
+ message += str_reset_reason(rtc_get_reset_reason(0));
|
|
1043
|
+ message += F(" ");
|
|
1044
|
+ message += str_reset_reason(rtc_get_reset_reason(1));
|
|
1045
|
+ message += F("\n<br>\n");
|
969
|
1046
|
message += F("Free heap: ");
|
970
|
1047
|
message += String(ESP.getFreeHeap() / 1024.0);
|
971
|
1048
|
message += F("k\n<br>\n");
|
|
@@ -975,7 +1052,7 @@ void handleRoot() {
|
975
|
1052
|
message += F("Flash chip size: ");
|
976
|
1053
|
message += String(ESP.getFlashChipSize() / 1024.0);
|
977
|
1054
|
message += F("k\n</p>\n");
|
978
|
|
-
|
|
1055
|
+
|
979
|
1056
|
#endif
|
980
|
1057
|
|
981
|
1058
|
message += F("<p>\n");
|
|
@@ -1019,18 +1096,18 @@ void handleRoot() {
|
1019
|
1096
|
message += F("<p>Try <a href='/update'>/update</a> for OTA firmware updates!</p>\n");
|
1020
|
1097
|
message += F("<p>Made by <a href='https://xythobuz.de'>xythobuz</a></p>\n");
|
1021
|
1098
|
message += F("<p><a href='https://git.xythobuz.de/thomas/giess-o-mat'>Project Repository</a></p>\n");
|
1022
|
|
-
|
|
1099
|
+
|
1023
|
1100
|
#ifdef ENABLE_GPIO_TEST
|
1024
|
1101
|
message += F("<p><a href='/gpiotest'>GPIO Test</a></p>\n");
|
1025
|
1102
|
#endif // ENABLE_GPIO_TEST
|
1026
|
|
-
|
|
1103
|
+
|
1027
|
1104
|
message += F("</div></div>\n");
|
1028
|
|
-
|
|
1105
|
+
|
1029
|
1106
|
message += F("<div class='log'><pre id='logbuf'>\n");
|
1030
|
1107
|
message += debug.getBuffer();
|
1031
|
1108
|
message += F("</pre></div>\n");
|
1032
|
1109
|
message += F("</body>\n");
|
1033
|
|
-
|
|
1110
|
+
|
1034
|
1111
|
message += F("<script type='text/javascript'>\n");
|
1035
|
1112
|
message += F("var socket = new WebSocket('ws://' + window.location.hostname + ':81');\n");
|
1036
|
1113
|
message += F("socket.onmessage = function(e) {\n");
|
|
@@ -1051,7 +1128,7 @@ void handleRoot() {
|
1051
|
1128
|
message += F( "lcd[0].innerHTML = str;\n");
|
1052
|
1129
|
message += F( "var state = document.getElementById('state');\n");
|
1053
|
1130
|
message += F( "state.innerHTML = \"State: \" + msg.state;\n");
|
1054
|
|
-
|
|
1131
|
+
|
1055
|
1132
|
message += F( "for (let i = 0; i < ");
|
1056
|
1133
|
message += String(VALVE_COUNT);
|
1057
|
1134
|
message += F("; i++) {\n");
|
|
@@ -1062,7 +1139,7 @@ void handleRoot() {
|
1062
|
1139
|
message += F( "valves[i].style = 'background-color: red;';\n");
|
1063
|
1140
|
message += F( "}\n");
|
1064
|
1141
|
message += F( "}\n");
|
1065
|
|
-
|
|
1142
|
+
|
1066
|
1143
|
message += F( "for (let i = 0; i < ");
|
1067
|
1144
|
message += String(PUMP_COUNT);
|
1068
|
1145
|
message += F("; i++) {\n");
|
|
@@ -1073,7 +1150,7 @@ void handleRoot() {
|
1073
|
1150
|
message += F( "pumps[i].style = 'background-color: red;';\n");
|
1074
|
1151
|
message += F( "}\n");
|
1075
|
1152
|
message += F( "}\n");
|
1076
|
|
-
|
|
1153
|
+
|
1077
|
1154
|
message += F( "for (let i = 0; i < ");
|
1078
|
1155
|
message += String(SWITCH_COUNT);
|
1079
|
1156
|
message += F("; i++) {\n");
|
|
@@ -1106,13 +1183,13 @@ void handleRoot() {
|
1106
|
1183
|
message += F( "kickstart[i].style = 'background-color: red;';\n");
|
1107
|
1184
|
message += F( "}\n");
|
1108
|
1185
|
message += F( "}\n");
|
1109
|
|
-
|
|
1186
|
+
|
1110
|
1187
|
message += F( "var switchstate = document.getElementById('switchstate');\n");
|
1111
|
1188
|
message += F( "switchstate.innerHTML = msg.switchstate;\n");
|
1112
|
1189
|
message += F("};\n");
|
1113
|
1190
|
message += F("var hist = document.getElementsByClassName('log')[0];\n");
|
1114
|
1191
|
message += F("hist.scrollTop = hist.scrollHeight;\n");
|
1115
|
|
-
|
|
1192
|
+
|
1116
|
1193
|
message += F("var buttons = document.getElementsByTagName('input');\n");
|
1117
|
1194
|
message += F("for (let i = 0; i < buttons.length; i++) {\n");
|
1118
|
1195
|
message += F( "buttons[i].addEventListener('click', updateButton);\n");
|
|
@@ -1128,10 +1205,10 @@ void handleRoot() {
|
1128
|
1205
|
|
1129
|
1206
|
void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length) {
|
1130
|
1207
|
if ((type != WStype_TEXT) || (length != 1)) {
|
1131
|
|
- debug.println("Websocket: invalid type=" + String(type) + " len=" + String(length) + " data=" + String((char *)payload));
|
|
1208
|
+ debug.println("Websocket: invalid type=" + String(type) + " len=" + String(length) /* + " data=" + String((char *)payload) */ );
|
1132
|
1209
|
return;
|
1133
|
1210
|
}
|
1134
|
|
-
|
|
1211
|
+
|
1135
|
1212
|
char c = payload[0];
|
1136
|
1213
|
if ((c >= '0') && (c <= '9')) {
|
1137
|
1214
|
control_act_input(c - '0');
|
|
@@ -1154,7 +1231,7 @@ void wifi_setup() {
|
1154
|
1231
|
debug.println("WiFi: initializing");
|
1155
|
1232
|
WiFi.hostname(hostname);
|
1156
|
1233
|
WiFi.mode(WIFI_STA);
|
1157
|
|
-
|
|
1234
|
+
|
1158
|
1235
|
debug.print("WiFi: connecting");
|
1159
|
1236
|
WiFi.begin(WIFI_SSID, WIFI_PW);
|
1160
|
1237
|
|
|
@@ -1170,14 +1247,14 @@ void wifi_setup() {
|
1170
|
1247
|
}
|
1171
|
1248
|
debug.println();
|
1172
|
1249
|
debug.println(String("WiFi: status=") + String(WiFi.status()));
|
1173
|
|
-
|
|
1250
|
+
|
1174
|
1251
|
#elif defined(ARDUINO_ARCH_ESP32)
|
1175
|
1252
|
|
1176
|
1253
|
// Set hostname workaround
|
1177
|
1254
|
debug.println("WiFi: set hostname");
|
1178
|
1255
|
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
1179
|
1256
|
WiFi.setHostname(hostname.c_str());
|
1180
|
|
-
|
|
1257
|
+
|
1181
|
1258
|
// Workaround for WiFi connecting only every 2nd reset
|
1182
|
1259
|
// https://github.com/espressif/arduino-esp32/issues/2501#issuecomment-513602522
|
1183
|
1260
|
debug.println("WiFi: connection work-around");
|
|
@@ -1207,7 +1284,7 @@ void wifi_setup() {
|
1207
|
1284
|
}
|
1208
|
1285
|
debug.println();
|
1209
|
1286
|
debug.println(String("WiFi: status=") + String(WiFi.status()));
|
1210
|
|
-
|
|
1287
|
+
|
1211
|
1288
|
// Set hostname workaround
|
1212
|
1289
|
debug.println("WiFi: set hostname work-around");
|
1213
|
1290
|
WiFi.setHostname(hostname.c_str());
|
|
@@ -1236,7 +1313,7 @@ void wifi_setup() {
|
1236
|
1313
|
MDNS.begin(hostname.c_str());
|
1237
|
1314
|
updater.setup(&server);
|
1238
|
1315
|
server.on("/", handleRoot);
|
1239
|
|
-
|
|
1316
|
+
|
1240
|
1317
|
#ifdef ENABLE_GPIO_TEST
|
1241
|
1318
|
server.on("/gpiotest", handleGpioTest);
|
1242
|
1319
|
#endif // ENABLE_GPIO_TEST
|
|
@@ -1276,7 +1353,7 @@ void wifi_setup() {
|
1276
|
1353
|
|
1277
|
1354
|
socket.begin();
|
1278
|
1355
|
socket.onEvent(webSocketEvent);
|
1279
|
|
-
|
|
1356
|
+
|
1280
|
1357
|
debug.println("WiFi: setup done");
|
1281
|
1358
|
}
|
1282
|
1359
|
|
|
@@ -1290,17 +1367,17 @@ void wifi_run() {
|
1290
|
1367
|
last_server_handle_time = millis();
|
1291
|
1368
|
server.handleClient();
|
1292
|
1369
|
socket.loop();
|
1293
|
|
-
|
|
1370
|
+
|
1294
|
1371
|
#ifdef ARDUINO_ARCH_ESP8266
|
1295
|
1372
|
MDNS.update();
|
1296
|
1373
|
#endif // ARDUINO_ARCH_ESP8266
|
1297
|
1374
|
}
|
1298
|
|
-
|
|
1375
|
+
|
1299
|
1376
|
if ((millis() - last_websocket_update_time) >= WEBSOCKET_UPDATE_INTERVAL) {
|
1300
|
1377
|
last_websocket_update_time = millis();
|
1301
|
1378
|
wifi_send_status_broadcast();
|
1302
|
1379
|
}
|
1303
|
|
-
|
|
1380
|
+
|
1304
|
1381
|
#ifdef ENABLE_GPIO_TEST
|
1305
|
1382
|
if (runningGpioTest && ((millis() - lastGpioTime) >= GPIO_TEST_INTERVAL)) {
|
1306
|
1383
|
gpioTestState = !gpioTestState;
|