3 Commits

Author SHA1 Message Date
  Thomas Buck 188b07f1b9 dont allow fullauto with less than configured amount of plants (2) 2 years ago
  Thomas Buck 5221bbb176 fix fert pumps running after pressing button to stop them 2 years ago
  Thomas Buck e4b0cf60b1 remove duplicated influxdb error handling 2 years ago
3 changed files with 35 additions and 65 deletions
  1. 4
    3
      include/config.h
  2. 16
    62
      src/Statemachine.cpp
  3. 15
    0
      src/WifiStuff.cpp

+ 4
- 3
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 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
 // Sketch version
44
 // Sketch version
44
 #define FIRMWARE_VERSION "0.6"
45
 #define FIRMWARE_VERSION "0.6"

+ 16
- 62
src/Statemachine.cpp View File

414
         }
414
         }
415
     } else if (state == fullauto_fert_run) {
415
     } else if (state == fullauto_fert_run) {
416
         // allow user to stop fertizilers and continue with tank filling
416
         // allow user to stop fertizilers and continue with tank filling
417
+        plants.abort();
418
+        stop_time = millis();
417
         auto wl = plants.getWaterlevel();
419
         auto wl = plants.getWaterlevel();
418
         if ((wl != Plants::full) && (wl != Plants::invalid)) {
420
         if ((wl != Plants::full) && (wl != Plants::invalid)) {
419
             // if the waterlevel is currently empty, we
421
             // if the waterlevel is currently empty, we
661
                     return;
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
                 // check if we need to run fertilizers
672
                 // check if we need to run fertilizers
665
                 if (selected_ferts.countSet() > 0) {
673
                 if (selected_ferts.countSet() > 0) {
666
                     // stirr before pumping fertilizers
674
                     // stirr before pumping fertilizers
1470
                     debug.println("ms");
1478
                     debug.println("ms");
1471
 
1479
 
1472
 #if defined(PLATFORM_ESP)
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
 #endif // PLATFORM_ESP
1482
 #endif // PLATFORM_ESP
1484
                 }
1483
                 }
1485
 
1484
 
1637
                     debug.print(String(time_to_water));
1636
                     debug.print(String(time_to_water));
1638
                     debug.println("ms");
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
         if ((old_state == auto_plant_run) || (old_state == fillnwater_plant_run)) {
1907
         if ((old_state == auto_plant_run) || (old_state == fillnwater_plant_run)) {
1918
             for (int i = 0; i < plants.countPlants(); i++) {
1908
             for (int i = 0; i < plants.countPlants(); i++) {
1919
                 if (selected_plants.isSet(i)) {
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
         } else if (old_state == auto_fert_run) {
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
 #endif // PLATFORM_ESP
1916
 #endif // PLATFORM_ESP
1945
     } else if (s == menu_pumps) {
1917
     } else if (s == menu_pumps) {
1995
 
1967
 
1996
 #if defined(PLATFORM_ESP)
1968
 #if defined(PLATFORM_ESP)
1997
         unsigned long runtime = stop_time - start_time;
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
 #endif // PLATFORM_ESP
1971
 #endif // PLATFORM_ESP
2009
     } else if (s == menu_valves) {
1972
     } else if (s == menu_valves) {
2010
         String a = String(F("(Input 1 to ")) + String(plants.countPlants() + 1) + String(F(")"));
1973
         String a = String(F("(Input 1 to ")) + String(plants.countPlants() + 1) + String(F(")"));
2060
 #if defined(PLATFORM_ESP)
2023
 #if defined(PLATFORM_ESP)
2061
         unsigned long runtime = stop_time - start_time;
2024
         unsigned long runtime = stop_time - start_time;
2062
         if (selected_id <= plants.countPlants()) {
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
 #endif // PLATFORM_ESP
2028
 #endif // PLATFORM_ESP
2075
     } else if (s == menu_aux) {
2029
     } else if (s == menu_aux) {

+ 15
- 0
src/WifiStuff.cpp View File

119
     success = influx.write(measurement);
119
     success = influx.write(measurement);
120
 #endif // ENABLE_INFLUXDB_LOGGING
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
     return success;
133
     return success;
123
 }
134
 }
124
 
135
 
134
 }
145
 }
135
 
146
 
136
 void wifi_send_status_broadcast(void) {
147
 void wifi_send_status_broadcast(void) {
148
+    if (WiFi.status() != WL_CONNECTED) {
149
+        return;
150
+    }
151
+
137
     if (socket.connectedClients() <= 0) {
152
     if (socket.connectedClients() <= 0) {
138
         return;
153
         return;
139
     }
154
     }

Loading…
Cancel
Save