3 コミット

作成者 SHA1 メッセージ 日付
  Thomas Buck 188b07f1b9 dont allow fullauto with less than configured amount of plants (2) 2年前
  Thomas Buck 5221bbb176 fix fert pumps running after pressing button to stop them 2年前
  Thomas Buck e4b0cf60b1 remove duplicated influxdb error handling 2年前
3個のファイルの変更35行の追加65行の削除
  1. 4
    3
      include/config.h
  2. 16
    62
      src/Statemachine.cpp
  3. 15
    0
      src/WifiStuff.cpp

+ 4
- 3
include/config.h ファイルの表示

@@ -36,9 +36,10 @@
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 30
40
-#define OVERRUN_RUNTIME 60
41
-#define PURGE_FILL_RUNTIME 10
39
+#define KICKSTART_RUNTIME 45
40
+#define OVERRUN_RUNTIME 75
41
+#define PURGE_FILL_RUNTIME 20
42
+#define FULLAUTO_MIN_PLANT_COUNT 2
42 43
 
43 44
 // Sketch version
44 45
 #define FIRMWARE_VERSION "0.6"

+ 16
- 62
src/Statemachine.cpp ファイルの表示

@@ -414,6 +414,8 @@ void Statemachine::input(int n) {
414 414
         }
415 415
     } else if (state == fullauto_fert_run) {
416 416
         // allow user to stop fertizilers and continue with tank filling
417
+        plants.abort();
418
+        stop_time = millis();
417 419
         auto wl = plants.getWaterlevel();
418 420
         if ((wl != Plants::full) && (wl != Plants::invalid)) {
419 421
             // if the waterlevel is currently empty, we
@@ -661,6 +663,12 @@ void Statemachine::input(int n) {
661 663
                     return;
662 664
                 }
663 665
 
666
+#ifdef FULLAUTO_MIN_PLANT_COUNT
667
+                if (selected_plants.countSet() < FULLAUTO_MIN_PLANT_COUNT) {
668
+                    return;
669
+                }
670
+#endif
671
+
664 672
                 // check if we need to run fertilizers
665 673
                 if (selected_ferts.countSet() > 0) {
666 674
                     // stirr before pumping fertilizers
@@ -1470,16 +1478,7 @@ void Statemachine::act(void) {
1470 1478
                     debug.println("ms");
1471 1479
 
1472 1480
 #if defined(PLATFORM_ESP)
1473
-                    bool success = wifi_write_database(time_to_fill, "calibrated_filling", -1);
1474
-                    if (!success) {
1475
-                        debug.print("Error writing to InfluxDB ");
1476
-                        debug.print(INFLUXDB_HOST);
1477
-                        debug.print(":");
1478
-                        debug.print(INFLUXDB_PORT);
1479
-                        debug.print("/");
1480
-                        debug.print(INFLUXDB_DATABASE);
1481
-                        debug.println("/calibrated_filling");
1482
-                    }
1481
+                    wifi_write_database(time_to_fill, "calibrated_filling", -1);
1483 1482
 #endif // PLATFORM_ESP
1484 1483
                 }
1485 1484
 
@@ -1637,18 +1636,9 @@ void Statemachine::act(void) {
1637 1636
                     debug.print(String(time_to_water));
1638 1637
                     debug.println("ms");
1639 1638
 
1640
-    #if defined(PLATFORM_ESP)
1641
-                    bool success = wifi_write_database(time_to_water, "calibrated_watering", selected_plants.getFirstSet() + 1);
1642
-                    if (!success) {
1643
-                        debug.print("Error writing to InfluxDB ");
1644
-                        debug.print(INFLUXDB_HOST);
1645
-                        debug.print(":");
1646
-                        debug.print(INFLUXDB_PORT);
1647
-                        debug.print("/");
1648
-                        debug.print(INFLUXDB_DATABASE);
1649
-                        debug.println("/calibrated_watering");
1650
-                    }
1651
-    #endif // PLATFORM_ESP
1639
+#if defined(PLATFORM_ESP)
1640
+                    wifi_write_database(time_to_water, "calibrated_watering", selected_plants.getFirstSet() + 1);
1641
+#endif // PLATFORM_ESP
1652 1642
                 }
1653 1643
             }
1654 1644
 
@@ -1917,29 +1907,11 @@ void Statemachine::switch_to(States s) {
1917 1907
         if ((old_state == auto_plant_run) || (old_state == fillnwater_plant_run)) {
1918 1908
             for (int i = 0; i < plants.countPlants(); i++) {
1919 1909
                 if (selected_plants.isSet(i)) {
1920
-                    bool success = wifi_write_database(runtime / 1000, "plant", i + 1);
1921
-                    if (!success) {
1922
-                        debug.print("Error writing to InfluxDB ");
1923
-                        debug.print(INFLUXDB_HOST);
1924
-                        debug.print(":");
1925
-                        debug.print(INFLUXDB_PORT);
1926
-                        debug.print("/");
1927
-                        debug.print(INFLUXDB_DATABASE);
1928
-                        debug.println("/plant");
1929
-                    }
1910
+                    wifi_write_database(runtime / 1000, "plant", i + 1);
1930 1911
                 }
1931 1912
             }
1932 1913
         } else if (old_state == auto_fert_run) {
1933
-            bool success = wifi_write_database(runtime / 1000, "fertilizer", selected_id);
1934
-            if (!success) {
1935
-                debug.print("Error writing to InfluxDB ");
1936
-                debug.print(INFLUXDB_HOST);
1937
-                debug.print(":");
1938
-                debug.print(INFLUXDB_PORT);
1939
-                debug.print("/");
1940
-                debug.print(INFLUXDB_DATABASE);
1941
-                debug.println("/fertilizer");
1942
-            }
1914
+            wifi_write_database(runtime / 1000, "fertilizer", selected_id);
1943 1915
         }
1944 1916
 #endif // PLATFORM_ESP
1945 1917
     } else if (s == menu_pumps) {
@@ -1995,16 +1967,7 @@ void Statemachine::switch_to(States s) {
1995 1967
 
1996 1968
 #if defined(PLATFORM_ESP)
1997 1969
         unsigned long runtime = stop_time - start_time;
1998
-        bool success = wifi_write_database(runtime / 1000, "fertilizer", selected_id);
1999
-        if (!success) {
2000
-            debug.print("Error writing to InfluxDB ");
2001
-            debug.print(INFLUXDB_HOST);
2002
-            debug.print(":");
2003
-            debug.print(INFLUXDB_PORT);
2004
-            debug.print("/");
2005
-            debug.print(INFLUXDB_DATABASE);
2006
-            debug.println("/fertilizer");
2007
-        }
1970
+        wifi_write_database(runtime / 1000, "fertilizer", selected_id);
2008 1971
 #endif // PLATFORM_ESP
2009 1972
     } else if (s == menu_valves) {
2010 1973
         String a = String(F("(Input 1 to ")) + String(plants.countPlants() + 1) + String(F(")"));
@@ -2060,16 +2023,7 @@ void Statemachine::switch_to(States s) {
2060 2023
 #if defined(PLATFORM_ESP)
2061 2024
         unsigned long runtime = stop_time - start_time;
2062 2025
         if (selected_id <= plants.countPlants()) {
2063
-            bool success = wifi_write_database(runtime / 1000, "plant", selected_id);
2064
-            if (!success) {
2065
-                debug.print("Error writing to InfluxDB ");
2066
-                debug.print(INFLUXDB_HOST);
2067
-                debug.print(":");
2068
-                debug.print(INFLUXDB_PORT);
2069
-                debug.print("/");
2070
-                debug.print(INFLUXDB_DATABASE);
2071
-                debug.println("/plant");
2072
-            }
2026
+            wifi_write_database(runtime / 1000, "plant", selected_id);
2073 2027
         }
2074 2028
 #endif // PLATFORM_ESP
2075 2029
     } else if (s == menu_aux) {

+ 15
- 0
src/WifiStuff.cpp ファイルの表示

@@ -119,6 +119,17 @@ bool wifi_write_database(int duration, const char *type, int id) {
119 119
     success = influx.write(measurement);
120 120
 #endif // ENABLE_INFLUXDB_LOGGING
121 121
 
122
+    if (!success) {
123
+        debug.print("Error writing to InfluxDB ");
124
+        debug.print(INFLUXDB_HOST);
125
+        debug.print(":");
126
+        debug.print(INFLUXDB_PORT);
127
+        debug.print("/");
128
+        debug.print(INFLUXDB_DATABASE);
129
+        debug.print("/");
130
+        debug.println(type);
131
+    }
132
+
122 133
     return success;
123 134
 }
124 135
 
@@ -134,6 +145,10 @@ void wifi_schedule_websocket(void) {
134 145
 }
135 146
 
136 147
 void wifi_send_status_broadcast(void) {
148
+    if (WiFi.status() != WL_CONNECTED) {
149
+        return;
150
+    }
151
+
137 152
     if (socket.connectedClients() <= 0) {
138 153
         return;
139 154
     }

読み込み中…
キャンセル
保存