|
@@ -19,6 +19,7 @@
|
19
|
19
|
|
20
|
20
|
#include "Plants.h"
|
21
|
21
|
#include "DebugLog.h"
|
|
22
|
+#include "WifiStuff.h"
|
22
|
23
|
#include "Statemachine.h"
|
23
|
24
|
#include "config.h"
|
24
|
25
|
|
|
@@ -200,7 +201,6 @@ void Statemachine::input(int n) {
|
200
|
201
|
plants.startPlant(i);
|
201
|
202
|
}
|
202
|
203
|
}
|
203
|
|
- selected_plants.clear();
|
204
|
204
|
|
205
|
205
|
selected_time = MAX_AUTO_PLANT_RUNTIME;
|
206
|
206
|
start_time = millis();
|
|
@@ -623,6 +623,37 @@ void Statemachine::switch_to(States s) {
|
623
|
623
|
a.c_str(),
|
624
|
624
|
"Hit any key for menu",
|
625
|
625
|
-1);
|
|
626
|
+
|
|
627
|
+#if defined(PLATFORM_ESP)
|
|
628
|
+ unsigned long runtime = stop_time - start_time;
|
|
629
|
+ if (old_state == auto_plant_run) {
|
|
630
|
+ for (int i = 0; i < plants.countPlants(); i++) {
|
|
631
|
+ if (selected_plants.isSet(i)) {
|
|
632
|
+ bool success = wifi_write_database(runtime / 1000, "plant", i + 1);
|
|
633
|
+ if (!success) {
|
|
634
|
+ debug.print("Error writing to InfluxDB ");
|
|
635
|
+ debug.print(INFLUXDB_HOST);
|
|
636
|
+ debug.print(":");
|
|
637
|
+ debug.print(INFLUXDB_PORT);
|
|
638
|
+ debug.print("/");
|
|
639
|
+ debug.print(INFLUXDB_DATABASE);
|
|
640
|
+ debug.println("/plant");
|
|
641
|
+ }
|
|
642
|
+ }
|
|
643
|
+ }
|
|
644
|
+ } else if (old_state == auto_fert_run) {
|
|
645
|
+ bool success = wifi_write_database(runtime / 1000, "fertilizer", selected_id);
|
|
646
|
+ if (!success) {
|
|
647
|
+ debug.print("Error writing to InfluxDB ");
|
|
648
|
+ debug.print(INFLUXDB_HOST);
|
|
649
|
+ debug.print(":");
|
|
650
|
+ debug.print(INFLUXDB_PORT);
|
|
651
|
+ debug.print("/");
|
|
652
|
+ debug.print(INFLUXDB_DATABASE);
|
|
653
|
+ debug.println("/fertilizer");
|
|
654
|
+ }
|
|
655
|
+ }
|
|
656
|
+#endif // PLATFORM_ESP
|
626
|
657
|
} else if (s == menu_pumps) {
|
627
|
658
|
String a = String("(Input 1 to ") + String(plants.countFertilizers()) + String(")");
|
628
|
659
|
|
|
@@ -671,6 +702,20 @@ void Statemachine::switch_to(States s) {
|
671
|
702
|
a.c_str(),
|
672
|
703
|
"Hit any key for menu",
|
673
|
704
|
-1);
|
|
705
|
+
|
|
706
|
+#if defined(PLATFORM_ESP)
|
|
707
|
+ unsigned long runtime = stop_time - start_time;
|
|
708
|
+ bool success = wifi_write_database(runtime / 1000, "fertilizer", selected_id);
|
|
709
|
+ if (!success) {
|
|
710
|
+ debug.print("Error writing to InfluxDB ");
|
|
711
|
+ debug.print(INFLUXDB_HOST);
|
|
712
|
+ debug.print(":");
|
|
713
|
+ debug.print(INFLUXDB_PORT);
|
|
714
|
+ debug.print("/");
|
|
715
|
+ debug.print(INFLUXDB_DATABASE);
|
|
716
|
+ debug.println("/fertilizer");
|
|
717
|
+ }
|
|
718
|
+#endif // PLATFORM_ESP
|
674
|
719
|
} else if (s == menu_valves) {
|
675
|
720
|
String a = String("(Input 1 to ") + String(plants.countPlants() + 1) + String(")");
|
676
|
721
|
|
|
@@ -719,6 +764,22 @@ void Statemachine::switch_to(States s) {
|
719
|
764
|
a.c_str(),
|
720
|
765
|
"Hit any key for menu",
|
721
|
766
|
-1);
|
|
767
|
+
|
|
768
|
+#if defined(PLATFORM_ESP)
|
|
769
|
+ unsigned long runtime = stop_time - start_time;
|
|
770
|
+ if (selected_id <= plants.countPlants()) {
|
|
771
|
+ bool success = wifi_write_database(runtime / 1000, "plant", selected_id);
|
|
772
|
+ if (!success) {
|
|
773
|
+ debug.print("Error writing to InfluxDB ");
|
|
774
|
+ debug.print(INFLUXDB_HOST);
|
|
775
|
+ debug.print(":");
|
|
776
|
+ debug.print(INFLUXDB_PORT);
|
|
777
|
+ debug.print("/");
|
|
778
|
+ debug.print(INFLUXDB_DATABASE);
|
|
779
|
+ debug.println("/plant");
|
|
780
|
+ }
|
|
781
|
+ }
|
|
782
|
+#endif // PLATFORM_ESP
|
722
|
783
|
} else if (s == error) {
|
723
|
784
|
print("------ Error! ------",
|
724
|
785
|
"There is a problem:",
|