diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino
index 1773cb0..f85a266 100644
--- a/Arduino/CanGrow/CanGrow.ino
+++ b/Arduino/CanGrow/CanGrow.ino
@@ -100,7 +100,8 @@ void setup() {
Serial.println(":: initialise I2C ::");
// initialise Wire for I2C
Wire.begin();
- Wire.setClockStretchLimit(2500);
+ // ClockStretchLimit seems to have negative effects
+ //Wire.setClockStretchLimit(2500);
Serial.println(":: initialise display ::");
// initialise I2C display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x64
@@ -241,6 +242,8 @@ void loop() {
controlPUMP();
+ controlFAN();
+
displayScreens();
// current time gets previous time for new interval
diff --git a/Arduino/CanGrow/CanGrow_Init.h b/Arduino/CanGrow/CanGrow_Init.h
index d5929f4..160810f 100644
--- a/Arduino/CanGrow/CanGrow_Init.h
+++ b/Arduino/CanGrow/CanGrow_Init.h
@@ -109,6 +109,7 @@ unsigned short MaintenanceDuration = 300;
char Esp32CamIP[16];
// PumpLastOn (long) timestamp
unsigned long PumpLastOn;
+bool OutputInvert;
diff --git a/Arduino/CanGrow/CanGrow_SysFunctions.h b/Arduino/CanGrow/CanGrow_SysFunctions.h
index fc8db14..29d2fb9 100644
--- a/Arduino/CanGrow/CanGrow_SysFunctions.h
+++ b/Arduino/CanGrow/CanGrow_SysFunctions.h
@@ -107,7 +107,8 @@ bool loadEEPROM() {
* 237 PumpLastOn (4 byte)
* 241 PumpIntervalVeg (1 byte)
* 242 PumpIntervalBloom (1 byte)
- * 243 ...
+ * 243 OutputInvert (1 byte)
+ * 244 ...
*
*/
@@ -173,7 +174,9 @@ bool loadEEPROM() {
EEPROM.get(221, Esp32CamIP);
// size is 4 byte
EEPROM.get(237, PumpLastOn);
-
+ // size is 1 byte
+ EEPROM.get(243, OutputInvert);
+
}
// TODO auth does not work atm
// EEPROM.get(160, WebUiUsername);
@@ -250,6 +253,10 @@ bool loadEEPROM() {
Serial.println(UseFANrelais);
Serial.print("MaintenanceDuration: ");
Serial.println(MaintenanceDuration);
+ Serial.print("PumpLastOn: ");
+ Serial.println(PumpLastOn);
+ Serial.print("OutputInvert: ");
+ Serial.println(OutputInvert);
Serial.println("---- Grow values ----");
Serial.print("GrowName: ");
@@ -396,7 +403,7 @@ unsigned short growState() {
void setOutput(byte Output, byte OutputState) {
/*
- * Pin assignments
+ * Output assignments
*
* 1 - LED
* 2 - FAN
@@ -405,6 +412,7 @@ void setOutput(byte Output, byte OutputState) {
*/
bool UseRelais = true;
byte OutputPin;
+ byte OutputState_tmp;
switch(Output) {
case 1:
@@ -438,10 +446,22 @@ void setOutput(byte Output, byte OutputState) {
//~ Serial.print("UseRelais: ");
//~ Serial.println(UseRelais);
+ // TODO read config for inverted outputs
+
if( (UseRelais == true) || (OutputPin == PinPUMP) ) {
- digitalWrite(OutputPin, 1 - OutputState);
+ if(OutputInvert == true) {
+ OutputState_tmp = 1 - OutputState;
+ } else {
+ OutputState_tmp = OutputState;
+ }
+ digitalWrite(OutputPin, OutputState_tmp);
} else {
- analogWrite(OutputPin, 255 - OutputState);
+ if(OutputInvert == true) {
+ OutputState_tmp = 255 - OutputState;
+ } else {
+ OutputState_tmp = OutputState;
+ }
+ analogWrite(OutputPin, OutputState_tmp);
}
}
@@ -676,7 +696,7 @@ void controlPUMP() {
switch(UsePump) {
case 1:
// when diff of time now and time pumpLastOn is greater then PumpInterval, do some watering (Or manual watering)
- if( (timeClient.getEpochTime() - PumpLastOn) >= (PumpInterval) ) { // TODO: * 24 * 60 * 60 PumpInterval
+ if( (timeClient.getEpochTime() - PumpLastOn) >= (PumpInterval * 24 * 60 *60) ) { // PumpInterval to, Days * 24 * 60 * 60
// only water as long PumpOnTime
if(PumpOnTimePassed < PumpOnTime) {
setOutput(3, 1);
@@ -688,6 +708,7 @@ void controlPUMP() {
PumpLastOn = timeClient.getEpochTime();
// write the value to EEPROM for the case ESP gets restarted
EEPROM.put(237, PumpLastOn);
+ EEPROM.commit(); //write to EEPROM
PumpOnTimePassed = 0;
}
} else {
@@ -719,9 +740,9 @@ void controlPUMP() {
//
case 3:
- if( ( (timeClient.getEpochTime() - PumpLastOn) >= (PumpInterval) ) && //TODO calculate PumpInterval into days as well here
+ if( ( (timeClient.getEpochTime() - PumpLastOn) >= (PumpInterval * 24 * 60 *60) ) && // PumpInterval to, Days * 24 * 60 * 60
( (valSoilmoistureAvg < SoilmoistureLow) ||
- ( (valSoilmoistureAvg >= SoilmoistureLow) && ( (PumpOnTimePassed > 0) && (PumpOnTimePassed <= PumpOnTime) ) )
+ ( (valSoilmoistureAvg >= SoilmoistureLow) && ( (PumpOnTimePassed > 0) && (PumpOnTimePassed <= PumpOnTime) ) )
) ) {
// check if we alerady exceeded max PumpOnTime
if(PumpOnTimePassed < PumpOnTime) {
@@ -750,3 +771,9 @@ void controlPUMP() {
//digitalWrite(PinPUMP, LOW);
}
}
+
+
+void controlFAN() {
+ setOutput(2, PinFANPWM); //inverted pwm
+}
+
diff --git a/Arduino/CanGrow/CanGrow_Version.h b/Arduino/CanGrow/CanGrow_Version.h
index 725945e..66e88dc 100644
--- a/Arduino/CanGrow/CanGrow_Version.h
+++ b/Arduino/CanGrow/CanGrow_Version.h
@@ -1,5 +1,5 @@
/* CanGrow_Version.h gets generated from cangrow.sh */
const char* CanGrowVer = "0.1-dev";
-const char* CanGrowBuild = "d2e264d-20240919022041";
+const char* CanGrowBuild = "461b816-20241205020134";
diff --git a/Arduino/CanGrow/CanGrow_WebFunctions.h b/Arduino/CanGrow/CanGrow_WebFunctions.h
index 82bbcc3..79f8450 100644
--- a/Arduino/CanGrow/CanGrow_WebFunctions.h
+++ b/Arduino/CanGrow/CanGrow_WebFunctions.h
@@ -498,15 +498,20 @@ void WEBgrowSettings() {
body+= "' required> Minutes
\n";
if(UseLEDrelais == false) {
- body += "LED brightness: %
\n";
}
if(UseFANrelais == false) {
- body += "FAN speed: %
\n";
+ } else {
+ body += "FAN on/off:
\n";
}
@@ -559,12 +564,12 @@ void WEBsystemSettings() {
body += "