my first plants are coming out of their seed - i need some light control urgently, lol
This commit is contained in:
parent
c7b3bc2d2f
commit
8922a8f9e9
1 changed files with 220 additions and 30 deletions
|
@ -39,16 +39,10 @@ float valHumidity;
|
|||
|
||||
|
||||
/*
|
||||
* EEPROM variables
|
||||
* EEPROM saved variables
|
||||
*/
|
||||
|
||||
//
|
||||
// System
|
||||
//
|
||||
// configured - if true, run setup assistant
|
||||
bool configured;
|
||||
// NTP Offset
|
||||
int ntpOffset;
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
@ -64,9 +58,32 @@ IPAddress WIFIgateway(192,168,4,254);
|
|||
IPAddress WIFIdns(0,0,0,0);
|
||||
char WebUiUsername[16] = "cangrow";
|
||||
char WebUiPassword[32] = "cangrow";
|
||||
|
||||
//
|
||||
// System
|
||||
//
|
||||
// configured - if true, run setup assistant
|
||||
bool configured;
|
||||
// NTP Offset
|
||||
int ntpOffset;
|
||||
// MoistureSensor_Type - contains which moisture sensor to use
|
||||
// 0: analog capacitive sensor
|
||||
// 1: I2C chirp sensor from catnip electronics
|
||||
byte MoistureSensor_Type;
|
||||
// SoilmoistureLow - contains the value , when soil moisture is assumed to be low,
|
||||
byte SoilmoistureLow;
|
||||
// UsePump - is the pump used? bool
|
||||
bool UsePump;
|
||||
// UseFan - is the fan used? bool
|
||||
byte PumpOnTime;
|
||||
bool UseFan;
|
||||
|
||||
//
|
||||
// Grow Stuff
|
||||
//
|
||||
|
||||
unsigned int NtpOffset;
|
||||
|
||||
// GrowName - contains the name of the grow/plant. Up to 32 byte
|
||||
char GrowName[32];
|
||||
// GrowStart - contains unix timestamp from date where grow starts (00:00)
|
||||
|
@ -88,17 +105,9 @@ byte SunriseHour;
|
|||
byte SunriseMinute;
|
||||
// PINled_PWM - contains the PWM value for dimming the grow light
|
||||
byte PINled_PWM;
|
||||
// MoistureSensor_Type - contains which moisture sensor to use
|
||||
// 0: analog capacitive sensor
|
||||
// 1: I2C chirp sensor from catnip electronics
|
||||
byte MoistureSensor_Type;
|
||||
// UsePump - is the pump used? bool
|
||||
bool UsePump;
|
||||
// UseFan - is the fan used? bool
|
||||
byte PumpOnTime;
|
||||
bool UseFan;
|
||||
// SoilmoistureLow - contains the value , when soil moisture is assumed to be low,
|
||||
byte SoilmoistureLow;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
|
@ -587,8 +596,8 @@ bool loadEEPROM() {
|
|||
EEPROM.get(128, WIFIgateway);
|
||||
// read var WIFIgateway from address 128, 16 byte long
|
||||
EEPROM.get(144, WIFIdns);
|
||||
// read var WIFIuseDHCP from Address 510, 1 byte long
|
||||
EEPROM.get(510, WIFIuseDHCP);
|
||||
// read var WIFIuseDHCP from Address 160, 1 byte long
|
||||
EEPROM.get(160, WIFIuseDHCP);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -603,9 +612,26 @@ bool loadEEPROM() {
|
|||
*
|
||||
* All boolean variables are at the end of the EEPROM
|
||||
*/
|
||||
EEPROM.get(511, configured);
|
||||
EEPROM.get(160, WebUiUsername);
|
||||
EEPROM.get(176, WebUiPassword);
|
||||
|
||||
|
||||
// size is 1 byte
|
||||
EEPROM.get(161, configured);
|
||||
// size is 1 byte
|
||||
EEPROM.get(162, UseFan);
|
||||
// size is 1 byte
|
||||
EEPROM.get(163, UsePump);
|
||||
// size is 1 byte
|
||||
EEPROM.get(164, PumpOnTime);
|
||||
// size is 1 byte
|
||||
EEPROM.get(165, MoistureSensor_Type);
|
||||
// size is 1 byte
|
||||
EEPROM.get(166, SoilmoistureLow);
|
||||
// size is 2 byte
|
||||
EEPROM.get(167, ntpOffset);
|
||||
|
||||
// TODO auth does not work atm
|
||||
// EEPROM.get(160, WebUiUsername);
|
||||
// EEPROM.get(176, WebUiPassword);
|
||||
|
||||
/*
|
||||
* Grow settings
|
||||
|
@ -618,8 +644,25 @@ bool loadEEPROM() {
|
|||
// print values to Serial output
|
||||
Serial.print("WIFIssid: ");
|
||||
Serial.println(WIFIssid);
|
||||
Serial.print("WIFIpassword: ");
|
||||
Serial.println(WIFIpassword);
|
||||
Serial.print("Use DHCP: ");
|
||||
Serial.println(WIFIuseDHCP);
|
||||
|
||||
Serial.print("UseFan: ");
|
||||
Serial.println(UseFan);
|
||||
Serial.print("UsePump: ");
|
||||
Serial.println(UsePump);
|
||||
Serial.print("PumpOnTime: ");
|
||||
Serial.println(PumpOnTime);
|
||||
Serial.print("MoistureSensor_Type: ");
|
||||
Serial.println(MoistureSensor_Type);
|
||||
Serial.print("SoilmoistureLow: ");
|
||||
Serial.println(SoilmoistureLow);
|
||||
Serial.print("ntpOffset: ");
|
||||
Serial.println(ntpOffset);
|
||||
|
||||
|
||||
Serial.print("configured: ");
|
||||
Serial.println(configured);
|
||||
} else {
|
||||
|
@ -833,20 +876,29 @@ void WebHandler() {
|
|||
webserver.on("/growSettings", HTTP_GET, WEBwifiSettings);
|
||||
} else {
|
||||
|
||||
// now we need to receive systemSettings
|
||||
webserver.on("/systemSettings/save", HTTP_POST, POSTsystemSettings);
|
||||
|
||||
// when system settings are unconfigured , then system settings are root
|
||||
if(configured == false) {
|
||||
webserver.on("/", HTTP_GET, WEBsystemSettings);
|
||||
webserver.on("/systemSettings", HTTP_GET, WEBsystemSettings);
|
||||
webserver.on("/growSettings", HTTP_GET, WEBsystemSettings);
|
||||
|
||||
|
||||
} else {
|
||||
webserver.on("/systemSettings", HTTP_GET, WEBsystemSettings);
|
||||
}
|
||||
|
||||
|
||||
webserver.on("/growSettings", HTTP_GET, WEBgrowSettings);
|
||||
// now we need to receive growSettings
|
||||
webserver.on("/growSettings/save", HTTP_POST, POSTgrowSettings);
|
||||
// when grow is unconfigured (GrowStart <1) then Grow settings are root
|
||||
if(GrowStart < 1) {
|
||||
webserver.on("/", HTTP_GET, WEBgrowSettings);
|
||||
} else {
|
||||
webserver.on("/growSettings", HTTP_GET, WEBgrowSettings);
|
||||
webserver.on("/", HTTP_GET, WEBroot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -946,7 +998,7 @@ void WEBwifiSettings() {
|
|||
body += "<br>";
|
||||
body += "</p>";
|
||||
}
|
||||
body += "<h1>WiFi config</h1>\n";
|
||||
body += "<h2>WiFi config</h2>\n";
|
||||
if(webserver.hasArg("success")) {
|
||||
body += "<div class='infomsg'>Successfully saved!<br>Please restart the device.</div>";
|
||||
}
|
||||
|
@ -980,9 +1032,66 @@ void WEBwifiSettings() {
|
|||
|
||||
void WEBsystemSettings() {
|
||||
String body = FPSTR(HTMLheader);
|
||||
body += "<h1>System settings</h1>";
|
||||
|
||||
if(configured == false) {
|
||||
body += "<h1>Step 2: System settings</h1>";
|
||||
body += "<p>Please configure all settings<br>";
|
||||
body += "</p>";
|
||||
}
|
||||
|
||||
body += "<h2>System settings</h2>";
|
||||
if(webserver.hasArg("success")) {
|
||||
body += "<div class='infomsg'>Successfully saved!<br>Please restart the device.</div>";
|
||||
}
|
||||
body += "<p>here you can set which features and sensors you use<br>";
|
||||
body += "</p>";
|
||||
|
||||
/*
|
||||
* // size is 1 byte
|
||||
EEPROM.put(162, UseFan);
|
||||
// size is 1 byte
|
||||
EEPROM.put(163, UsePump);
|
||||
// size is 1 byte
|
||||
EEPROM.put(164, PumpOnTime);
|
||||
// size is 1 byte
|
||||
EEPROM.put(165, MoistureSensor_Type);
|
||||
// size is 1 byte
|
||||
EEPROM.put(166, SoilmoistureLow);
|
||||
// size is 2 byte
|
||||
EEPROM.put(167, ntpOffset);
|
||||
* */
|
||||
|
||||
|
||||
body += "<form method='post' action='/systemSettings/save'>\n";
|
||||
|
||||
body += "Use fan: <select id='UseFan' name='UseFan' required>\n";
|
||||
body += "<option disabled value='' selected hidden>---</option>\n";
|
||||
body += "<option value='1'>Yes</option>\n";
|
||||
body += "<option value='0'>No</option>\n";
|
||||
body += "</select><br>\n";
|
||||
|
||||
|
||||
body += "Use pump: <select id='UsePump' name='UsePump' required>\n";
|
||||
body += "<option disabled value='' selected hidden>---</option>\n";
|
||||
body += "<option value='1'>Yes</option>\n";
|
||||
body += "<option value='0'>No</option>\n";
|
||||
body += "</select><br>\n";
|
||||
|
||||
body += "Pump on time: <input type='text' name='PumpOnTime' required><br>\n";
|
||||
|
||||
body += "Moisture sensor type: <select id='MoistureSensor_Type' name='MoistureSensor_Type' required>\n";
|
||||
body += "<option disabled value='' selected hidden>---</option>\n";
|
||||
body += "<option value='0'>Analog capacitive</option>\n";
|
||||
body += "<option value='1'>I2C chirp</option>\n";
|
||||
body += "</select><br>\n";
|
||||
|
||||
body += "Soil moisture low: <input type='text' name='SoilmoistureLow' required><br>\n";
|
||||
|
||||
body += "NTP offset: <input type='text' name='ntpOffset' required><br>\n";
|
||||
|
||||
body += "<input type='submit' value='Save'>\n";
|
||||
body += "</form>\n";
|
||||
|
||||
body += FPSTR(HTMLfooter);
|
||||
|
||||
webserver.send(200, "text/html", body);
|
||||
|
@ -993,9 +1102,26 @@ void WEBsystemSettings() {
|
|||
*/
|
||||
void WEBgrowSettings() {
|
||||
String body = FPSTR(HTMLheader);
|
||||
body += "<h1>Grow Settings</h1>";
|
||||
body += "<p>Here you can set everything grow related, like light hours, how much water, LED brightnes<br>";
|
||||
|
||||
if(strlen(GrowName) > 0) {
|
||||
body += "<h1>Step 3: Grow settings</h1>";
|
||||
body += "<p>Please configure all settings<br>";
|
||||
body += "</p>";
|
||||
}
|
||||
|
||||
body += "<h2>Grow Settings</h2>";
|
||||
if(webserver.hasArg("success")) {
|
||||
body += "<div class='infomsg'>Successfully saved!<br>Please restart the device.</div>";
|
||||
}
|
||||
body += "<p>Here you can set everything grow related, like light hours, how much water, LED brightness<br>";
|
||||
body += "</p>";
|
||||
|
||||
body += "<form method='post' action='/growSettings/save'>\n";
|
||||
|
||||
body += "Brightness <input type='range' id='PINled_PWM' name='PINled_PWM' min='1' max='255' step='5' />";
|
||||
|
||||
body += "<input type='submit' value='Save'>\n";
|
||||
body += "</form>\n";
|
||||
body += FPSTR(HTMLfooter);
|
||||
|
||||
webserver.send(200, "text/html", body);
|
||||
|
@ -1008,6 +1134,70 @@ void WEBgrowSettings() {
|
|||
*
|
||||
*/
|
||||
|
||||
void POSTgrowSettings() {
|
||||
PINled_PWM = webserver.arg("PINled_PWM").toInt();
|
||||
|
||||
analogWrite(D4, PINled_PWM);
|
||||
|
||||
Serial.println(":: POSTgrowSettings ::");
|
||||
|
||||
Serial.print("PINled_PWM: ");
|
||||
Serial.println(PINled_PWM);
|
||||
|
||||
webserver.sendHeader("Location", String("/growSettings?success"), true);
|
||||
webserver.send(302, "text/plain", "growSettings/save: success!");
|
||||
}
|
||||
|
||||
|
||||
void POSTsystemSettings() {
|
||||
ntpOffset = webserver.arg("ntpOffset").toInt();
|
||||
MoistureSensor_Type = webserver.arg("MoistureSensor_Type").toInt();
|
||||
SoilmoistureLow = webserver.arg("SoilmoistureLow").toInt();
|
||||
UsePump = webserver.arg("UsePump").toInt();
|
||||
PumpOnTime = webserver.arg("PumpOnTime").toInt();
|
||||
UseFan = webserver.arg("UseFan").toInt();
|
||||
|
||||
configured = true;
|
||||
|
||||
// size is 1 byte
|
||||
EEPROM.put(161, configured);
|
||||
// size is 1 byte
|
||||
EEPROM.put(162, UseFan);
|
||||
// size is 1 byte
|
||||
EEPROM.put(163, UsePump);
|
||||
// size is 1 byte
|
||||
EEPROM.put(164, PumpOnTime);
|
||||
// size is 1 byte
|
||||
EEPROM.put(165, MoistureSensor_Type);
|
||||
// size is 1 byte
|
||||
EEPROM.put(166, SoilmoistureLow);
|
||||
// size is 2 byte
|
||||
EEPROM.put(167, ntpOffset);
|
||||
|
||||
EEPROM.commit();
|
||||
|
||||
Serial.println(":: POSTsystemSettings ::");
|
||||
|
||||
Serial.print("configured: ");
|
||||
Serial.println(configured);
|
||||
Serial.print("UseFan: ");
|
||||
Serial.println(UseFan);
|
||||
Serial.print("UsePump: ");
|
||||
Serial.println(UsePump);
|
||||
Serial.print("PumpOnTime: ");
|
||||
Serial.println(PumpOnTime);
|
||||
Serial.print("MoistureSensor_Type: ");
|
||||
Serial.println(MoistureSensor_Type);
|
||||
Serial.print("SoilmoistureLow: ");
|
||||
Serial.println(SoilmoistureLow);
|
||||
Serial.print("ntpOffset: ");
|
||||
Serial.println(ntpOffset);
|
||||
|
||||
webserver.sendHeader("Location", String("/systemSettings?success"), true);
|
||||
webserver.send(302, "text/plain", "systemSettings/save: success!");
|
||||
}
|
||||
|
||||
|
||||
void POSTwifiSettings() {
|
||||
String WIFIssid_new = webserver.arg("WIFIssid");
|
||||
String WIFIpassword_new = webserver.arg("WIFIpassword");
|
||||
|
@ -1040,7 +1230,7 @@ void POSTwifiSettings() {
|
|||
EEPROM.put(112, WIFInetmask);
|
||||
EEPROM.put(128, WIFIgateway);
|
||||
EEPROM.put(144, WIFIdns);
|
||||
EEPROM.put(510, WIFIuseDHCP);
|
||||
EEPROM.put(160, WIFIuseDHCP);
|
||||
EEPROM.commit();
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue