Преглед на файлове

add full-auto mode. tweaks to web ui. allow use without wifi.

Thomas Buck преди 2 години
родител
ревизия
bada1f33df
променени са 9 файла, в които са добавени 632 реда и са изтрити 170 реда
  1. 1
    1
      include/BoolField.h
  2. 16
    0
      include/Statemachine.h
  3. 7
    2
      include/config.h
  4. 3
    3
      include/config_pins.h
  5. 2
    2
      src/BoolField.cpp
  6. 2
    2
      src/DebugLog.cpp
  7. 1
    1
      src/Functionality.cpp
  8. 554
    142
      src/Statemachine.cpp
  9. 46
    17
      src/WifiStuff.cpp

+ 1
- 1
include/BoolField.h Целия файл

@@ -26,7 +26,7 @@ public:
26 26
     ~BoolField(void);
27 27
     
28 28
     void clear(void);
29
-    void set(int n);
29
+    void set(int n, bool value = true);
30 30
     bool isSet(int n);
31 31
     int countSet(void);
32 32
     int getFirstSet(void);

+ 16
- 0
include/Statemachine.h Целия файл

@@ -36,6 +36,7 @@ public:
36 36
         
37 37
         auto_mode_a, // select mode 1
38 38
         auto_mode_b, // select mode 2
39
+        auto_mode_c, // select mode 3
39 40
         auto_fert_a, // select fertilizer 1
40 41
         auto_fert_b, // select fertilizer 2
41 42
         auto_fert_run,
@@ -51,6 +52,20 @@ public:
51 52
         fillnwater_kickstart_run,
52 53
         fillnwater_plant_run,
53 54
 
55
+        fullauto_fert, // d i a
56
+        fullauto_plant, // d i a
57
+        fullauto_stirr_run, // d i a
58
+        fullauto_fert_run, // d i a
59
+        fullauto_tank_run, // d i a
60
+        fullauto_kickstart_run, // d i a
61
+        fullauto_plant_run, // d i a
62
+        fullauto_plant_overrun, // d i a
63
+        fullauto_tank_purge_run, // d i a
64
+        fullauto_kickstart_purge_run, // d i a
65
+        fullauto_plant_purge_run, // d i a
66
+        fullauto_plant_purge_overrun, // d i a
67
+        fullauto_done, // d i a
68
+
54 69
         automation_mode,
55 70
         
56 71
         menu_pumps, // selet pump
@@ -118,6 +133,7 @@ private:
118 133
     backspace_fn backspace;
119 134
     
120 135
     BoolField selected_plants;
136
+    BoolField selected_ferts;
121 137
     uint32_t selected_id; // pump or valve id
122 138
     uint32_t selected_time; // runtime
123 139
     unsigned long start_time, stop_time, last_animation_time;

+ 7
- 2
include/config.h Целия файл

@@ -36,10 +36,12 @@
36 36
 #define MAX_PUMP_RUNTIME 30
37 37
 #define MAX_VALVE_RUNTIME (45 * 60)
38 38
 #define MAX_AUX_RUNTIME (5 * 60)
39
-#define KICKSTART_RUNTIME 10
39
+#define KICKSTART_RUNTIME 30
40
+#define OVERRUN_RUNTIME 60
41
+#define PURGE_FILL_RUNTIME 10
40 42
 
41 43
 // Sketch version
42
-#define FIRMWARE_VERSION "0.5"
44
+#define FIRMWARE_VERSION "0.6"
43 45
 
44 46
 // all given in milliseconds
45 47
 #define SERVER_HANDLE_INTERVAL 10
@@ -49,6 +51,9 @@
49 51
 #define LED_CONNECT_BLINK_INTERVAL 250
50 52
 #define LED_ERROR_BLINK_INTERVAL 100
51 53
 
54
+// each attempt takes LED_CONNECT_BLINK_INTERVAL ms
55
+#define MAX_WIFI_CONNECT_ATTEMPTS 40
56
+
52 57
 #define INVERT_SENSOR_BOTTOM
53 58
 //#define INVERT_SENSOR_TOP
54 59
 

+ 3
- 3
include/config_pins.h Целия файл

@@ -66,7 +66,7 @@
66 66
 #define PUMP_PINS 16, 17, 18
67 67
 
68 68
 // ensure a default for each PUMP_COUNT
69
-#define AUTO_PUMP_RUNTIME { 20, 5, 5 }
69
+#define AUTO_PUMP_RUNTIME { 20, 10, 10 }
70 70
 
71 71
 // bottom, top
72 72
 #define SWITCH_COUNT 2
@@ -136,14 +136,14 @@
136 136
 
137 137
 // kickstarting pumps, same count as plants!
138 138
 // set pin to -1 to disable kickstart for this plant.
139
-#define KICKSTART_PINS -1, -1, -1, -1, 108, 109, 110, 111
139
+#define KICKSTART_PINS 112, 113, 114, 115, 108, 109, 110, 111
140 140
 
141 141
 // a, b, c
142 142
 #define PUMP_COUNT 3
143 143
 #define PUMP_PINS 2, 0, 4
144 144
 
145 145
 // ensure a default for each PUMP_COUNT
146
-#define AUTO_PUMP_RUNTIME { 20, 5, 5 }
146
+#define AUTO_PUMP_RUNTIME { 20, 10, 10 }
147 147
 
148 148
 // stirrer, locks
149 149
 #define STIRRER_COUNT 1

+ 2
- 2
src/BoolField.cpp Целия файл

@@ -34,8 +34,8 @@ void BoolField::clear(void) {
34 34
     }
35 35
 }
36 36
 
37
-void BoolField::set(int n) {
38
-    field[n] = true;
37
+void BoolField::set(int n, bool value) {
38
+    field[n] = value;
39 39
 }
40 40
 
41 41
 bool BoolField::isSet(int n) {

+ 2
- 2
src/DebugLog.cpp Целия файл

@@ -67,11 +67,11 @@ void DebugLog::print(int n) {
67 67
 }
68 68
 
69 69
 void DebugLog::println(void) {
70
-    print(String('\n'));
70
+    print(String(F("\r\n")));
71 71
 }
72 72
 
73 73
 void DebugLog::println(String s) {
74
-    s += '\n';
74
+    s += String(F("\r\n"));
75 75
     print(s);
76 76
 }
77 77
 

+ 1
- 1
src/Functionality.cpp Целия файл

@@ -540,7 +540,7 @@ void write_to_all(const char *a, const char *b,
540 540
     //debug.println("write_to_all i2c");
541 541
     
542 542
     // rarely some lines don't update
543
-    delay(100);
543
+    delay(50);
544 544
 
545 545
     for (int i = 0; i < 4; i++) {
546 546
         Wire.beginTransmission(OWN_I2C_ADDRESS);

+ 554
- 142
src/Statemachine.cpp
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 46
- 17
src/WifiStuff.cpp Целия файл

@@ -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;

Loading…
Отказ
Запис