diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index b581284..0f4075b 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -8,18 +8,30 @@ * */ -// external Libraries +// Libraries +// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI #include +// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire #include -#include -#include -#include "DHT.h" -#include -#include +// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/EEPROM #include -#include -#include +// https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi +#include #include +// https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer +#include +// https://github.com/adafruit/Adafruit-GFX-Library +#include +// https://github.com/adafruit/Adafruit_SSD1306 +#include +// https://github.com/adafruit/DHT-sensor-library +#include "DHT.h" +// https://github.com/bblanchon/ArduinoJson +#include +// https://github.com/arduino-libraries/NTPClient +#include +// https://github.com/PaulStoffregen/Time +#include /* * @@ -264,7 +276,7 @@ const char HTMLheader[] PROGMEM = R"EOF(
  • System settings
  • WiFi settings
  • Help
  • -
  • +
  • @@ -303,6 +315,23 @@ const char HTMLhelp[] PROGMEM = R"EOF( Here you will get some helpful help. )EOF"; +const char JSreplaceStr[] PROGMEM = R"EOF( + +)EOF"; + +const char JSconvertDateToEpoch[] PROGMEM = R"EOF( + +)EOF"; + /* * * Pin assignments @@ -687,28 +716,31 @@ bool loadEEPROM() { // size is 32 byte EEPROM.get(170, GrowName); - // size is 4 byte - EEPROM.get(202, GrowStart); - // size is 1 byte - EEPROM.get(206, DaysVeg); - // size is 1 byte - EEPROM.get(207, DaysBloom); - // size is 1 byte - EEPROM.get(208, LighthoursVeg); - // size is 1 byte - EEPROM.get(209, LighthoursBloom); - // size is 1 byte - EEPROM.get(210, SunriseHour); - // size is 1 byte - EEPROM.get(211, SunriseMinute); - + if(strlen(GrowName) < 1) { + // size is 4 byte + EEPROM.get(202, GrowStart); + // size is 1 byte + EEPROM.get(206, DaysVeg); + // size is 1 byte + EEPROM.get(207, DaysBloom); + // size is 1 byte + EEPROM.get(208, LighthoursVeg); + // size is 1 byte + EEPROM.get(209, LighthoursBloom); + // size is 1 byte + EEPROM.get(210, SunriseHour); + // size is 1 byte + EEPROM.get(211, SunriseMinute); + // size is 1 byte + EEPROM.get(212, DayOfGrow); + } // to ensure PINled_PWM always set to 255 when UseLEDrelais is true // we set it here again, does not matter whats stored. // size is 1 byte if(UseLEDrelais == true) { PINled_PWM = 255; } else { - EEPROM.get(212, PINled_PWM); + EEPROM.get(213, PINled_PWM); } @@ -757,6 +789,8 @@ bool loadEEPROM() { Serial.println(SunriseHour); Serial.print("SunriseMinute: "); Serial.println(SunriseMinute); + Serial.print("DayOfGrow: "); + Serial.println(DayOfGrow); Serial.print("PINled_PWM: "); Serial.println(PINled_PWM); @@ -1045,11 +1079,17 @@ String returnHTMLfooter() { String footer; // show the GrowName in the menu if set if(strlen(GrowName) > 0){ - // add a seedling to the growname :) - String divGrowName = "🌱 "; - divGrowName += GrowName; - // replace content of html ID GrowName - footer += JSreplaceStr("GrowName", divGrowName); + + // add replaceStr javascript function from PROGMEM + // first is dst ID, second is content (&#.. is a seedling emoji ) + footer += FPSTR(JSreplaceStr); + footer += ""; } footer += FPSTR(HTMLfooter); @@ -1075,6 +1115,34 @@ String returnStrSelected(byte savedValue, byte selectId) { return returnStr; } + +String returnStrDateFromEpoch(unsigned long epochTime) { + String dateStr; + byte Day = day(epochTime); + byte Month = month(epochTime); + unsigned int Year = year(epochTime); + + dateStr = Year; + dateStr += "-"; + + if(Month < 10) { + dateStr += "0"; + dateStr += Month; + } else { + dateStr += Month; + } + + dateStr += "-"; + + if(Day < 10) { + dateStr += "0"; + dateStr += Day; + } else { + dateStr += Day; + } + + return dateStr; +} /* * * Web pages @@ -1285,6 +1353,7 @@ void WEBgrowSettings() { body += "

    Final step: Grow settings

    "; body += "

    Please configure all settings
    "; body += "

    "; + GrowStart = timeClient.getEpochTime(); } body += "

    Grow Settings

    "; @@ -1302,9 +1371,17 @@ void WEBgrowSettings() { body += GrowName; body+= "' required>
    \n"; - body += "Grow start date:
    \n"; + + body += "
    \n"; + body+= "' required>\n"; + + body += "Days of vegetation: \n"; body += "\n"; + body += FPSTR(JSconvertDateToEpoch); body += returnHTMLfooter(); webserver.send(200, "text/html", body); @@ -1389,7 +1467,7 @@ void POSTgrowSettings() { // size is 1 byte EEPROM.put(211, SunriseMinute); // size is 1 byte - EEPROM.put(212, PINled_PWM); + EEPROM.put(213, PINled_PWM); EEPROM.commit(); @@ -1543,11 +1621,12 @@ void POSTwifiSettings() { } +/* String JSreplaceStr(String elementID, String content) { String jsReturn = ""; return jsReturn; } - +*/