diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 173313b..db49d27 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -325,7 +325,7 @@ function convertDateToEpoch(src, dst) { * D0 - MOSFET Pump * D1, D2 - I2C * D3 - DHT11 - * D4 - PIN_WIPE + * D4 - PinWIPE * D5 - MOSFET Fan * D6 - MOSFET Grow LED, PWM * D7 - waterlevel (set HIGH to read value) @@ -342,7 +342,7 @@ const uint8_t PINdht = D3; // D4 is HIGH at boot, boot fail if pulled to LOW // During Start Screen you can pull D4 to LOW to wipe saved data in EEPROM // DO NOT PULL D4 DOWN AT WHEN POWERING ON !!! BOOT WILL FAIL -const uint8_t PIN_WIPE = D4; +const uint8_t PinWIPE = D4; const uint8_t PinFAN = D5; const uint8_t PinLED = D6; // const uint8_t PINwaterlevel = D7; @@ -593,14 +593,14 @@ void wipeEEPROM() { // wipeMsg is helper variable to know if the Serial.print Message was // already sent byte wipeMsg = 0; - while(digitalRead(PIN_WIPE) == LOW ) { + while(digitalRead(PinWIPE) == LOW ) { // only show the Serial message once if(wipeMsg == 0) { - Serial.println("Please release PIN_WIPE to erase all data saved in EEPROM"); + Serial.println("Please release PinWIPE to erase all data saved in EEPROM"); Serial.println("LAST CHANCE TO KEEP THE DATA BY RESETTING NOW!!"); display.setCursor(0,36); - display.println("RELEASE PIN_WIPE"); + display.println("RELEASE PinWIPE"); display.println("TO WIPE EEPROM"); display.display(); @@ -623,18 +623,18 @@ void wipeEEPROM() { Serial.println("DONE"); - // set D4 PIN_WIPE internal LED to Output to give feedback WIPE + // set D4 PinWIPE internal LED to Output to give feedback WIPE // was done - pinMode(PIN_WIPE, OUTPUT); + pinMode(PinWIPE, OUTPUT); Serial.println("!! Device will restart in 3 seconds !!"); // let the internal led blink fast to signalize wipe is done for(byte i = 0; i <= 24 ; i++) { if(i % 2) { - digitalWrite(PIN_WIPE, LOW); + digitalWrite(PinWIPE, LOW); } else { - digitalWrite(PIN_WIPE, HIGH); + digitalWrite(PinWIPE, HIGH); } delay(125); } @@ -1038,9 +1038,7 @@ void refreshSensors() { * */ void setup() { - // Start EEPROM - EEPROM.begin(512); - + // setup pins pinMode(PinFAN, OUTPUT); pinMode(PINdht, INPUT); @@ -1048,7 +1046,7 @@ void setup() { pinMode(PINsoilmoisture, OUTPUT); pinMode(PinLED, OUTPUT); pinMode(PinPUMP, OUTPUT); - pinMode(PIN_WIPE, OUTPUT); + pinMode(PinWIPE, OUTPUT); // set all OUTPUT to low @@ -1063,12 +1061,14 @@ void setup() { // 220Hz is note A3 btw. analogWriteFreq(220); + // Start EEPROM + EEPROM.begin(512); + // Start Serial Serial.begin(115200); // Write a line before doing serious output, because before there is some garbage in serial // whats get the cursor somewhere over the place - // output Serial.println("420"); Serial.println(".:: CanGrow Start ::."); @@ -1076,7 +1076,7 @@ void setup() { Wire.begin(); // initialise I2C display - display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32 + display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x64 display.clearDisplay(); display.display(); @@ -1094,7 +1094,7 @@ void setup() { // initialise DHT11 dht.begin(); //TODO: Do only, when configured - Serial.println("To wipe the EEPROM saved data, set D4 (PIN_WIPE) to LOW - NOW! (2 seconds left)"); + Serial.println("To wipe the EEPROM saved data, set D4 (PinWIPE) to LOW - NOW! (2 seconds left)"); // wait a few seconds to let the user pull D4 down to wipe EEPROM // and we can enjoy the boot screen meanwhile :p // meanwhile blink with the led onboad :) @@ -1103,24 +1103,25 @@ void setup() { display.fillRect(0,36,128,64-36, 0); display.setCursor(0,36); display.println("To wipe EEPROM pull"); - display.println("D4 (PIN_WIPE) to GND"); + display.println("D4 (PinWIPE) to GND"); display.display(); - + + // blink with the onboard LED on D4 (PinWIPE) for(byte i = 0; i <= 6 ; i++) { if(i % 2) { - digitalWrite(PIN_WIPE, LOW); + digitalWrite(PinWIPE, LOW); } else { - digitalWrite(PIN_WIPE, HIGH); + digitalWrite(PinWIPE, HIGH); } delay(333); } // set back to HIGH because thats the default - digitalWrite(PIN_WIPE, HIGH); + digitalWrite(PinWIPE, HIGH); //delay(2000); - // read status from PIN_WIPE to WIPE - // when PIN_WIPE is set to LOW, wipe EEPROM - if(digitalRead(PIN_WIPE) == LOW) { + // read status from PinWIPE to WIPE + // when PinWIPE is set to LOW, wipe EEPROM + if(digitalRead(PinWIPE) == LOW) { // wipe EEPROM wipeEEPROM(); } @@ -1190,12 +1191,17 @@ void loop() { // current time gets previous time for new interval outputPrevTime = currentRuntime; } - - - //delay(1000); } +/* + * + * + * Web related stuff + * + * + */ + /* * Web Handler */ @@ -1241,7 +1247,7 @@ void WebHandler() { // favicon.ico is a special one, because its requested everytime and i dont wont to deliver the // failed whole page every call. we can save up this 0,5kb traffic :o) webserver.on("/favicon.ico", [](){ webserver.send(404, "text/html", "404 - not found"); }); - webserver.onNotFound(WEB404); + webserver.onNotFound(Sys404); // switching MOSFETs webserver.on("/switch", HTTP_POST, POSTsetOutput); @@ -1371,6 +1377,13 @@ String returnStrDateFromEpoch(unsigned long epochTime) { return dateStr; } + +/* + * + * System pages like infos, errors + * + */ + void SysRestart() { String body = returnHTMLheader(); // TODO only debug and development solution, remove this later @@ -1414,6 +1427,22 @@ void SysWipe() { } } +void Sys404() { + String body = returnHTMLheader(); + body += "
CanGrow is actually unconfigured. You need to Setup your WiFi first down below.
";
- body += "
After you entered your WiFi connection details, you need to restart and are step closer to your grow 🥦";
- body += "
";
+/*
+ * Grow page
+ */
+void WEBgrowSettings() {
+ // if system settings are unconfigured, we cannot proceed with growSettings
+ if(configured == false) {
+ webserver.sendHeader("Location", String("/systemSettings"), true);
+ webserver.send(302, "text/plain", "please configure systemSettings first");
+ } else {
+
+ String body = returnHTMLheader("growSettings");
+
+ if(strlen(GrowName) < 1) {
+ body += "
Please configure all settings
";
+ body += "
Here you can set everything grow related, like light hours, how much water, LED brightness
";
body += "
Select your wifi network from the SSID list.
To use DHCP leave IP, Subnet, Gateway and DNS fields blank!
Please configure all settings
";
- body += "
Here you can set everything grow related, like light hours, how much water, LED brightness
";
+void WEBwifiSettings() {
+ byte ssidsAvail = WiFi.scanNetworks();
+ String body = returnHTMLheader("wifiSettings");
+ if(FirstRun == true) {
+ body += "
CanGrow is actually unconfigured. You need to Setup your WiFi first down below.
";
+ body += "
After you entered your WiFi connection details, you need to restart and are step closer to your grow 🥦";
+ body += "
";
body += "
Select your wifi network from the SSID list.
To use DHCP leave IP, Subnet, Gateway and DNS fields blank!