firmware WIP - systemSettings restore settings
This commit is contained in:
parent
150cbc17d2
commit
3aed858228
1 changed files with 104 additions and 71 deletions
|
@ -67,8 +67,8 @@ bool configured;
|
||||||
// NTP Offset
|
// NTP Offset
|
||||||
int ntpOffset;
|
int ntpOffset;
|
||||||
// MoistureSensor_Type - contains which moisture sensor to use
|
// MoistureSensor_Type - contains which moisture sensor to use
|
||||||
// 0: analog capacitive sensor
|
// 1: analog capacitive sensor
|
||||||
// 1: I2C chirp sensor from catnip electronics
|
// 2: I2C chirp sensor from catnip electronics
|
||||||
byte MoistureSensor_Type;
|
byte MoistureSensor_Type;
|
||||||
// SoilmoistureLow - contains the value , when soil moisture is assumed to be low,
|
// SoilmoistureLow - contains the value , when soil moisture is assumed to be low,
|
||||||
byte SoilmoistureLow;
|
byte SoilmoistureLow;
|
||||||
|
@ -78,6 +78,10 @@ bool UsePump;
|
||||||
byte PumpOnTime;
|
byte PumpOnTime;
|
||||||
bool UseFan;
|
bool UseFan;
|
||||||
|
|
||||||
|
// In case the user uses no 12V LED on the LED output and an relais instead
|
||||||
|
// we have to disable PWM. So we ask here for what kind of light user is going
|
||||||
|
bool UseLEDrelais;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Grow Stuff
|
// Grow Stuff
|
||||||
//
|
//
|
||||||
|
@ -427,10 +431,10 @@ int getWaterlevel() {
|
||||||
* 0 : OK
|
* 0 : OK
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int waterlevelWARN = 200;
|
byte waterlevelWARN = 200;
|
||||||
int waterlevelOK = 400;
|
byte waterlevelOK = 400;
|
||||||
int waterlevelRAW = 0;
|
byte waterlevelRAW = 0;
|
||||||
int waterlevel = 0;
|
byte waterlevel = 0;
|
||||||
|
|
||||||
// enable Vcc for water level sensor
|
// enable Vcc for water level sensor
|
||||||
digitalWrite(PINwaterlevel, HIGH);
|
digitalWrite(PINwaterlevel, HIGH);
|
||||||
|
@ -453,22 +457,28 @@ int getWaterlevel() {
|
||||||
return waterlevel;
|
return waterlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
float getTemperature(bool tempSensor) {
|
float getTemperature(byte tempSensor) {
|
||||||
/*
|
/*
|
||||||
* tempSensor
|
* tempSensor
|
||||||
* ==========
|
* ==========
|
||||||
* 0/false : DHT11 temp sensor
|
* 1 : DHT11 temp sensor
|
||||||
* 1/true : chirp I2C temp sensor
|
* 2 : chirp I2C temp sensor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float temperature = 0;
|
float temperature = 0;
|
||||||
|
|
||||||
if(tempSensor == false ) {
|
switch(tempSensor) {
|
||||||
// read temperature from DHT11
|
case 1:
|
||||||
temperature = dht.readTemperature();
|
// read temperature from DHT11
|
||||||
} else {
|
temperature = dht.readTemperature();
|
||||||
// read temperature from chrip I2C
|
break;
|
||||||
temperature = readI2CRegister16bit(0x20, 5) * 0.10 ;
|
case 2:
|
||||||
|
// read temperature from chrip I2C
|
||||||
|
temperature = readI2CRegister16bit(0x20, 5) * 0.10 ;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// if sensor type is not recognized, return 99
|
||||||
|
temperature = 99.99;
|
||||||
}
|
}
|
||||||
|
|
||||||
return temperature;
|
return temperature;
|
||||||
|
@ -483,8 +493,8 @@ int getSoilmoisture(byte moistureSensor) {
|
||||||
/*
|
/*
|
||||||
* moistureSensor
|
* moistureSensor
|
||||||
* ==============
|
* ==============
|
||||||
* 0 : analog capacitive moisture sensor
|
* 1 : analog capacitive moisture sensor
|
||||||
* 1 : chirp I2C moisture sensor
|
* 2 : chirp I2C moisture sensor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// value to return
|
// value to return
|
||||||
|
@ -494,25 +504,32 @@ int getSoilmoisture(byte moistureSensor) {
|
||||||
// value for dry
|
// value for dry
|
||||||
int dry;
|
int dry;
|
||||||
|
|
||||||
if(moistureSensor == 0 ) {
|
switch(moistureSensor) {
|
||||||
// read analog value from analog moisture sensor
|
case 1:
|
||||||
wet = 180;
|
// read analog value from analog moisture sensor
|
||||||
dry= 590;
|
wet = 180;
|
||||||
|
dry= 590;
|
||||||
|
|
||||||
digitalWrite(PINsoilmoisture, HIGH);
|
digitalWrite(PINsoilmoisture, HIGH);
|
||||||
// wait a bit to let the circuit stabilize
|
// wait a bit to let the circuit stabilize
|
||||||
delay(100);
|
delay(100);
|
||||||
// get analog input value
|
// get analog input value
|
||||||
soilmoisture = analogRead(PINanalog);
|
soilmoisture = analogRead(PINanalog);
|
||||||
// disable Vcc for the sensor to release analog pin
|
// disable Vcc for the sensor to release analog pin
|
||||||
digitalWrite(PINsoilmoisture, LOW);
|
digitalWrite(PINsoilmoisture, LOW);
|
||||||
} else {
|
break;
|
||||||
// read soil moisture from chrip I2C
|
case 2:
|
||||||
wet = 560;
|
// read soil moisture from chrip I2C
|
||||||
dry= 250;
|
wet = 560;
|
||||||
|
dry= 250;
|
||||||
|
|
||||||
// get raw value from I2C chirp sensor
|
// get raw value from I2C chirp sensor
|
||||||
soilmoisture = readI2CRegister16bit(0x20, 0);
|
soilmoisture = readI2CRegister16bit(0x20, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wet = 0;
|
||||||
|
dry = 1;
|
||||||
|
soilmoisture = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return map(soilmoisture, wet, dry, 100, 0);
|
return map(soilmoisture, wet, dry, 100, 0);
|
||||||
|
@ -943,6 +960,24 @@ void WebAuthApi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returnSelected(bool)
|
||||||
|
* returns char[] "selected" if bool is true
|
||||||
|
* useful for html forms, to preset a saved value as selected
|
||||||
|
*/
|
||||||
|
String returnStrSelected(byte savedValue, byte selectId) {
|
||||||
|
String returnStr;
|
||||||
|
|
||||||
|
if(configured == true) {
|
||||||
|
if(savedValue == selectId) {
|
||||||
|
returnStr = "selected";
|
||||||
|
} else {
|
||||||
|
returnStr = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnStr;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Web pages
|
* Web pages
|
||||||
|
@ -1020,11 +1055,8 @@ void WEBwifiSettings() {
|
||||||
for(int i = 0 ; i < ssidsAvail; i++) {
|
for(int i = 0 ; i < ssidsAvail; i++) {
|
||||||
String wifiName = WiFi.SSID(i);
|
String wifiName = WiFi.SSID(i);
|
||||||
Serial.println(wifiName);
|
Serial.println(wifiName);
|
||||||
body += "<option value='";
|
body += "<option value='" + wifiName + "'>";
|
||||||
body += wifiName;
|
body += wifiName + "</option>\n";
|
||||||
body += "'>";
|
|
||||||
body += wifiName;
|
|
||||||
body += "</option>\n";
|
|
||||||
}
|
}
|
||||||
body += "</select><br>\n";
|
body += "</select><br>\n";
|
||||||
body += "Password: <input type='password' name='WIFIpassword'><br>\n";
|
body += "Password: <input type='password' name='WIFIpassword'><br>\n";
|
||||||
|
@ -1055,48 +1087,48 @@ void WEBsystemSettings() {
|
||||||
body += "<p>here you can set which features and sensors you use<br>";
|
body += "<p>here you can set which features and sensors you use<br>";
|
||||||
body += "</p>";
|
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 += "<form method='post' action='/systemSettings/save'>\n";
|
||||||
|
|
||||||
body += "Use fan: <select id='UseFan' name='UseFan' required>\n";
|
body += "Use fan: <select id='UseFan' name='UseFan' required>\n";
|
||||||
body += "<option disabled value='' selected hidden>---</option>\n";
|
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||||
body += "<option value='1'>Yes</option>\n";
|
body += "<option value='1'" + returnStrSelected(UseFan, 1) + ">Yes</option>\n";
|
||||||
body += "<option value='0'>No</option>\n";
|
body += "<option value='0'" + returnStrSelected(UseFan, 0) + ">No</option>\n";
|
||||||
body += "</select><br>\n";
|
body += "</select><br>\n";
|
||||||
|
|
||||||
|
|
||||||
body += "Use pump: <select id='UsePump' name='UsePump' required>\n";
|
body += "Use pump: <select id='UsePump' name='UsePump' required>\n";
|
||||||
body += "<option disabled value='' selected hidden>---</option>\n";
|
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||||
body += "<option value='1'>Yes</option>\n";
|
body += "<option value='1'" + returnStrSelected(UsePump, 1) + ">Yes</option>\n";
|
||||||
body += "<option value='0'>No</option>\n";
|
body += "<option value='0'" + returnStrSelected(UsePump, 0) + ">No</option>\n";
|
||||||
body += "</select><br>\n";
|
body += "</select><br>\n";
|
||||||
|
|
||||||
body += "Pump on time: <input type='text' name='PumpOnTime' required><br>\n";
|
|
||||||
|
body += "Use relais for LED: <select id='UseLEDrelais' name='UseLEDrelais' required>\n";
|
||||||
|
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||||
|
body += "<option value='1'" + returnStrSelected(UseLEDrelais, 1) + ">Yes</option>\n";
|
||||||
|
body += "<option value='0'" + returnStrSelected(UseLEDrelais, 0) + ">No</option>\n";
|
||||||
|
body += "</select><br>\n";
|
||||||
|
|
||||||
|
// TODO ugly. can this done be better?
|
||||||
|
body += "Pump on time: <input type='text' name='PumpOnTime' value='";
|
||||||
|
body += PumpOnTime;
|
||||||
|
body += "'required><br>\n";
|
||||||
|
|
||||||
body += "Moisture sensor type: <select id='MoistureSensor_Type' name='MoistureSensor_Type' required>\n";
|
body += "Moisture sensor type: <select id='MoistureSensor_Type' name='MoistureSensor_Type' required>\n";
|
||||||
body += "<option disabled value='' selected hidden>---</option>\n";
|
if(configured == false) {
|
||||||
body += "<option value='0'>Analog capacitive</option>\n";
|
body += "<option disabled value='' selected hidden>---</option>\n";
|
||||||
body += "<option value='1'>I2C chirp</option>\n";
|
}
|
||||||
|
body += "<option value='1'" + returnStrSelected(MoistureSensor_Type, 1) + ">Analog capacitive</option>\n";
|
||||||
|
body += "<option value='2'" + returnStrSelected(MoistureSensor_Type, 2) + ">I2C chirp</option>\n";
|
||||||
body += "</select><br>\n";
|
body += "</select><br>\n";
|
||||||
|
|
||||||
body += "Soil moisture low: <input type='text' name='SoilmoistureLow' required><br>\n";
|
body += "Soil moisture low: <input type='text' name='SoilmoistureLow' value='";
|
||||||
|
body += SoilmoistureLow;
|
||||||
|
body += "' required><br>\n";
|
||||||
|
|
||||||
body += "NTP offset: <input type='text' name='ntpOffset' required><br>\n";
|
body += "NTP offset: <input type='text' name='ntpOffset' value='";
|
||||||
|
body += ntpOffset;
|
||||||
|
body+= "' required><br>\n";
|
||||||
|
|
||||||
body += "<input type='submit' value='Save'>\n";
|
body += "<input type='submit' value='Save'>\n";
|
||||||
body += "</form>\n";
|
body += "</form>\n";
|
||||||
|
@ -1128,8 +1160,7 @@ void WEBgrowSettings() {
|
||||||
body += "<form method='post' action='/growSettings/save'>\n";
|
body += "<form method='post' action='/growSettings/save'>\n";
|
||||||
|
|
||||||
body += "Brightness <input type='range' id='PINled_PWM' name='PINled_PWM' min='1' max='255' value='";
|
body += "Brightness <input type='range' id='PINled_PWM' name='PINled_PWM' min='1' max='255' value='";
|
||||||
body += PINled_PWM;
|
body += PINled_PWM + "'/>";
|
||||||
body += "'/>";
|
|
||||||
|
|
||||||
body += "<input type='submit' value='Save'>\n";
|
body += "<input type='submit' value='Save'>\n";
|
||||||
body += "</form>\n";
|
body += "</form>\n";
|
||||||
|
@ -1184,6 +1215,8 @@ void POSTsystemSettings() {
|
||||||
EEPROM.put(166, SoilmoistureLow);
|
EEPROM.put(166, SoilmoistureLow);
|
||||||
// size is 2 byte
|
// size is 2 byte
|
||||||
EEPROM.put(167, ntpOffset);
|
EEPROM.put(167, ntpOffset);
|
||||||
|
// size is 1 byte
|
||||||
|
EEPROM.put(169, UseLEDrelais);
|
||||||
|
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue