Browse Source

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

Thomas Buck 2 years ago
parent
commit
bada1f33df
9 changed files with 632 additions and 170 deletions
  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 View File

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

+ 16
- 0
include/Statemachine.h View File

36
         
36
         
37
         auto_mode_a, // select mode 1
37
         auto_mode_a, // select mode 1
38
         auto_mode_b, // select mode 2
38
         auto_mode_b, // select mode 2
39
+        auto_mode_c, // select mode 3
39
         auto_fert_a, // select fertilizer 1
40
         auto_fert_a, // select fertilizer 1
40
         auto_fert_b, // select fertilizer 2
41
         auto_fert_b, // select fertilizer 2
41
         auto_fert_run,
42
         auto_fert_run,
51
         fillnwater_kickstart_run,
52
         fillnwater_kickstart_run,
52
         fillnwater_plant_run,
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
         automation_mode,
69
         automation_mode,
55
         
70
         
56
         menu_pumps, // selet pump
71
         menu_pumps, // selet pump
118
     backspace_fn backspace;
133
     backspace_fn backspace;
119
     
134
     
120
     BoolField selected_plants;
135
     BoolField selected_plants;
136
+    BoolField selected_ferts;
121
     uint32_t selected_id; // pump or valve id
137
     uint32_t selected_id; // pump or valve id
122
     uint32_t selected_time; // runtime
138
     uint32_t selected_time; // runtime
123
     unsigned long start_time, stop_time, last_animation_time;
139
     unsigned long start_time, stop_time, last_animation_time;

+ 7
- 2
include/config.h View File

36
 #define MAX_PUMP_RUNTIME 30
36
 #define MAX_PUMP_RUNTIME 30
37
 #define MAX_VALVE_RUNTIME (45 * 60)
37
 #define MAX_VALVE_RUNTIME (45 * 60)
38
 #define MAX_AUX_RUNTIME (5 * 60)
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
 // Sketch version
43
 // Sketch version
42
-#define FIRMWARE_VERSION "0.5"
44
+#define FIRMWARE_VERSION "0.6"
43
 
45
 
44
 // all given in milliseconds
46
 // all given in milliseconds
45
 #define SERVER_HANDLE_INTERVAL 10
47
 #define SERVER_HANDLE_INTERVAL 10
49
 #define LED_CONNECT_BLINK_INTERVAL 250
51
 #define LED_CONNECT_BLINK_INTERVAL 250
50
 #define LED_ERROR_BLINK_INTERVAL 100
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
 #define INVERT_SENSOR_BOTTOM
57
 #define INVERT_SENSOR_BOTTOM
53
 //#define INVERT_SENSOR_TOP
58
 //#define INVERT_SENSOR_TOP
54
 
59
 

+ 3
- 3
include/config_pins.h View File

66
 #define PUMP_PINS 16, 17, 18
66
 #define PUMP_PINS 16, 17, 18
67
 
67
 
68
 // ensure a default for each PUMP_COUNT
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
 // bottom, top
71
 // bottom, top
72
 #define SWITCH_COUNT 2
72
 #define SWITCH_COUNT 2
136
 
136
 
137
 // kickstarting pumps, same count as plants!
137
 // kickstarting pumps, same count as plants!
138
 // set pin to -1 to disable kickstart for this plant.
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
 // a, b, c
141
 // a, b, c
142
 #define PUMP_COUNT 3
142
 #define PUMP_COUNT 3
143
 #define PUMP_PINS 2, 0, 4
143
 #define PUMP_PINS 2, 0, 4
144
 
144
 
145
 // ensure a default for each PUMP_COUNT
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
 // stirrer, locks
148
 // stirrer, locks
149
 #define STIRRER_COUNT 1
149
 #define STIRRER_COUNT 1

+ 2
- 2
src/BoolField.cpp View File

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
 bool BoolField::isSet(int n) {
41
 bool BoolField::isSet(int n) {

+ 2
- 2
src/DebugLog.cpp View File

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

+ 1
- 1
src/Functionality.cpp View File

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

+ 554
- 142
src/Statemachine.cpp
File diff suppressed because it is too large
View File


+ 46
- 17
src/WifiStuff.cpp View File

50
 SimpleUpdater updater;
50
 SimpleUpdater updater;
51
 unsigned long last_server_handle_time = 0;
51
 unsigned long last_server_handle_time = 0;
52
 unsigned long last_websocket_update_time = 0;
52
 unsigned long last_websocket_update_time = 0;
53
+int wifi_ok = 0;
53
 
54
 
54
 String message_buffer_a;
55
 String message_buffer_a;
55
 String message_buffer_b;
56
 String message_buffer_b;
259
     message += F("<title>Gieß-o-mat</title>\n");
260
     message += F("<title>Gieß-o-mat</title>\n");
260
     
261
     
261
     message += F("<style type='text/css'>\n");
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
     message += F(".container {\n");
267
     message += F(".container {\n");
263
     message += F("display: flex;\n");
268
     message += F("display: flex;\n");
269
+    message += F("max-width: 1200px;\n");
270
+    message += F("margin: auto;\n");
264
     message += F("}\n");
271
     message += F("}\n");
265
     
272
     
266
     message += F(".ui {\n");
273
     message += F(".ui {\n");
284
     message += F("width: max-content;\n");
291
     message += F("width: max-content;\n");
285
     message += F("border: 1px solid black;\n");
292
     message += F("border: 1px solid black;\n");
286
     message += F("border-radius: 50%;\n");
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
     message += F("}\n");
296
     message += F("}\n");
290
     
297
     
291
     message += F(".info {\n");
298
     message += F(".info {\n");
299
     message += F(".log {\n");
306
     message += F(".log {\n");
300
     message += F("max-height: 300px;\n");
307
     message += F("max-height: 300px;\n");
301
     message += F("padding: 0 1.0em;\n");
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
     message += F("border: 1px dashed black;\n");
312
     message += F("border: 1px dashed black;\n");
304
     message += F("font-family: monospace;\n");
313
     message += F("font-family: monospace;\n");
305
     message += F("overflow-y: scroll;\n");
314
     message += F("overflow-y: scroll;\n");
356
     message += F("</style>\n");
365
     message += F("</style>\n");
357
     
366
     
358
     message += F("</head><body>\n");
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
     message += F("<div class='container'>\n");
370
     message += F("<div class='container'>\n");
362
     message += F("<div class='ui'>\n");
371
     message += F("<div class='ui'>\n");
363
     message += F("<pre class='lcd'>\n");
372
     message += F("<pre class='lcd'>\n");
509
     message += F("\n</p><p>\n");
518
     message += F("\n</p><p>\n");
510
     message += F("MAC: ");
519
     message += F("MAC: ");
511
     message += WiFi.macAddress();
520
     message += WiFi.macAddress();
521
+    message += F("\n<br>\n");
522
+    message += F("IPv4: ");
523
+    message += WiFi.localIP().toString();
512
     message += F("\n</p>\n");
524
     message += F("\n</p>\n");
513
 
525
 
514
 #if defined(ARDUINO_ARCH_ESP8266)
526
 #if defined(ARDUINO_ARCH_ESP8266)
597
     message += F(    "}\n");
609
     message += F(    "}\n");
598
     message += F(    "var msg = JSON.parse(e.data);\n");
610
     message += F(    "var msg = JSON.parse(e.data);\n");
599
     message += F(    "var str = msg.a + '\\n' + msg.b + '\\n' + msg.c + '\\n' + msg.d;\n");
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
     message += F(    "var lcd = document.getElementsByClassName('lcd');\n");
613
     message += F(    "var lcd = document.getElementsByClassName('lcd');\n");
602
     message += F(    "lcd[0].innerHTML = str;\n");
614
     message += F(    "lcd[0].innerHTML = str;\n");
603
     message += F(    "var state = document.getElementById('state');\n");
615
     message += F(    "var state = document.getElementById('state');\n");
696
     // Build hostname string
708
     // Build hostname string
697
     String hostname = "giess-o-mat";
709
     String hostname = "giess-o-mat";
698
 
710
 
711
+    int ws = 0, connect_attempts = 0;
712
+
699
 #if defined(ARDUINO_ARCH_ESP8266)
713
 #if defined(ARDUINO_ARCH_ESP8266)
700
 
714
 
701
     // Connect to WiFi AP
715
     // Connect to WiFi AP
705
     
719
     
706
     debug.print("WiFi: connecting");
720
     debug.print("WiFi: connecting");
707
     WiFi.begin(WIFI_SSID, WIFI_PW);
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
         delay(LED_CONNECT_BLINK_INTERVAL);
726
         delay(LED_CONNECT_BLINK_INTERVAL);
711
         digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
727
         digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
712
     }
728
     }
713
     debug.println();
729
     debug.println();
730
+    debug.println(String("WiFi: status=") + String(WiFi.status()));
714
     
731
     
715
 #elif defined(ARDUINO_ARCH_ESP32)
732
 #elif defined(ARDUINO_ARCH_ESP32)
716
 
733
 
736
     WiFi.mode(WIFI_STA);
753
     WiFi.mode(WIFI_STA);
737
     WiFi.begin(WIFI_SSID, WIFI_PW);
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
         debug.print(String(" ") + String(ws));
758
         debug.print(String(" ") + String(ws));
742
         delay(LED_CONNECT_BLINK_INTERVAL);
759
         delay(LED_CONNECT_BLINK_INTERVAL);
743
         digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
760
         digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
744
     }
761
     }
745
     debug.println();
762
     debug.println();
746
-
747
     debug.println(String("WiFi: status=") + String(WiFi.status()));
763
     debug.println(String("WiFi: status=") + String(WiFi.status()));
748
     
764
     
749
     // Set hostname workaround
765
     // Set hostname workaround
752
 
768
 
753
 #endif
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
     debug.print("WiFi: got IPv4: ");
779
     debug.print("WiFi: got IPv4: ");
756
-    debug.println(WiFi.localIP());
780
+    debug.println(WiFi.localIP().toString());
757
 
781
 
758
 #ifdef ENABLE_INFLUXDB_LOGGING
782
 #ifdef ENABLE_INFLUXDB_LOGGING
759
     // Setup InfluxDB Client
783
     // Setup InfluxDB Client
781
 }
805
 }
782
 
806
 
783
 void wifi_run() {
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
     if ((millis() - last_server_handle_time) >= SERVER_HANDLE_INTERVAL) {
818
     if ((millis() - last_server_handle_time) >= SERVER_HANDLE_INTERVAL) {
785
         last_server_handle_time = millis();
819
         last_server_handle_time = millis();
786
         server.handleClient();
820
         server.handleClient();
796
         wifi_send_status_broadcast();
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
 #ifdef ENABLE_GPIO_TEST
833
 #ifdef ENABLE_GPIO_TEST
805
     if (runningGpioTest && ((millis() - lastGpioTime) >= GPIO_TEST_INTERVAL)) {
834
     if (runningGpioTest && ((millis() - lastGpioTime) >= GPIO_TEST_INTERVAL)) {
806
         gpioTestState = !gpioTestState;
835
         gpioTestState = !gpioTestState;

Loading…
Cancel
Save