2024-03-30 03:04:48 +01:00
|
|
|
/*
|
|
|
|
* CanGrow - simply DIY automatic plant grow system (for cannabis).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
/*
|
|
|
|
* Includes
|
|
|
|
*
|
|
|
|
*/
|
2024-03-30 03:04:48 +01:00
|
|
|
|
2024-04-17 22:10:02 +02:00
|
|
|
// Libraries
|
|
|
|
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/SPI
|
2024-03-30 01:25:58 +01:00
|
|
|
#include <SPI.h>
|
2024-04-17 22:10:02 +02:00
|
|
|
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire
|
2024-03-30 01:25:58 +01:00
|
|
|
#include <Wire.h>
|
2024-04-17 22:10:02 +02:00
|
|
|
// https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/EEPROM
|
|
|
|
#include <EEPROM.h>
|
|
|
|
// https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
// https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer
|
|
|
|
#include <ESP8266WebServer.h>
|
|
|
|
// https://github.com/adafruit/Adafruit-GFX-Library
|
2024-03-30 01:25:58 +01:00
|
|
|
#include <Adafruit_GFX.h>
|
2024-04-17 22:10:02 +02:00
|
|
|
// https://github.com/adafruit/Adafruit_SSD1306
|
2024-03-30 01:25:58 +01:00
|
|
|
#include <Adafruit_SSD1306.h>
|
2024-04-17 22:10:02 +02:00
|
|
|
// https://github.com/adafruit/DHT-sensor-library
|
2024-03-30 03:04:48 +01:00
|
|
|
#include "DHT.h"
|
2024-04-17 22:10:02 +02:00
|
|
|
// https://github.com/bblanchon/ArduinoJson
|
2024-04-13 14:39:16 +02:00
|
|
|
#include <ArduinoJson.h>
|
2024-04-17 22:10:02 +02:00
|
|
|
// https://github.com/arduino-libraries/NTPClient
|
2024-04-14 16:39:49 +02:00
|
|
|
#include <NTPClient.h>
|
2024-04-17 22:10:02 +02:00
|
|
|
// https://github.com/PaulStoffregen/Time
|
|
|
|
#include <TimeLib.h>
|
2024-03-30 03:04:48 +01:00
|
|
|
|
2024-04-19 02:31:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Constants
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
const char* CanGrowVer = "0.1";
|
|
|
|
const char* APssid = "CanGrow-unconfigured";
|
|
|
|
/*
|
|
|
|
* TODO - does not work atm. idk why.
|
|
|
|
* const char* APpass = "CanGrow";
|
|
|
|
const int APchannel = 6;
|
|
|
|
const bool APhidden = false;
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
/*
|
2024-04-13 02:38:39 +02:00
|
|
|
*
|
|
|
|
* Variables
|
2024-04-09 13:45:33 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-04-13 17:53:47 +02:00
|
|
|
// valSoilmoisture - contains the value of getSoilmoisture()
|
|
|
|
byte valSoilmoisture;
|
|
|
|
// valTemperature - contains the value of getTemperature()
|
|
|
|
float valTemperature;
|
|
|
|
// valTemperature - contains the value of getHumidity()
|
|
|
|
float valHumidity;
|
|
|
|
// valWaterlevel - contains the value of getWaterlevel()
|
2024-04-17 01:44:41 +02:00
|
|
|
// do we need a restart? (e.g. after wifi settings change)
|
|
|
|
bool NeedRestart;
|
2024-04-17 02:18:01 +02:00
|
|
|
bool FirstRun;
|
2024-04-13 17:53:47 +02:00
|
|
|
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
/*
|
2024-04-19 02:31:15 +02:00
|
|
|
*
|
2024-04-16 12:31:03 +02:00
|
|
|
* EEPROM saved variables
|
2024-04-19 02:31:15 +02:00
|
|
|
*
|
2024-04-13 02:38:39 +02:00
|
|
|
*/
|
2024-04-13 15:46:40 +02:00
|
|
|
|
2024-04-14 16:39:49 +02:00
|
|
|
//
|
|
|
|
// WiFi
|
|
|
|
//
|
2024-04-17 22:44:30 +02:00
|
|
|
|
|
|
|
// if empty, CanGrow start in AccessPoint mode
|
2024-04-13 02:38:39 +02:00
|
|
|
char WIFIssid[32];
|
|
|
|
char WIFIpassword[64];
|
2024-04-14 15:13:27 +02:00
|
|
|
// WIFIuseDHCP - if true, get IP by DHCP
|
|
|
|
bool WIFIuseDHCP;
|
2024-04-13 19:02:12 +02:00
|
|
|
IPAddress WIFIip(192,168,4,20);
|
|
|
|
IPAddress WIFInetmask(255,255,255,0);
|
|
|
|
IPAddress WIFIgateway(192,168,4,254);
|
2024-04-13 21:41:36 +02:00
|
|
|
IPAddress WIFIdns(0,0,0,0);
|
2024-04-30 20:02:46 +02:00
|
|
|
//char WebUiUsername[16] = "cangrow";
|
|
|
|
//char WebUiPassword[32] = "cangrow";
|
2024-04-16 12:31:03 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// System
|
|
|
|
//
|
2024-04-17 22:44:30 +02:00
|
|
|
// configured - if false, let the user configure system settings first
|
2024-04-17 03:01:21 +02:00
|
|
|
bool configured = false;
|
2024-04-16 12:31:03 +02:00
|
|
|
// NTP Offset
|
2024-04-30 00:54:08 +02:00
|
|
|
short NtpOffset;
|
2024-04-16 12:31:03 +02:00
|
|
|
// MoistureSensor_Type - contains which moisture sensor to use
|
2024-04-16 23:26:58 +02:00
|
|
|
// 1: analog capacitive sensor
|
|
|
|
// 2: I2C chirp sensor from catnip electronics
|
2024-04-16 12:31:03 +02:00
|
|
|
byte MoistureSensor_Type;
|
|
|
|
// SoilmoistureLow - contains the value , when soil moisture is assumed to be low,
|
2024-04-17 03:01:21 +02:00
|
|
|
byte SoilmoistureLow = 20;
|
2024-04-16 12:31:03 +02:00
|
|
|
// UsePump - is the pump used? bool
|
|
|
|
bool UsePump;
|
|
|
|
// UseFan - is the fan used? bool
|
2024-04-17 22:44:30 +02:00
|
|
|
byte PumpOnTime = 3;
|
2024-04-16 12:31:03 +02:00
|
|
|
bool UseFan;
|
2024-04-16 23:26:58 +02:00
|
|
|
// 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;
|
2024-04-28 22:59:26 +02:00
|
|
|
bool UseFANrelais;
|
2024-04-17 23:16:44 +02:00
|
|
|
// Which temperature sensor to use?
|
|
|
|
byte TemperatureSensor_Type;
|
2024-04-16 23:26:58 +02:00
|
|
|
|
2024-04-14 16:39:49 +02:00
|
|
|
//
|
|
|
|
// Grow Stuff
|
|
|
|
//
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-13 19:02:12 +02:00
|
|
|
// GrowName - contains the name of the grow/plant. Up to 32 byte
|
2024-04-17 22:44:30 +02:00
|
|
|
// if empty, let the user setup grow settings first
|
2024-04-13 19:02:12 +02:00
|
|
|
char GrowName[32];
|
2024-04-13 17:53:47 +02:00
|
|
|
// GrowStart - contains unix timestamp from date where grow starts (00:00)
|
2024-04-16 01:51:24 +02:00
|
|
|
// unsigned long is 8 byte
|
2024-04-13 17:53:47 +02:00
|
|
|
unsigned long GrowStart;
|
|
|
|
// DayOfGrow contains on which day the grow is
|
|
|
|
byte DayOfGrow;
|
|
|
|
// DaysVeg - contains how many days to be in vegetation phase
|
2024-04-17 03:01:21 +02:00
|
|
|
byte DaysVeg = 35;
|
2024-04-13 17:53:47 +02:00
|
|
|
// DaysBloom - contains how many days to be in bloom phase
|
2024-04-17 03:01:21 +02:00
|
|
|
byte DaysBloom = 49;
|
2024-04-13 17:53:47 +02:00
|
|
|
// LighthoursVeg - contains how many hours the Growlight is on in Veg
|
2024-04-17 03:01:21 +02:00
|
|
|
byte LighthoursVeg = 16;
|
2024-04-13 17:53:47 +02:00
|
|
|
// LighthoursBloom - contains how many hours the Growlight is on in Bloom
|
2024-04-17 03:01:21 +02:00
|
|
|
byte LighthoursBloom = 12;
|
2024-04-14 16:39:49 +02:00
|
|
|
// SunriseHour - contains to which hour of day the growlight turns on
|
2024-04-17 03:01:21 +02:00
|
|
|
byte SunriseHour = 7;
|
2024-04-14 16:39:49 +02:00
|
|
|
// SunriseHour - contains to which minute of SunriseHour the growlight turns on
|
2024-04-17 03:01:21 +02:00
|
|
|
byte SunriseMinute = 0;
|
2024-04-30 00:54:08 +02:00
|
|
|
// PINledPWM - contains the PWM value for dimming the grow light
|
2024-04-17 01:08:11 +02:00
|
|
|
// default is 255 to ensure it is just on for the case UseLEDrelais is true
|
2024-04-30 00:54:08 +02:00
|
|
|
byte PINledPWM = 255;
|
|
|
|
byte PINfanPWM = 255;
|
|
|
|
|
|
|
|
// fade in and out sunrise and sunset?
|
|
|
|
bool SunFade;
|
|
|
|
byte SunFadeDuration = 30;
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
/*
|
|
|
|
*
|
2024-04-14 16:39:49 +02:00
|
|
|
* NTP
|
2024-04-19 02:31:15 +02:00
|
|
|
*
|
2024-04-14 16:39:49 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
WiFiUDP ntpUDP;
|
|
|
|
NTPClient timeClient(ntpUDP);
|
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Webserver
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
ESP8266WebServer webserver(80);
|
|
|
|
|
|
|
|
/*
|
2024-04-14 15:43:18 +02:00
|
|
|
* HTML constants for header, footer, css, ...
|
2024-04-30 20:02:46 +02:00
|
|
|
* Note: I know of the existence of SPIFFS and ESPHtmlTemplateProcessor,
|
|
|
|
* but to keep things simple for compiling and upload for others, I decided
|
|
|
|
* to not use those.
|
2024-04-13 02:38:39 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Template: const char HTMLexamplepage[] PROGMEM = R"EOF()EOF";
|
|
|
|
const char HTMLheader[] PROGMEM = R"EOF(
|
2024-04-14 15:43:18 +02:00
|
|
|
<!DOCTYPE html>
|
2024-04-13 02:38:39 +02:00
|
|
|
<html>
|
2024-04-14 15:43:18 +02:00
|
|
|
<head>
|
2024-04-30 20:02:46 +02:00
|
|
|
<meta charset='UTF-8'>
|
|
|
|
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
|
2024-04-14 15:43:18 +02:00
|
|
|
<title>CanGrow</title>
|
2024-04-30 20:02:46 +02:00
|
|
|
<!-- <link rel='stylesheet' href='/style.css'> -->
|
2024-04-17 19:41:10 +02:00
|
|
|
<style>
|
|
|
|
/* Having the whole CSS here ensures it's all the time present*/
|
|
|
|
body {
|
|
|
|
color: #cae0d0;
|
|
|
|
background-color: #1d211e;
|
|
|
|
font-family: helvetica;
|
|
|
|
}
|
|
|
|
|
|
|
|
.center {
|
|
|
|
width: 60%; min-width: 420px;
|
|
|
|
margin: auto;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
h1, h2, h3, h4, h5 {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
a:link, a:visited {
|
|
|
|
color: #04AA6D;
|
|
|
|
}
|
|
|
|
|
|
|
|
a:hover {
|
|
|
|
color: #64AA6D;
|
|
|
|
}
|
|
|
|
|
|
|
|
a:active {
|
|
|
|
color: #04AA6D;
|
|
|
|
}
|
|
|
|
|
|
|
|
.infomsg , .warnmsg {
|
|
|
|
color: #fff;
|
|
|
|
border-radius: 3px;
|
|
|
|
padding: 4px;
|
|
|
|
width: fit-content; min-width: 200px; max-width: 420px;
|
|
|
|
margin: auto;
|
|
|
|
margin-bottom: 5px;
|
|
|
|
font-weight: bold;
|
|
|
|
text-align: center;
|
|
|
|
text-decoration: none;
|
|
|
|
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
.infomsg {
|
|
|
|
background: #04AA6D;
|
|
|
|
}
|
|
|
|
|
|
|
|
.warnmsg {
|
|
|
|
background: #aa4204;
|
|
|
|
}
|
|
|
|
|
2024-04-17 22:23:40 +02:00
|
|
|
.inputShort {
|
|
|
|
width: 42px;
|
|
|
|
}
|
|
|
|
|
2024-04-17 19:41:10 +02:00
|
|
|
/* from https://gist.github.com/iamhelenliu/5755179 - thank you! */
|
|
|
|
.nav {
|
|
|
|
background: #333;
|
|
|
|
width: 60%; min-width: 420px;
|
|
|
|
margin: auto;
|
|
|
|
margin-bottom: 10px;
|
|
|
|
padding: 0;
|
|
|
|
position: relative;
|
|
|
|
border-radius: 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nav li {
|
|
|
|
display: inline-block;
|
|
|
|
list-style: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nav li:first-of-type {
|
|
|
|
background: #026b45;
|
|
|
|
border-top-left-radius: 3px;
|
|
|
|
border-bottom-left-radius: 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nav li a , .nav span {
|
|
|
|
color: #ddd;
|
|
|
|
display: block;
|
2024-04-30 20:02:46 +02:00
|
|
|
font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif;
|
2024-04-17 19:41:10 +02:00
|
|
|
font-size:0.8em;
|
|
|
|
padding: 10px 20px;
|
|
|
|
text-decoration: none;
|
|
|
|
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5);
|
|
|
|
}
|
2024-04-19 02:31:15 +02:00
|
|
|
|
|
|
|
.nav li a:hover , .activeMenu , .menuTime{
|
2024-04-17 19:41:10 +02:00
|
|
|
background: #04AA6D;
|
|
|
|
color: #fff;
|
|
|
|
border-radius: 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nav li a:active {
|
|
|
|
color: #cae0d0;
|
|
|
|
}
|
2024-04-19 02:31:15 +02:00
|
|
|
|
|
|
|
.activeMenu {
|
|
|
|
background: #444;
|
|
|
|
}
|
|
|
|
|
|
|
|
.MenuTime {
|
|
|
|
background: #292929;
|
|
|
|
}
|
2024-04-17 19:41:10 +02:00
|
|
|
</style>
|
2024-04-19 02:31:15 +02:00
|
|
|
<script>
|
|
|
|
function highlightActiveMenu(menuEntry) {
|
2024-04-30 20:02:46 +02:00
|
|
|
document.getElementById(menuEntry).classList.add('activeMenu');
|
2024-04-19 02:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function replaceStr(dst, content) {
|
|
|
|
document.getElementById(dst).innerHTML = content;
|
|
|
|
}
|
|
|
|
</script>
|
2024-04-14 15:43:18 +02:00
|
|
|
</head>
|
2024-04-13 02:38:39 +02:00
|
|
|
<body>
|
2024-04-30 20:02:46 +02:00
|
|
|
<ul class='nav'>
|
|
|
|
<li><a id='MenuGrowName' href='/'>🌱 CanGrow</a></li>
|
|
|
|
<li><a id='MgrowSettings' href='/growSettings'>Grow settings</a></li>
|
|
|
|
<li><a id='MsystemSettings' href='/systemSettings'>System settings</a></li>
|
|
|
|
<li><a id='MwifiSettings' href='/wifiSettings'>WiFi settings</a></li>
|
|
|
|
<li><a id='Mhelp' href='/help'>Help</a></li>
|
|
|
|
<li><span id='MenuTime' class='MenuTime'></span></li>
|
|
|
|
<li><a id='CanGrowVer' href='https://git.la10cy.net/DeltaLima/CanGrow' target='_blank'>CanGrow</a></li>
|
2024-04-15 01:53:54 +02:00
|
|
|
</ul>
|
2024-04-30 20:02:46 +02:00
|
|
|
<div class='center'>
|
2024-04-15 01:53:54 +02:00
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
)EOF";
|
|
|
|
|
|
|
|
const char HTMLfooter[] PROGMEM = R"EOF(
|
2024-04-15 23:51:17 +02:00
|
|
|
</div>
|
2024-04-13 02:38:39 +02:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
)EOF";
|
2024-04-09 13:45:33 +02:00
|
|
|
|
2024-04-17 01:44:41 +02:00
|
|
|
|
|
|
|
const char HTMLsuccess[] PROGMEM = R"EOF(
|
|
|
|
<div class='infomsg'>Successfully saved!</div>
|
|
|
|
)EOF";
|
|
|
|
|
|
|
|
const char HTMLneedRestart[] PROGMEM = R"EOF(
|
2024-04-17 03:01:21 +02:00
|
|
|
<div class='warnmsg'>Restart is required to apply new WiFi settings!
|
2024-04-30 20:02:46 +02:00
|
|
|
<form action='/system/restart'>
|
|
|
|
<input type='submit' value='Restart now' />
|
2024-04-17 03:01:21 +02:00
|
|
|
</form>
|
|
|
|
</div>
|
2024-04-16 01:51:24 +02:00
|
|
|
)EOF";
|
|
|
|
|
|
|
|
const char HTMLhelp[] PROGMEM = R"EOF(
|
|
|
|
<h1>CanGrow help</h1>
|
|
|
|
Here you will get some helpful help.
|
2024-04-14 15:43:18 +02:00
|
|
|
)EOF";
|
|
|
|
|
2024-04-17 22:10:02 +02:00
|
|
|
const char JSreplaceStr[] PROGMEM = R"EOF(
|
|
|
|
<script>
|
2024-04-19 02:31:15 +02:00
|
|
|
|
2024-04-17 22:10:02 +02:00
|
|
|
</script>
|
|
|
|
)EOF";
|
|
|
|
|
|
|
|
const char JSconvertDateToEpoch[] PROGMEM = R"EOF(
|
|
|
|
<script>
|
|
|
|
function convertDateToEpoch(src, dst) {
|
|
|
|
var valGrowStart = document.getElementById(src).value ;
|
|
|
|
document.getElementById(dst).value = new Date(valGrowStart).getTime() / 1000;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
)EOF";
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
/*
|
2024-04-13 19:02:12 +02:00
|
|
|
*
|
2024-04-09 13:45:33 +02:00
|
|
|
* Pin assignments
|
|
|
|
*
|
2024-04-30 00:54:08 +02:00
|
|
|
* D0 - MOSFET Pump
|
2024-04-13 19:02:12 +02:00
|
|
|
* D1, D2 - I2C
|
|
|
|
* D3 - DHT11
|
|
|
|
* D4 - PIN_WIPE
|
2024-04-30 00:54:08 +02:00
|
|
|
* D5 - MOSFET Fan
|
2024-04-13 19:02:12 +02:00
|
|
|
* D6 - MOSFET Grow LED, PWM
|
|
|
|
* D7 - waterlevel (set HIGH to read value)
|
|
|
|
* D8 - analog soil moisture (set HIGH to read value)
|
|
|
|
* A0 - analog input for soil moisture and waterlevel readings
|
|
|
|
*
|
|
|
|
* D4 and D7 cannot be HIGH at the same time!
|
2024-04-09 13:45:33 +02:00
|
|
|
*/
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-01 23:47:11 +02:00
|
|
|
// D0 is HIGH at boot, no PWM
|
2024-04-28 22:59:26 +02:00
|
|
|
const uint8_t PINpump = D0;
|
2024-04-01 23:47:11 +02:00
|
|
|
// If D3 is pulled to LOW, boot fails
|
2024-04-13 02:38:39 +02:00
|
|
|
const uint8_t PINdht = D3;
|
2024-04-01 23:47:11 +02:00
|
|
|
// D4 is HIGH at boot, boot fail if pulled to LOW
|
2024-04-13 19:02:12 +02:00
|
|
|
// 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
|
2024-04-13 02:38:39 +02:00
|
|
|
const uint8_t PIN_WIPE = D4;
|
2024-04-28 22:59:26 +02:00
|
|
|
const uint8_t PINfan = D5;
|
2024-04-13 02:38:39 +02:00
|
|
|
const uint8_t PINled = D6; //
|
|
|
|
const uint8_t PINwaterlevel = D7;
|
|
|
|
const uint8_t PINsoilmoisture = D8;
|
|
|
|
const uint8_t PINanalog = A0;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* millis timer
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
unsigned long outputPrevTime = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Status vars
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int D6status = false;
|
|
|
|
|
|
|
|
|
2024-03-30 01:25:58 +01:00
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
/* I2C Stuff
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define WIRE Wire
|
2024-04-07 03:55:17 +02:00
|
|
|
|
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
/*
|
|
|
|
* DHT Stuff
|
2024-04-09 13:45:33 +02:00
|
|
|
*
|
|
|
|
*/
|
2024-03-30 03:04:48 +01:00
|
|
|
#define DHTTYPE DHT11
|
2024-04-09 13:45:33 +02:00
|
|
|
DHT dht(PINdht, DHTTYPE);
|
2024-03-30 03:04:48 +01:00
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
/*
|
|
|
|
* Display Stuff
|
2024-04-09 13:45:33 +02:00
|
|
|
*/
|
2024-04-22 01:58:31 +02:00
|
|
|
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &WIRE);
|
2024-03-30 01:25:58 +01:00
|
|
|
// 'CanGrow_Logo', 128x32px
|
|
|
|
const unsigned char bmpCanGrow_Logo [] PROGMEM = {
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x03, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x07, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x0e, 0x03, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x38, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x1c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x70, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x18, 0x03, 0x00, 0x00, 0x00, 0x04, 0x07, 0xe0, 0x20, 0x60, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x18, 0x03, 0x00, 0x00, 0x00, 0x06, 0x07, 0xe0, 0xe0, 0x60, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x18, 0x00, 0x00, 0x00, 0x00, 0x03, 0x87, 0xe1, 0xc0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x30, 0x00, 0x3f, 0xc3, 0xff, 0x03, 0xc7, 0xe3, 0xc0, 0xcf, 0xf9, 0xff, 0xe3, 0xfc, 0xc1, 0x83,
|
|
|
|
0x30, 0x00, 0x7f, 0xe3, 0xff, 0x83, 0xe7, 0xe7, 0xc0, 0xcf, 0xfb, 0xff, 0xe7, 0xfe, 0xc3, 0x87,
|
|
|
|
0x30, 0x00, 0xe0, 0x73, 0x80, 0xc1, 0xf7, 0xef, 0xc0, 0xc0, 0x1b, 0x80, 0x0e, 0x03, 0xc3, 0x86,
|
|
|
|
0x30, 0x00, 0xc0, 0x33, 0x00, 0xc1, 0xff, 0xff, 0x80, 0xc0, 0x1b, 0x00, 0x0c, 0x03, 0xc7, 0x8e,
|
|
|
|
0x30, 0x01, 0xc0, 0x37, 0x00, 0xc0, 0xff, 0xff, 0x80, 0xc0, 0x3b, 0x00, 0x1c, 0x03, 0xc7, 0x8c,
|
|
|
|
0x60, 0x01, 0xc0, 0x37, 0x00, 0xc0, 0xff, 0xff, 0x01, 0x80, 0x3f, 0x00, 0x18, 0x03, 0xcf, 0x9c,
|
|
|
|
0x60, 0x00, 0x00, 0x37, 0x00, 0xc0, 0x7f, 0xfe, 0x01, 0x80, 0x37, 0x00, 0x18, 0x03, 0xcf, 0x9c,
|
|
|
|
0x60, 0x00, 0x00, 0x76, 0x01, 0xc0, 0x1f, 0xfc, 0x01, 0x80, 0x36, 0x00, 0x18, 0x06, 0xdf, 0xb8,
|
|
|
|
0x60, 0x00, 0x7f, 0xe6, 0x01, 0x9f, 0x9f, 0xfc, 0xf9, 0x80, 0x36, 0x00, 0x18, 0x06, 0xdd, 0xb8,
|
|
|
|
0x60, 0x00, 0xff, 0xe6, 0x01, 0x87, 0xff, 0xff, 0xf1, 0x80, 0x76, 0x00, 0x18, 0x06, 0xdd, 0xb0,
|
|
|
|
0xc0, 0x01, 0xc0, 0xee, 0x01, 0x83, 0xff, 0xff, 0xc3, 0x00, 0x7e, 0x00, 0x30, 0x06, 0xf9, 0xf0,
|
|
|
|
0xc0, 0x0b, 0x80, 0x6e, 0x01, 0x81, 0xff, 0xff, 0x83, 0x00, 0x6e, 0x00, 0x30, 0x06, 0xf9, 0xe0,
|
|
|
|
0xc0, 0x1b, 0x00, 0xec, 0x01, 0x80, 0x1f, 0xf8, 0x03, 0x00, 0x6c, 0x00, 0x30, 0x0e, 0xf1, 0xe0,
|
|
|
|
0xc0, 0x3b, 0x00, 0xcc, 0x03, 0x80, 0x3f, 0xfc, 0x03, 0x00, 0xec, 0x00, 0x30, 0x0c, 0xf1, 0xc0,
|
|
|
|
0xc0, 0x7b, 0x01, 0xcc, 0x03, 0x00, 0x7f, 0xfe, 0x03, 0x01, 0xec, 0x00, 0x30, 0x1c, 0xe1, 0xc0,
|
|
|
|
0x7f, 0xf1, 0xff, 0xdc, 0x03, 0x00, 0xf0, 0x8f, 0x01, 0xff, 0xfc, 0x00, 0x1f, 0xf8, 0xe1, 0xc0,
|
|
|
|
0x3f, 0xe0, 0xff, 0xcc, 0x03, 0x00, 0x00, 0x80, 0x00, 0xff, 0xcc, 0x00, 0x0f, 0xf0, 0xc1, 0x80,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 528)
|
|
|
|
const int bmpallArray_LEN = 1;
|
|
|
|
const unsigned char* bmpallArray[1] = {
|
|
|
|
bmpCanGrow_Logo
|
|
|
|
};
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
|
|
|
|
/*
|
2024-04-13 02:38:39 +02:00
|
|
|
*
|
|
|
|
*
|
2024-04-09 13:45:33 +02:00
|
|
|
* Functions
|
|
|
|
*
|
2024-04-13 02:38:39 +02:00
|
|
|
*
|
2024-04-09 13:45:33 +02:00
|
|
|
*/
|
2024-03-30 01:25:58 +01:00
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
/*
|
|
|
|
* Chirp functions
|
|
|
|
*/
|
2024-03-30 01:25:58 +01:00
|
|
|
void writeI2CRegister8bit(int addr, int value) {
|
|
|
|
Wire.beginTransmission(addr);
|
|
|
|
Wire.write(value);
|
|
|
|
Wire.endTransmission();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int readI2CRegister16bit(int addr, int reg) {
|
|
|
|
Wire.beginTransmission(addr);
|
|
|
|
Wire.write(reg);
|
|
|
|
Wire.endTransmission();
|
|
|
|
delay(20);
|
|
|
|
Wire.requestFrom(addr, 2);
|
|
|
|
unsigned int t = Wire.read() << 8;
|
|
|
|
t = t | Wire.read();
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Sensor functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-03-31 05:47:43 +02:00
|
|
|
int getWaterlevel() {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* waterlevelRAW
|
|
|
|
* ===========
|
|
|
|
* 0 - 199 : CRITICAL
|
|
|
|
* 200 - 399 : WARNING
|
|
|
|
* >400 : OK
|
|
|
|
*
|
|
|
|
* waterlevel
|
|
|
|
* ==========
|
|
|
|
* 2 : CRITICAL
|
|
|
|
* 1 : WARNING
|
|
|
|
* 0 : OK
|
|
|
|
*/
|
|
|
|
|
2024-04-19 00:29:19 +02:00
|
|
|
short waterlevelWARN = 200;
|
|
|
|
short waterlevelOK = 400;
|
|
|
|
short waterlevelRAW = 0;
|
2024-04-16 23:26:58 +02:00
|
|
|
byte waterlevel = 0;
|
2024-03-31 05:47:43 +02:00
|
|
|
|
|
|
|
// enable Vcc for water level sensor
|
2024-04-01 23:47:11 +02:00
|
|
|
digitalWrite(PINwaterlevel, HIGH);
|
2024-03-31 15:46:23 +02:00
|
|
|
// wait a bit to let the circuit stabilize
|
2024-04-13 02:38:39 +02:00
|
|
|
// TODO: replace delay() with millis()
|
2024-04-07 01:18:54 +02:00
|
|
|
delay(100);
|
2024-03-31 05:47:43 +02:00
|
|
|
// get the value
|
2024-04-01 23:47:11 +02:00
|
|
|
waterlevelRAW = analogRead(PINanalog);
|
2024-04-07 01:18:54 +02:00
|
|
|
// disable Vcc for the sensor to prevent electrolysis effect and release analog pin
|
2024-04-01 23:47:11 +02:00
|
|
|
digitalWrite(PINwaterlevel, LOW);
|
2024-03-31 05:47:43 +02:00
|
|
|
|
|
|
|
if( waterlevelRAW >= waterlevelOK) {
|
|
|
|
waterlevel = 0;
|
|
|
|
} else if( waterlevelRAW >= waterlevelWARN) {
|
|
|
|
waterlevel = 1;
|
|
|
|
} else {
|
|
|
|
waterlevel = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return waterlevel;
|
|
|
|
}
|
|
|
|
|
2024-04-16 23:26:58 +02:00
|
|
|
float getTemperature(byte tempSensor) {
|
2024-03-31 05:47:43 +02:00
|
|
|
/*
|
|
|
|
* tempSensor
|
|
|
|
* ==========
|
2024-04-16 23:26:58 +02:00
|
|
|
* 1 : DHT11 temp sensor
|
|
|
|
* 2 : chirp I2C temp sensor
|
2024-03-31 05:47:43 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
float temperature = 0;
|
|
|
|
|
2024-04-16 23:26:58 +02:00
|
|
|
switch(tempSensor) {
|
|
|
|
case 1:
|
|
|
|
// read temperature from DHT11
|
|
|
|
temperature = dht.readTemperature();
|
|
|
|
break;
|
|
|
|
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;
|
2024-03-31 05:47:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return temperature;
|
|
|
|
}
|
|
|
|
|
|
|
|
float getHumidity() {
|
|
|
|
float humidity = dht.readHumidity();
|
|
|
|
return humidity;
|
|
|
|
}
|
|
|
|
|
2024-04-13 19:02:12 +02:00
|
|
|
int getSoilmoisture(byte moistureSensor) {
|
2024-04-07 02:10:45 +02:00
|
|
|
/*
|
|
|
|
* moistureSensor
|
|
|
|
* ==============
|
2024-04-16 23:26:58 +02:00
|
|
|
* 1 : analog capacitive moisture sensor
|
|
|
|
* 2 : chirp I2C moisture sensor
|
2024-04-07 02:10:45 +02:00
|
|
|
*/
|
|
|
|
|
2024-04-07 01:56:33 +02:00
|
|
|
// value to return
|
2024-04-07 01:18:54 +02:00
|
|
|
int soilmoisture;
|
2024-04-07 01:56:33 +02:00
|
|
|
// value for wet
|
|
|
|
int wet;
|
|
|
|
// value for dry
|
|
|
|
int dry;
|
2024-04-07 01:18:54 +02:00
|
|
|
|
2024-04-16 23:26:58 +02:00
|
|
|
switch(moistureSensor) {
|
|
|
|
case 1:
|
|
|
|
// read analog value from analog moisture sensor
|
|
|
|
wet = 180;
|
|
|
|
dry= 590;
|
|
|
|
|
|
|
|
digitalWrite(PINsoilmoisture, HIGH);
|
|
|
|
// wait a bit to let the circuit stabilize
|
|
|
|
delay(100);
|
|
|
|
// get analog input value
|
|
|
|
soilmoisture = analogRead(PINanalog);
|
|
|
|
// disable Vcc for the sensor to release analog pin
|
|
|
|
digitalWrite(PINsoilmoisture, LOW);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// read soil moisture from chrip I2C
|
|
|
|
wet = 560;
|
|
|
|
dry= 250;
|
|
|
|
|
|
|
|
// get raw value from I2C chirp sensor
|
|
|
|
soilmoisture = readI2CRegister16bit(0x20, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wet = 0;
|
|
|
|
dry = 1;
|
|
|
|
soilmoisture = -1;
|
2024-04-07 01:18:54 +02:00
|
|
|
}
|
|
|
|
|
2024-04-07 01:56:33 +02:00
|
|
|
return map(soilmoisture, wet, dry, 100, 0);
|
2024-03-31 05:47:43 +02:00
|
|
|
}
|
|
|
|
|
2024-03-31 05:53:57 +02:00
|
|
|
int getLightchirp() {
|
|
|
|
// get the "light value" from I2C chirp module
|
|
|
|
writeI2CRegister8bit(0x20, 3); //request light measurement
|
|
|
|
int lightchirp = readI2CRegister16bit(0x20, 4);
|
|
|
|
return lightchirp;
|
|
|
|
}
|
|
|
|
|
2024-04-13 04:27:40 +02:00
|
|
|
|
2024-04-13 03:24:47 +02:00
|
|
|
void wipeEEPROM() {
|
2024-04-13 19:10:57 +02:00
|
|
|
Serial.println(":: wipe EEPROM ::");
|
|
|
|
|
2024-04-14 15:13:27 +02:00
|
|
|
// wipeMsg is helper variable to know if the Serial.print Message was
|
|
|
|
// already sent
|
|
|
|
byte wipeMsg = 0;
|
2024-04-13 19:02:12 +02:00
|
|
|
while(digitalRead(PIN_WIPE) == LOW ) {
|
|
|
|
// only show the Serial message once
|
2024-04-14 15:13:27 +02:00
|
|
|
if(wipeMsg == 0) {
|
2024-04-13 19:02:12 +02:00
|
|
|
Serial.println("Please release PIN_WIPE to erase all data saved in EEPROM");
|
2024-04-13 19:10:57 +02:00
|
|
|
Serial.println("LAST CHANCE TO KEEP THE DATA BY RESETTING NOW!!");
|
2024-04-22 01:58:31 +02:00
|
|
|
|
|
|
|
display.setCursor(0,36);
|
|
|
|
display.println("RELEASE PIN_WIPE");
|
|
|
|
display.println("TO WIPE EEPROM");
|
|
|
|
display.display();
|
|
|
|
|
2024-04-13 19:10:57 +02:00
|
|
|
// increase i to show the serial message only once
|
2024-04-14 15:13:27 +02:00
|
|
|
wipeMsg = 1;
|
2024-04-13 19:02:12 +02:00
|
|
|
}
|
2024-04-13 19:10:57 +02:00
|
|
|
delay(500);
|
2024-04-13 19:02:12 +02:00
|
|
|
}
|
|
|
|
|
2024-04-13 14:39:16 +02:00
|
|
|
// write a 0 to all 512 bytes of the EEPROM
|
|
|
|
Serial.print("wiping EEPROM... ");
|
2024-04-22 01:58:31 +02:00
|
|
|
display.setCursor(0,36);
|
|
|
|
display.println("Wiping EEPROM...");
|
|
|
|
display.println("Will restart in 3s");
|
|
|
|
display.display();
|
2024-04-13 14:39:16 +02:00
|
|
|
for (int i = 0; i < 512; i++) { EEPROM.write(i, 0); }
|
2024-04-13 15:46:40 +02:00
|
|
|
|
|
|
|
// commit everything to EEPROM and end here
|
|
|
|
EEPROM.end();
|
|
|
|
|
2024-04-13 14:39:16 +02:00
|
|
|
Serial.println("DONE");
|
2024-04-13 15:46:40 +02:00
|
|
|
|
|
|
|
// set D4 PIN_WIPE internal LED to Output to give feedback WIPE
|
|
|
|
// was done
|
2024-04-13 14:39:16 +02:00
|
|
|
pinMode(PIN_WIPE, OUTPUT);
|
2024-04-13 15:46:40 +02:00
|
|
|
|
2024-04-14 15:13:27 +02:00
|
|
|
Serial.println("!! Device will restart in 3 seconds !!");
|
2024-04-13 15:46:40 +02:00
|
|
|
|
2024-04-14 15:13:27 +02:00
|
|
|
// let the internal led blink fast to signalize wipe is done
|
|
|
|
for(byte i = 0; i <= 24 ; i++) {
|
|
|
|
if(i % 2) {
|
2024-04-13 15:46:40 +02:00
|
|
|
digitalWrite(PIN_WIPE, LOW);
|
|
|
|
} else {
|
|
|
|
digitalWrite(PIN_WIPE, HIGH);
|
|
|
|
}
|
2024-04-14 15:13:27 +02:00
|
|
|
delay(125);
|
2024-04-13 15:46:40 +02:00
|
|
|
}
|
|
|
|
ESP.restart();
|
2024-04-13 03:24:47 +02:00
|
|
|
}
|
2024-04-09 13:45:33 +02:00
|
|
|
|
2024-04-13 04:27:40 +02:00
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
bool loadEEPROM() {
|
2024-04-28 22:59:26 +02:00
|
|
|
/*
|
|
|
|
* EEPROM Save table
|
|
|
|
*
|
|
|
|
* 0 WIFIssid
|
|
|
|
* 32 WIFIpassword
|
|
|
|
* 96 WIFIip
|
|
|
|
* 112 WIFInetmask
|
|
|
|
* 128 WIFIgateway
|
|
|
|
* 144 WIFIdns
|
|
|
|
* 160 WIFIuseDHCP
|
|
|
|
*
|
|
|
|
* 161 configured
|
|
|
|
* 162 UseFan
|
|
|
|
* 163 UsePump
|
|
|
|
* 164 PumpOnTime
|
|
|
|
* 165 MoistureSensor_Type
|
|
|
|
* 166 SoilmoistureLow
|
2024-04-30 00:54:08 +02:00
|
|
|
* 167 NtpOffset
|
2024-04-28 22:59:26 +02:00
|
|
|
* 169 UseLEDrelais
|
|
|
|
*
|
|
|
|
* 170 GrowName
|
|
|
|
* 202 GrowStart
|
|
|
|
* 206 DaysVeg
|
|
|
|
* 207 DaysBloom
|
|
|
|
* 208 LighthoursVet
|
|
|
|
* 209 LighthoursBloom
|
|
|
|
* 210 SunriseHour
|
|
|
|
* 211 SunriseMinute
|
|
|
|
* 212 DayOfGrow
|
|
|
|
*
|
|
|
|
* -- afterwards added, need to sort --
|
|
|
|
*
|
2024-04-30 00:54:08 +02:00
|
|
|
* 213 PINledPWM
|
2024-04-28 22:59:26 +02:00
|
|
|
* 214 TemperatureSensor_Type
|
2024-04-29 01:32:17 +02:00
|
|
|
* 215 UseFANrelais
|
2024-04-30 00:54:08 +02:00
|
|
|
* 216 PINfanPWM
|
|
|
|
* 217 SunFade
|
|
|
|
* 218 SunFadeDuration
|
2024-04-28 22:59:26 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-04-13 21:41:36 +02:00
|
|
|
Serial.println(":: loading EEPROM ::");
|
2024-04-16 01:51:24 +02:00
|
|
|
|
2024-04-22 01:58:31 +02:00
|
|
|
display.setCursor(0,36);
|
|
|
|
display.fillRect(0,36,128,64-36, 0);
|
|
|
|
display.println("loading EEPROM");
|
|
|
|
display.display();
|
2024-04-16 01:51:24 +02:00
|
|
|
// read var WIFIssid from address 0, 32 byte long
|
|
|
|
// read this first, because we decide on the ssid length (>0?) if
|
|
|
|
// we run in unconfigured AP mode, nor not
|
|
|
|
EEPROM.get(0, WIFIssid);
|
2024-04-13 15:46:40 +02:00
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
// when length is > 0 then read furter EEPROM config data
|
|
|
|
if(strlen(WIFIssid)) {
|
2024-04-13 19:02:12 +02:00
|
|
|
/*
|
2024-04-15 23:51:17 +02:00
|
|
|
* WIFI settings
|
2024-04-13 19:02:12 +02:00
|
|
|
*/
|
2024-04-16 01:51:24 +02:00
|
|
|
|
2024-04-13 19:02:12 +02:00
|
|
|
// read var WIFIpassword from address 32, 64 byte long
|
|
|
|
EEPROM.get(32, WIFIpassword);
|
|
|
|
// read var WIFIip from address 96, 16 byte long
|
|
|
|
EEPROM.get(96, WIFIip);
|
|
|
|
// read var WIFInetmask from address 112, 16 byte long
|
|
|
|
EEPROM.get(112, WIFInetmask);
|
|
|
|
// read var WIFIgateway from address 128, 16 byte long
|
|
|
|
EEPROM.get(128, WIFIgateway);
|
2024-04-13 21:41:36 +02:00
|
|
|
// read var WIFIgateway from address 128, 16 byte long
|
|
|
|
EEPROM.get(144, WIFIdns);
|
2024-04-16 12:31:03 +02:00
|
|
|
// read var WIFIuseDHCP from Address 160, 1 byte long
|
|
|
|
EEPROM.get(160, WIFIuseDHCP);
|
2024-04-13 19:02:12 +02:00
|
|
|
|
2024-04-15 23:51:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* System settings
|
|
|
|
*/
|
2024-04-17 22:44:30 +02:00
|
|
|
|
2024-04-16 12:31:03 +02:00
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.get(161, configured);
|
2024-04-17 22:44:30 +02:00
|
|
|
if(configured == true) {
|
|
|
|
// 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
|
2024-04-30 00:54:08 +02:00
|
|
|
EEPROM.get(167, NtpOffset);
|
2024-04-17 22:44:30 +02:00
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.get(169, UseLEDrelais);
|
2024-04-17 23:16:44 +02:00
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.get(214, TemperatureSensor_Type);
|
2024-04-29 01:32:17 +02:00
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.get(215, UseFANrelais);
|
2024-04-17 22:44:30 +02:00
|
|
|
}
|
2024-04-16 12:31:03 +02:00
|
|
|
// TODO auth does not work atm
|
|
|
|
// EEPROM.get(160, WebUiUsername);
|
|
|
|
// EEPROM.get(176, WebUiPassword);
|
2024-04-15 23:51:17 +02:00
|
|
|
|
2024-04-13 19:02:12 +02:00
|
|
|
/*
|
2024-04-15 23:51:17 +02:00
|
|
|
* Grow settings
|
2024-04-13 19:02:12 +02:00
|
|
|
*/
|
|
|
|
|
2024-04-17 01:08:11 +02:00
|
|
|
// size is 32 byte
|
|
|
|
EEPROM.get(170, GrowName);
|
2024-04-17 22:23:40 +02:00
|
|
|
if(strlen(GrowName) > 0) {
|
2024-04-17 22:10:02 +02:00
|
|
|
// 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);
|
2024-04-30 00:54:08 +02:00
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.get(213, PINledPWM);
|
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.get(216, PINfanPWM);
|
|
|
|
EEPROM.get(217, SunFade);
|
|
|
|
EEPROM.get(218, SunFadeDuration);
|
2024-04-17 22:44:30 +02:00
|
|
|
|
2024-04-17 22:10:02 +02:00
|
|
|
}
|
2024-04-17 22:44:30 +02:00
|
|
|
|
2024-04-13 19:02:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// print values to Serial output
|
2024-04-17 01:08:11 +02:00
|
|
|
Serial.println("---- WiFi values ----");
|
2024-04-13 19:02:12 +02:00
|
|
|
Serial.print("WIFIssid: ");
|
|
|
|
Serial.println(WIFIssid);
|
2024-04-16 12:31:03 +02:00
|
|
|
Serial.print("WIFIpassword: ");
|
|
|
|
Serial.println(WIFIpassword);
|
2024-04-14 15:13:27 +02:00
|
|
|
Serial.print("Use DHCP: ");
|
|
|
|
Serial.println(WIFIuseDHCP);
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-17 01:08:11 +02:00
|
|
|
Serial.println("---- System values ----");
|
|
|
|
Serial.print("configured: ");
|
|
|
|
Serial.println(configured);
|
2024-04-16 12:31:03 +02:00
|
|
|
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);
|
2024-04-30 00:54:08 +02:00
|
|
|
Serial.print("NtpOffset: ");
|
|
|
|
Serial.println(NtpOffset);
|
2024-04-17 01:08:11 +02:00
|
|
|
Serial.print("UseLEDrelais: ");
|
|
|
|
Serial.println(UseLEDrelais);
|
2024-04-29 01:32:17 +02:00
|
|
|
Serial.print("UseFANrelais: ");
|
|
|
|
Serial.println(UseFANrelais);
|
2024-04-17 01:08:11 +02:00
|
|
|
|
|
|
|
Serial.println("---- Grow values ----");
|
|
|
|
Serial.print("GrowName: ");
|
|
|
|
Serial.println(GrowName);
|
|
|
|
Serial.print("GrowStart: ");
|
|
|
|
Serial.println(GrowStart);
|
|
|
|
Serial.print("DaysVeg: ");
|
|
|
|
Serial.println(DaysVeg);
|
|
|
|
Serial.print("DaysBloom: ");
|
|
|
|
Serial.println(DaysBloom);
|
|
|
|
Serial.print("LighthoursVeg: ");
|
|
|
|
Serial.println(LighthoursVeg);
|
|
|
|
Serial.print("LighthoursBloom: ");
|
|
|
|
Serial.println(LighthoursBloom);
|
|
|
|
Serial.print("SunriseHour: ");
|
|
|
|
Serial.println(SunriseHour);
|
|
|
|
Serial.print("SunriseMinute: ");
|
|
|
|
Serial.println(SunriseMinute);
|
2024-04-17 22:10:02 +02:00
|
|
|
Serial.print("DayOfGrow: ");
|
|
|
|
Serial.println(DayOfGrow);
|
2024-04-30 00:54:08 +02:00
|
|
|
Serial.print("PINledPWM: ");
|
|
|
|
Serial.println(PINledPWM);
|
|
|
|
Serial.print("PINfanPWM: ");
|
|
|
|
Serial.println(PINfanPWM);
|
|
|
|
Serial.print("SunFade: ");
|
|
|
|
Serial.println(SunFade);
|
|
|
|
Serial.print("SunFadeDuration: ");
|
|
|
|
Serial.println(SunFadeDuration);
|
2024-04-16 12:31:03 +02:00
|
|
|
|
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
} else {
|
|
|
|
Serial.println("EEPROM value WIFIssid is empty");
|
2024-04-13 19:02:12 +02:00
|
|
|
}
|
2024-04-13 21:41:36 +02:00
|
|
|
Serial.println(":: EEPROM loaded ::");
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-22 01:58:31 +02:00
|
|
|
display.setCursor(0,42);
|
|
|
|
display.println("EEPROM loaded");
|
|
|
|
display.display();
|
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
return(strlen(WIFIssid));
|
2024-04-13 02:38:39 +02:00
|
|
|
}
|
|
|
|
|
2024-04-13 21:41:36 +02:00
|
|
|
void wifiConnect() {
|
|
|
|
Serial.println(":: Connecting to WiFi ::");
|
2024-04-17 02:18:01 +02:00
|
|
|
FirstRun = false;
|
2024-04-13 21:41:36 +02:00
|
|
|
Serial.print("SSID: ");
|
|
|
|
Serial.println(WIFIssid);
|
2024-04-22 01:58:31 +02:00
|
|
|
|
|
|
|
display.fillRect(0,36,128,64-36, 0);
|
|
|
|
display.setCursor(0,36);
|
|
|
|
display.println("Connecting to WiFi");
|
|
|
|
display.println(WIFIssid);
|
|
|
|
display.display();
|
2024-04-13 21:41:36 +02:00
|
|
|
|
|
|
|
// Start WiFi connection
|
|
|
|
WiFi.begin(WIFIssid, WIFIpassword);
|
2024-04-14 15:13:27 +02:00
|
|
|
if(WIFIuseDHCP == false) {
|
|
|
|
WiFi.config(WIFIip, WIFIdns, WIFIgateway, WIFInetmask);
|
|
|
|
}
|
2024-04-13 21:41:36 +02:00
|
|
|
|
|
|
|
// wait until WiFi connection is established
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
delay(500);
|
|
|
|
Serial.print(".");
|
|
|
|
}
|
|
|
|
Serial.println(" CONNECTED!");
|
|
|
|
Serial.print("IP: ");
|
|
|
|
Serial.println(WiFi.localIP());
|
2024-04-17 22:33:24 +02:00
|
|
|
|
|
|
|
Serial.println(":: Getting time from NTP ::");
|
2024-04-22 01:58:31 +02:00
|
|
|
display.fillRect(0,36,128,64-36, 0);
|
|
|
|
display.setCursor(0,36);
|
|
|
|
display.println("Getting NTP time");
|
|
|
|
display.display();
|
|
|
|
|
2024-04-14 16:39:49 +02:00
|
|
|
timeClient.begin();
|
2024-04-30 00:54:08 +02:00
|
|
|
timeClient.setTimeOffset(NtpOffset * 60 * 60);
|
2024-04-14 16:39:49 +02:00
|
|
|
timeClient.update();
|
2024-04-17 22:33:24 +02:00
|
|
|
while ( ! timeClient.isTimeSet()) {
|
|
|
|
timeClient.update();
|
|
|
|
delay(500);
|
|
|
|
Serial.print(".");
|
|
|
|
}
|
|
|
|
|
2024-04-14 16:39:49 +02:00
|
|
|
Serial.println(timeClient.getFormattedTime());
|
|
|
|
Serial.println(timeClient.getEpochTime());
|
2024-04-22 01:58:31 +02:00
|
|
|
display.println(timeClient.getFormattedTime());
|
2024-04-16 13:23:24 +02:00
|
|
|
display.display();
|
|
|
|
display.print("IP: ");
|
|
|
|
display.print(WiFi.localIP());
|
|
|
|
display.display();
|
2024-04-13 21:41:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wifiAp() {
|
|
|
|
Serial.println(":: Creating Accesspoint ::");
|
2024-04-22 01:58:31 +02:00
|
|
|
|
|
|
|
display.fillRect(0,36,128,64-36, 0);
|
|
|
|
display.setCursor(0,36);
|
|
|
|
display.println("Creating AccessPoint");
|
|
|
|
display.println(APssid);
|
|
|
|
display.display();
|
|
|
|
|
2024-04-17 02:18:01 +02:00
|
|
|
FirstRun = true;
|
2024-04-13 21:41:36 +02:00
|
|
|
// configure WiFi Access Point
|
|
|
|
WiFi.softAPConfig(WIFIip, WIFIgateway, WIFInetmask);
|
|
|
|
// start Access Point
|
|
|
|
// TODO make AP with password - does not work atm. idk why.
|
|
|
|
WiFi.softAP(APssid);
|
|
|
|
Serial.print("SSID: ");
|
|
|
|
Serial.println(APssid);
|
|
|
|
Serial.print("CanGrow IP address: ");
|
|
|
|
Serial.println(WiFi.softAPIP());
|
2024-04-17 02:18:01 +02:00
|
|
|
// TODO does not work atm, idk why
|
|
|
|
//Serial.println("The login credentials for the WebUI are 'cangrow' for username and password");
|
2024-04-13 21:41:36 +02:00
|
|
|
}
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-30 02:31:55 +02:00
|
|
|
void setOutput(byte Output, byte OutputState) {
|
2024-04-30 00:54:08 +02:00
|
|
|
/*
|
|
|
|
* Pin assignments
|
|
|
|
*
|
|
|
|
* 1 - LED
|
|
|
|
* 2 - FAN
|
|
|
|
* 3 - PUMP
|
|
|
|
*
|
|
|
|
*/
|
2024-04-30 02:31:55 +02:00
|
|
|
bool UseRelais = true;
|
|
|
|
byte OutputPin;
|
2024-04-30 00:54:08 +02:00
|
|
|
|
2024-04-30 02:31:55 +02:00
|
|
|
switch(Output) {
|
2024-04-30 00:54:08 +02:00
|
|
|
case 1:
|
2024-04-30 02:31:55 +02:00
|
|
|
OutputPin = PINled;
|
|
|
|
if(UseLEDrelais == true) {
|
|
|
|
UseRelais = true;
|
2024-04-30 00:54:08 +02:00
|
|
|
} else {
|
2024-04-30 02:31:55 +02:00
|
|
|
UseRelais = false;
|
2024-04-30 00:54:08 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2024-04-30 02:31:55 +02:00
|
|
|
OutputPin = PINfan;
|
|
|
|
if(UseFANrelais == true) {
|
|
|
|
UseRelais = true;
|
2024-04-30 00:54:08 +02:00
|
|
|
} else {
|
2024-04-30 02:31:55 +02:00
|
|
|
UseRelais = false;
|
2024-04-30 00:54:08 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
// PUMP Pin (D0) does not support PWM, so we do not need to care about
|
|
|
|
case 3:
|
2024-04-30 02:31:55 +02:00
|
|
|
OutputPin = PINpump;
|
2024-04-30 00:54:08 +02:00
|
|
|
break;
|
|
|
|
}
|
2024-04-30 02:31:55 +02:00
|
|
|
|
|
|
|
//~ Serial.print("Output: ");
|
|
|
|
//~ Serial.println(Output);
|
|
|
|
//~ Serial.print("OutputPin: ");
|
|
|
|
//~ Serial.println(OutputPin);
|
|
|
|
//~ Serial.print("OutputState: ");
|
|
|
|
//~ Serial.println(OutputState);
|
|
|
|
//~ Serial.print("UseRelais: ");
|
|
|
|
//~ Serial.println(UseRelais);
|
|
|
|
|
|
|
|
if( (UseRelais == true) || (OutputPin == PINpump) ) {
|
|
|
|
digitalWrite(OutputPin, OutputState);
|
|
|
|
} else {
|
|
|
|
analogWrite(OutputPin, OutputState);
|
|
|
|
}
|
2024-04-30 00:54:08 +02:00
|
|
|
}
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
/*
|
|
|
|
* Setup
|
|
|
|
*
|
|
|
|
*/
|
2024-03-30 01:25:58 +01:00
|
|
|
void setup() {
|
2024-04-13 14:39:16 +02:00
|
|
|
// Start EEPROM
|
|
|
|
EEPROM.begin(512);
|
|
|
|
|
2024-03-31 04:41:50 +02:00
|
|
|
// setup pins
|
|
|
|
pinMode(PINfan, OUTPUT);
|
|
|
|
pinMode(PINdht, INPUT);
|
2024-04-01 23:47:11 +02:00
|
|
|
pinMode(PINwaterlevel, OUTPUT);
|
2024-04-07 01:18:54 +02:00
|
|
|
pinMode(PINsoilmoisture, OUTPUT);
|
2024-03-31 04:41:50 +02:00
|
|
|
pinMode(PINled, OUTPUT);
|
|
|
|
pinMode(PINpump, OUTPUT);
|
2024-04-18 16:04:40 +02:00
|
|
|
pinMode(PIN_WIPE, OUTPUT);
|
2024-04-15 01:53:54 +02:00
|
|
|
|
2024-03-31 04:41:50 +02:00
|
|
|
|
|
|
|
// set all OUTPUT to low
|
|
|
|
digitalWrite(PINfan, LOW);
|
2024-04-01 23:47:11 +02:00
|
|
|
digitalWrite(PINwaterlevel, LOW);
|
2024-04-07 01:18:54 +02:00
|
|
|
digitalWrite(PINsoilmoisture, LOW);
|
2024-03-31 04:41:50 +02:00
|
|
|
digitalWrite(PINled, LOW);
|
|
|
|
digitalWrite(PINpump, LOW);
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-29 02:23:49 +02:00
|
|
|
// set PWM frequency lower to avoid annoying noises
|
|
|
|
// in combination with 47uF at fan output, 220Hz is kinda sweetspot
|
|
|
|
// 220Hz is note A3 btw.
|
2024-04-29 01:32:17 +02:00
|
|
|
analogWriteFreq(220);
|
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
// Start Serial
|
|
|
|
Serial.begin(115200);
|
2024-04-13 15:46:40 +02:00
|
|
|
|
2024-04-17 22:45:50 +02:00
|
|
|
// Write a line before doing serious output, because before there is some garbage in serial
|
|
|
|
// whats get the cursor somewhere over the place
|
2024-04-13 14:39:16 +02:00
|
|
|
// output
|
2024-04-17 22:45:50 +02:00
|
|
|
Serial.println("420");
|
2024-04-13 14:39:16 +02:00
|
|
|
Serial.println(".:: CanGrow Start ::.");
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-03-31 04:41:50 +02:00
|
|
|
// initialise Wire for I2C
|
2024-03-30 01:25:58 +01:00
|
|
|
Wire.begin();
|
2024-04-07 00:46:27 +02:00
|
|
|
|
2024-03-31 04:41:50 +02:00
|
|
|
// initialise I2C display
|
2024-03-30 01:25:58 +01:00
|
|
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
|
|
|
|
display.clearDisplay();
|
|
|
|
display.display();
|
|
|
|
|
2024-03-31 04:41:50 +02:00
|
|
|
// set display settings
|
|
|
|
display.setTextSize(1);
|
|
|
|
display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
|
|
|
|
|
|
|
|
// display Logo
|
2024-03-30 01:25:58 +01:00
|
|
|
display.drawBitmap(0, 0, bmpCanGrow_Logo, 128, 32, WHITE);
|
|
|
|
display.display();
|
2024-04-13 02:38:39 +02:00
|
|
|
|
|
|
|
// reset chirp
|
|
|
|
writeI2CRegister8bit(0x20, 6); //TODO: Do only, when configured
|
2024-03-30 03:04:48 +01:00
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
// initialise DHT11
|
|
|
|
dht.begin(); //TODO: Do only, when configured
|
2024-04-22 01:58:31 +02:00
|
|
|
|
2024-04-13 19:02:12 +02:00
|
|
|
Serial.println("To wipe the EEPROM saved data, set D4 (PIN_WIPE) to LOW - NOW! (2 seconds left)");
|
2024-04-13 03:24:47 +02:00
|
|
|
// wait a few seconds to let the user pull D4 down to wipe EEPROM
|
|
|
|
// and we can enjoy the boot screen meanwhile :p
|
2024-04-14 15:13:27 +02:00
|
|
|
// meanwhile blink with the led onboad :)
|
|
|
|
// 333 * 6 =~ 2 seconds
|
2024-04-22 01:58:31 +02:00
|
|
|
|
|
|
|
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.display();
|
2024-04-18 16:04:40 +02:00
|
|
|
|
2024-04-14 15:13:27 +02:00
|
|
|
for(byte i = 0; i <= 6 ; i++) {
|
|
|
|
if(i % 2) {
|
|
|
|
digitalWrite(PIN_WIPE, LOW);
|
|
|
|
} else {
|
|
|
|
digitalWrite(PIN_WIPE, HIGH);
|
|
|
|
}
|
|
|
|
delay(333);
|
|
|
|
}
|
2024-04-15 01:53:54 +02:00
|
|
|
// set back to HIGH because thats the default
|
|
|
|
digitalWrite(PIN_WIPE, HIGH);
|
2024-04-14 15:13:27 +02:00
|
|
|
//delay(2000);
|
2024-04-13 15:46:40 +02:00
|
|
|
|
2024-04-13 03:24:47 +02:00
|
|
|
// read status from PIN_WIPE to WIPE
|
2024-04-13 15:46:40 +02:00
|
|
|
// when PIN_WIPE is set to LOW, wipe EEPROM
|
2024-04-13 19:02:12 +02:00
|
|
|
if(digitalRead(PIN_WIPE) == LOW) {
|
2024-04-13 15:46:40 +02:00
|
|
|
// wipe EEPROM
|
2024-04-13 03:24:47 +02:00
|
|
|
wipeEEPROM();
|
|
|
|
}
|
|
|
|
|
2024-04-13 19:02:12 +02:00
|
|
|
/*
|
|
|
|
* load EEPROM and Setup WiFi
|
|
|
|
*
|
|
|
|
* call loadEEPROM() which returns a bool
|
|
|
|
* When true, CanGrow is already configured and EEPROM values are applied
|
|
|
|
* When false, CanGrow is unconfigured and we need to run the setup assistant
|
2024-04-13 15:46:40 +02:00
|
|
|
*/
|
2024-04-13 19:02:12 +02:00
|
|
|
|
|
|
|
|
2024-04-13 21:41:36 +02:00
|
|
|
// load stored values from EEPROM and check what var configured is returned
|
2024-04-13 19:02:12 +02:00
|
|
|
if(loadEEPROM()) {
|
2024-04-13 21:41:36 +02:00
|
|
|
|
|
|
|
// connect to wifi
|
|
|
|
wifiConnect();
|
2024-04-13 03:24:47 +02:00
|
|
|
|
2024-04-13 21:41:36 +02:00
|
|
|
// configured is 0, setup Access Point
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// start an wifi accesspoint
|
|
|
|
wifiAp();
|
2024-04-16 01:51:24 +02:00
|
|
|
|
2024-04-13 03:24:47 +02:00
|
|
|
}
|
2024-04-16 01:51:24 +02:00
|
|
|
// set web handler
|
|
|
|
WebHandler();
|
2024-04-13 19:02:12 +02:00
|
|
|
// start webserver
|
2024-04-30 00:54:08 +02:00
|
|
|
webserver.begin();
|
2024-04-13 03:24:47 +02:00
|
|
|
|
2024-04-30 00:54:08 +02:00
|
|
|
Serial.println(".:: CanGrow Ready ::.");
|
2024-03-30 01:25:58 +01:00
|
|
|
}
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
|
|
|
|
/*
|
2024-04-13 02:38:39 +02:00
|
|
|
*
|
|
|
|
*
|
2024-04-09 13:45:33 +02:00
|
|
|
* Loop
|
|
|
|
*
|
2024-04-13 02:38:39 +02:00
|
|
|
*
|
2024-04-09 13:45:33 +02:00
|
|
|
*/
|
2024-03-30 01:25:58 +01:00
|
|
|
void loop() {
|
2024-04-18 03:09:16 +02:00
|
|
|
// var definition
|
|
|
|
unsigned int secondsSunrise = (SunriseHour * 60 * 60) + (SunriseMinute * 60);
|
|
|
|
unsigned int secondsToday = (timeClient.getHours() * 60 * 60) + (timeClient.getMinutes() * 60) + timeClient.getSeconds();
|
|
|
|
unsigned long currentRuntime = millis();
|
2024-04-18 15:45:17 +02:00
|
|
|
byte lightHours;
|
2024-04-30 00:54:08 +02:00
|
|
|
byte PINledPWM_tmp;
|
2024-04-18 03:09:16 +02:00
|
|
|
|
|
|
|
// first we call webserver handle client
|
2024-04-13 02:38:39 +02:00
|
|
|
webserver.handleClient();
|
2024-04-18 03:09:16 +02:00
|
|
|
|
2024-04-30 00:54:08 +02:00
|
|
|
// do every second when everything is configured and grow is started
|
2024-04-18 15:15:59 +02:00
|
|
|
if( (configured == true) && (strlen(GrowName) > 0) && (currentRuntime - outputPrevTime >= 1000) ){
|
2024-04-18 03:09:16 +02:00
|
|
|
|
2024-04-18 15:45:17 +02:00
|
|
|
// calculate acutal DayOfGrow
|
|
|
|
DayOfGrow = int(ceil(float((timeClient.getEpochTime() - GrowStart) / 60 / 60 / 24)));
|
|
|
|
// decide if we are in Veg or Bloom phase of grow
|
|
|
|
// when DayOfGrow is larger then DaysVeg we must be in Bloom
|
|
|
|
if(DayOfGrow > DaysVeg ) {
|
|
|
|
lightHours = LighthoursBloom;
|
|
|
|
} else {
|
|
|
|
lightHours = LighthoursVeg;
|
|
|
|
}
|
|
|
|
|
2024-04-30 02:31:55 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LED controlling
|
|
|
|
*/
|
|
|
|
|
2024-04-30 00:54:08 +02:00
|
|
|
// check if secondsToday is larger then secondsSunrise time AND if
|
|
|
|
// secondsToday is smaller then the sum of secondsSunrise + seconds of lightHours
|
2024-04-30 02:31:55 +02:00
|
|
|
if( ((secondsToday >= secondsSunrise) && (secondsToday <= ( secondsSunrise + (lightHours * 60 * 60))) ) ){
|
|
|
|
Serial.println("light on time");
|
|
|
|
|
|
|
|
// when SunFade is true, fade LED light. Otherwise just turn on or off
|
|
|
|
if( (SunFade == true) && (UseLEDrelais == false) && (secondsSunrise + SunFadeDuration * 60 >= secondsToday) ) {
|
|
|
|
// in the first n minutes of lighting (SunFadeDuration), we want
|
|
|
|
// to raise the light slowly to prevent stress from the plant
|
2024-04-30 00:54:08 +02:00
|
|
|
// convert progress sunrise to PWM value
|
2024-04-30 02:31:55 +02:00
|
|
|
PINledPWM_tmp = (SunFadeDuration * 60 - ((secondsSunrise + SunFadeDuration * 60) - secondsToday)) * PINledPWM / (SunFadeDuration * 60);
|
|
|
|
setOutput(1, PINledPWM_tmp);
|
|
|
|
Serial.print("sunrise PWM; ");
|
|
|
|
Serial.println(PINledPWM_tmp);
|
2024-04-30 00:54:08 +02:00
|
|
|
|
2024-04-30 02:31:55 +02:00
|
|
|
} else if( (SunFade == true) && (UseLEDrelais == false) && (secondsToday >= ((secondsSunrise + lightHours * 60 * 60) - SunFadeDuration * 60) ) ) {
|
2024-04-30 00:54:08 +02:00
|
|
|
// calculate progress sunset to PWM value
|
2024-04-30 02:31:55 +02:00
|
|
|
PINledPWM_tmp = (secondsSunrise + (lightHours * 60 * 60) - secondsToday) * PINledPWM / (SunFadeDuration * 60);
|
|
|
|
setOutput(1, PINledPWM_tmp);
|
|
|
|
Serial.print("sunset PWM: ");
|
|
|
|
Serial.println(PINledPWM_tmp);
|
2024-04-30 00:54:08 +02:00
|
|
|
|
|
|
|
} else {
|
2024-04-30 02:31:55 +02:00
|
|
|
Serial.println("just turn on the light");
|
2024-04-30 00:54:08 +02:00
|
|
|
// no sunrise or sunset, just keep the LED turned on
|
|
|
|
setOutput(1, PINledPWM);
|
|
|
|
}
|
2024-04-25 01:54:14 +02:00
|
|
|
|
2024-04-18 03:09:16 +02:00
|
|
|
} else {
|
2024-04-30 02:31:55 +02:00
|
|
|
Serial.println("good night time");
|
2024-04-18 03:09:16 +02:00
|
|
|
// turn off
|
2024-04-30 00:54:08 +02:00
|
|
|
setOutput(1, 0);
|
2024-04-18 03:09:16 +02:00
|
|
|
}
|
2024-04-30 00:54:08 +02:00
|
|
|
|
|
|
|
// current time gets previous time for new interval
|
2024-04-30 02:31:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------
|
|
|
|
// check if secondsToday is larger then secondsSunrise time AND if secondsToday is smaller then the sum of secondsSunrise + seconds of lightHours
|
|
|
|
if( (secondsToday >= secondsSunrise) && (secondsToday <= ( secondsSunrise + (lightHours * 60 * 60) ) )){
|
|
|
|
// turn on light
|
|
|
|
|
|
|
|
|
|
|
|
// TODO write a LED control function which takes also takes care of UseLEDrelais
|
|
|
|
//analogWrite(PINled, PINledPWM);
|
|
|
|
setOutput(1, PINledPWM);
|
|
|
|
} else {
|
|
|
|
// turn off
|
|
|
|
digitalWrite(PINled, LOW);
|
|
|
|
}
|
|
|
|
---------------------------------- */
|
2024-04-18 03:09:16 +02:00
|
|
|
outputPrevTime = currentRuntime;
|
2024-04-13 02:38:39 +02:00
|
|
|
}
|
2024-04-18 03:09:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
//delay(1000);
|
|
|
|
}
|
2024-04-13 19:02:12 +02:00
|
|
|
|
2024-04-15 01:53:54 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Web Handler
|
|
|
|
*/
|
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
void WebHandler() {
|
|
|
|
/*
|
2024-04-15 01:53:54 +02:00
|
|
|
* Webserver handlers
|
|
|
|
* here are the generic webserver handlers like 404 not found
|
2024-04-16 01:51:24 +02:00
|
|
|
* wifiSettings, ...
|
2024-04-15 01:53:54 +02:00
|
|
|
*
|
|
|
|
* if you are looking for the single webpages handler, have a look to
|
|
|
|
*
|
|
|
|
* WebHandler_unconfigured() and WebHandler_configured()
|
|
|
|
*/
|
2024-04-17 02:03:45 +02:00
|
|
|
// style.css
|
2024-04-17 19:41:10 +02:00
|
|
|
//webserver.on("/style.css", HTTP_GET, WEBstyleCSS);
|
2024-04-17 02:03:45 +02:00
|
|
|
|
|
|
|
// Web root
|
|
|
|
webserver.on("/", HTTP_GET, WEBroot);
|
|
|
|
|
2024-04-15 01:53:54 +02:00
|
|
|
// WiFi Stuff
|
2024-04-16 01:51:24 +02:00
|
|
|
webserver.on("/wifiSettings", HTTP_GET, WEBwifiSettings);
|
|
|
|
webserver.on("/wifiSettings/save", HTTP_POST, POSTwifiSettings);
|
2024-04-15 23:51:17 +02:00
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
// System stuff
|
|
|
|
webserver.on("/systemSettings", HTTP_GET, WEBsystemSettings);
|
|
|
|
webserver.on("/systemSettings/save", HTTP_POST, POSTsystemSettings);
|
|
|
|
|
|
|
|
// Grow stuff
|
|
|
|
webserver.on("/growSettings", HTTP_GET, WEBgrowSettings);
|
|
|
|
webserver.on("/growSettings/save", HTTP_POST, POSTgrowSettings);
|
2024-04-16 02:33:06 +02:00
|
|
|
// help
|
|
|
|
webserver.on("/help", HTTP_GET, WEBhelp);
|
2024-04-17 03:01:21 +02:00
|
|
|
|
|
|
|
// restart when NeedRestart is true
|
2024-04-18 15:15:59 +02:00
|
|
|
webserver.on("/system/restart", HTTP_GET, SysRestart);
|
|
|
|
// wipe eeprom triggered from WebGui
|
|
|
|
webserver.on("/system/wipe", HTTP_GET, SysWipe);
|
2024-04-16 01:51:24 +02:00
|
|
|
// does not work atm TODO
|
2024-04-17 02:03:45 +02:00
|
|
|
//webserver.on("/logout", [](){ webserver.send(401, "text/html", "logged out!"); });
|
2024-04-15 23:51:17 +02:00
|
|
|
|
2024-04-15 01:53:54 +02:00
|
|
|
// 404 handling
|
2024-04-15 23:51:17 +02:00
|
|
|
// 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"); });
|
2024-04-15 01:53:54 +02:00
|
|
|
webserver.onNotFound(WEB404);
|
2024-04-18 02:13:05 +02:00
|
|
|
|
|
|
|
// switching MOSFETs
|
2024-04-30 00:54:08 +02:00
|
|
|
webserver.on("/switch", HTTP_POST, POSTsetOutput);
|
2024-04-18 02:13:05 +02:00
|
|
|
|
2024-04-25 01:54:14 +02:00
|
|
|
// api stuff
|
|
|
|
webserver.on("/api/sensors", HTTP_GET, APIgetSensors);
|
2024-04-18 15:15:59 +02:00
|
|
|
|
2024-04-15 01:53:54 +02:00
|
|
|
}
|
|
|
|
|
2024-04-19 02:31:15 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* return functions, they return things for the web stuff
|
|
|
|
*/
|
2024-04-15 23:51:17 +02:00
|
|
|
|
2024-04-30 20:02:46 +02:00
|
|
|
String returnHTMLheader(String MenuEntry = "") {
|
|
|
|
String header;
|
|
|
|
header += FPSTR(HTMLheader);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// print actual time in header
|
|
|
|
//~ footer += "<script>replaceStr('CanGrowVer', 'CanGrow v";
|
|
|
|
//~ footer += CanGrowVer;
|
|
|
|
//~ footer += "');\n";
|
|
|
|
//~ footer += "replaceStr('MenuTime', '";
|
|
|
|
//~ footer += timeClient.getFormattedTime();
|
|
|
|
//~ footer += "');\n";
|
|
|
|
//~ footer += "highlightActiveMenu('M";
|
|
|
|
//~ footer += MenuEntry;
|
|
|
|
//~ footer += "');";
|
|
|
|
//~ footer += "</script>";
|
|
|
|
|
|
|
|
//~ // show the GrowName in the menu if set
|
|
|
|
//~ if(strlen(GrowName) > 0){
|
|
|
|
|
|
|
|
|
|
|
|
//~ footer += "<script>replaceStr('MenuGrowName', '🌱 ";
|
|
|
|
//~ footer += GrowName;
|
|
|
|
//~ footer += "');\n";
|
|
|
|
//~ // include the GrowName in the title
|
|
|
|
//~ footer += "document.title = 'CanGrow - ";
|
|
|
|
//~ footer += GrowName;
|
|
|
|
//~ footer += "';";
|
|
|
|
//~ footer += "</script>";
|
|
|
|
//~ }
|
|
|
|
|
|
|
|
//~ footer += FPSTR(HTMLfooter);
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2024-04-17 01:08:11 +02:00
|
|
|
// returns footer with javascript stuff
|
2024-04-19 02:31:15 +02:00
|
|
|
String returnHTMLfooter(String MenuEntry = "") {
|
2024-04-17 01:08:11 +02:00
|
|
|
String footer;
|
2024-04-18 03:38:10 +02:00
|
|
|
|
|
|
|
// print actual time in header
|
2024-04-19 02:31:15 +02:00
|
|
|
|
|
|
|
footer += "<script>replaceStr('CanGrowVer', 'CanGrow v";
|
|
|
|
footer += CanGrowVer;
|
|
|
|
footer += "');\n";
|
|
|
|
footer += "replaceStr('MenuTime', '";
|
2024-04-18 03:38:10 +02:00
|
|
|
footer += timeClient.getFormattedTime();
|
|
|
|
footer += "');\n";
|
2024-04-19 02:31:15 +02:00
|
|
|
footer += "highlightActiveMenu('M";
|
|
|
|
footer += MenuEntry;
|
|
|
|
footer += "');";
|
2024-04-18 03:38:10 +02:00
|
|
|
footer += "</script>";
|
|
|
|
|
2024-04-17 01:08:11 +02:00
|
|
|
// show the GrowName in the menu if set
|
|
|
|
if(strlen(GrowName) > 0){
|
2024-04-17 22:10:02 +02:00
|
|
|
|
2024-04-18 03:38:10 +02:00
|
|
|
|
2024-04-17 22:10:02 +02:00
|
|
|
footer += "<script>replaceStr('MenuGrowName', '🌱 ";
|
|
|
|
footer += GrowName;
|
2024-04-18 03:38:10 +02:00
|
|
|
footer += "');\n";
|
2024-04-17 22:10:02 +02:00
|
|
|
// include the GrowName in the title
|
|
|
|
footer += "document.title = 'CanGrow - ";
|
|
|
|
footer += GrowName;
|
2024-04-18 03:38:10 +02:00
|
|
|
footer += "';";
|
|
|
|
footer += "</script>";
|
2024-04-17 01:08:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
footer += FPSTR(HTMLfooter);
|
|
|
|
|
|
|
|
return footer;
|
|
|
|
}
|
2024-04-16 23:26:58 +02:00
|
|
|
|
2024-04-19 02:31:15 +02:00
|
|
|
|
2024-04-16 23:26:58 +02:00
|
|
|
/*
|
|
|
|
* 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;
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-16 23:26:58 +02:00
|
|
|
if(configured == true) {
|
|
|
|
if(savedValue == selectId) {
|
|
|
|
returnStr = "selected";
|
|
|
|
} else {
|
|
|
|
returnStr = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnStr;
|
|
|
|
}
|
2024-04-17 22:10:02 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-04-19 02:31:15 +02:00
|
|
|
|
|
|
|
void SysRestart() {
|
|
|
|
String body = FPSTR(HTMLheader);
|
|
|
|
// TODO only debug and development solution, remove this later
|
|
|
|
if( (webserver.hasArg("confirmed")) || (NeedRestart == true) ) {
|
|
|
|
body += "<h1>Restarting</h1>";
|
|
|
|
body += "<div class='infomsg'>After restart CanGrow will be connected to WiFi SSID<br><b>";
|
|
|
|
body += WIFIssid;
|
|
|
|
body += "</b><br>You get its IP-Address from the display or serial console.</div>";
|
|
|
|
body += returnHTMLfooter();
|
|
|
|
webserver.send(200, "text/html", body);
|
|
|
|
Serial.println("Restarting... see you soon space cowboy!");
|
|
|
|
delay(1000);
|
|
|
|
ESP.restart();
|
|
|
|
} else {
|
|
|
|
body += "<h1>Restart CanGrow</h1>";
|
|
|
|
body += "<div class='infomsg'>Do you want to restart CanGrow?";
|
|
|
|
body += "<br>Please confirm.";
|
|
|
|
body += "<form action='/system/restart'><input type='hidden' name='confirmed' value='true' /><input type='submit' value='Confirm restart' /></form>";
|
|
|
|
body += "</div>";
|
|
|
|
body += returnHTMLfooter();
|
|
|
|
webserver.send(200, "text/html", body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SysWipe() {
|
|
|
|
String body = FPSTR(HTMLheader);
|
|
|
|
// TODO only debug and development solution, remove this later
|
|
|
|
if(webserver.hasArg("confirmed")) {
|
|
|
|
body += "<div class='warnmsg'><h2>!! Wiping CanGrow's EEPROM !!</h2><br>Device will restart in a few seconds.</div>";
|
|
|
|
body += returnHTMLfooter();
|
|
|
|
webserver.send(200, "text/html", body);
|
|
|
|
wipeEEPROM();
|
|
|
|
} else {
|
|
|
|
body += "<h1>Wipeing EEPROM</h1>";
|
|
|
|
body += "<div class='warnmsg'>All settings will be removed!!<br>";
|
|
|
|
body += "<br>Please confirm wiping the EEPROM";
|
|
|
|
body += "<form action='/system/wipe'><input type='hidden' name='confirmed' value='true' /><input type='submit' value='Confirm wiping' /></form>";
|
|
|
|
body += "</div>";
|
|
|
|
body += returnHTMLfooter();
|
|
|
|
webserver.send(200, "text/html", body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO
|
|
|
|
* DOES NOT WORK WHEN CONNECTED TO EXISTING WIFI
|
|
|
|
* IDK WHY
|
|
|
|
*
|
2024-04-30 20:02:46 +02:00
|
|
|
|
|
|
|
* void WebAuth() {
|
|
|
|
*
|
|
|
|
* char webAuthRealm[] = "CanGrowRealm";
|
|
|
|
* if(!webserver.authenticate(WebUiUsername, WebUiPassword)) {
|
|
|
|
* String body = FPSTR(HTMLheader);
|
|
|
|
* body += "<h1>Login failed.</h1>";
|
|
|
|
* body += FPSTR(HTMLfooter);
|
|
|
|
* webserver.requestAuthentication(DIGEST_AUTH, webAuthRealm, body);
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* void WebAuthApi() {
|
|
|
|
*
|
2024-04-19 02:31:15 +02:00
|
|
|
* TODO
|
|
|
|
* DOES NOT WORK WHEN CONNECTED TO EXISTING WIFI
|
|
|
|
* IDK WHY
|
|
|
|
*
|
2024-04-30 20:02:46 +02:00
|
|
|
*
|
|
|
|
* char webAuthRealm[] = "CanGrowRealm";
|
|
|
|
* if(!webserver.authenticate(WebUiUsername, WebUiPassword)) {
|
|
|
|
* webserver.requestAuthentication(DIGEST_AUTH, webAuthRealm);
|
|
|
|
* }
|
|
|
|
* }
|
2024-04-19 02:31:15 +02:00
|
|
|
*/
|
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Web pages
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2024-04-13 21:41:36 +02:00
|
|
|
void WEB404() {
|
2024-04-13 02:38:39 +02:00
|
|
|
String body = FPSTR(HTMLheader);
|
2024-04-17 19:41:10 +02:00
|
|
|
body += "<div class='warnmsg'><h1>404 - not found</h1></div>";
|
2024-04-17 01:08:11 +02:00
|
|
|
body += returnHTMLfooter();
|
2024-04-15 23:51:17 +02:00
|
|
|
webserver.send(404, "text/html", body);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WEBlogout() {
|
|
|
|
String body = FPSTR(HTMLheader);
|
|
|
|
body += "<h1>you are logged out.</h1>";
|
|
|
|
body += FPSTR(HTMLfooter);
|
|
|
|
|
|
|
|
// TODO does not work atm
|
|
|
|
webserver.send(401, "text/html", body);
|
2024-04-13 21:41:36 +02:00
|
|
|
}
|
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
void WEBhelp() {
|
|
|
|
String body = FPSTR(HTMLheader);
|
|
|
|
body += FPSTR(HTMLhelp);
|
2024-04-19 02:31:15 +02:00
|
|
|
body += returnHTMLfooter("help");
|
2024-04-16 01:51:24 +02:00
|
|
|
webserver.send(200, "text/html", body);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Root pages
|
|
|
|
*/
|
|
|
|
|
|
|
|
void WEBroot() {
|
2024-04-17 03:01:21 +02:00
|
|
|
if(FirstRun == true) {
|
2024-04-17 02:03:45 +02:00
|
|
|
webserver.sendHeader("Location", String("/wifiSettings"), true);
|
|
|
|
webserver.send(302, "text/plain", "please configure wifiSettings first");
|
|
|
|
} else if(configured == false){
|
|
|
|
webserver.sendHeader("Location", String("/systemSettings"), true);
|
|
|
|
webserver.send(302, "text/plain", "please configure systemSettings first");
|
|
|
|
} else if(strlen(GrowName) < 1){
|
|
|
|
webserver.sendHeader("Location", String("/growSettings"), true);
|
|
|
|
webserver.send(302, "text/plain", "please configure growSettings first");
|
|
|
|
} else {
|
|
|
|
String body = FPSTR(HTMLheader);
|
|
|
|
|
2024-04-17 23:25:46 +02:00
|
|
|
body += "<h1>🌱 ";
|
2024-04-17 23:16:44 +02:00
|
|
|
body += GrowName;
|
|
|
|
body += "</h1>";
|
|
|
|
body += "Grow started: ";
|
|
|
|
body += returnStrDateFromEpoch(GrowStart);
|
|
|
|
body += "<br>";
|
|
|
|
body += "Day of Grow: ";
|
2024-04-18 15:45:17 +02:00
|
|
|
body += DayOfGrow;
|
2024-04-18 15:15:59 +02:00
|
|
|
body += "<br>";
|
2024-04-17 23:16:44 +02:00
|
|
|
body += "Soil Moisture: ";
|
|
|
|
body += getSoilmoisture(MoistureSensor_Type);
|
|
|
|
body += " %<br>";
|
|
|
|
body += "Humidity: ";
|
|
|
|
body += getHumidity();
|
2024-04-17 23:25:46 +02:00
|
|
|
body += " %<br>";
|
2024-04-17 23:16:44 +02:00
|
|
|
body += "Temperature: ";
|
|
|
|
body += getTemperature(TemperatureSensor_Type);
|
|
|
|
body += " °C<br>";
|
|
|
|
if(UsePump == true) {
|
|
|
|
body += "Pump water level: ";
|
|
|
|
switch(getWaterlevel()) {
|
|
|
|
case 0:
|
|
|
|
body += "OK";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
body += "Warning";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
body += "Critical";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-04-18 03:49:44 +02:00
|
|
|
body += "<br>";
|
|
|
|
body += "Growlight brightnes: ";
|
2024-04-30 00:54:08 +02:00
|
|
|
body += ((PINledPWM * 100) / 255);
|
2024-04-18 03:49:44 +02:00
|
|
|
body += " %<br>";
|
2024-04-18 02:13:05 +02:00
|
|
|
body += "<form method='post' action='/switch'>";
|
|
|
|
body += "MOSFET<select id='output' name='output' required>\n";
|
|
|
|
body += "<option disabled value='' selected hidden>---</option>\n";
|
|
|
|
body += "<option value='1'>LED</option>\n";
|
2024-04-30 02:31:55 +02:00
|
|
|
body += "<option value='2'>FAN</option>\n";
|
|
|
|
body += "<option value='3'>PUMP</option>\n";
|
2024-04-18 02:13:05 +02:00
|
|
|
body += "</select><br>";
|
|
|
|
|
|
|
|
body += "On/Off: <select id='state' name='state' required>\n";
|
|
|
|
body += "<option disabled value='' selected hidden>---</option>\n";
|
|
|
|
body += "<option value='1'>On</option>\n";
|
|
|
|
body += "<option value='0'>Off</option>\n";
|
|
|
|
body += "</select><br>\n";
|
2024-04-29 01:32:17 +02:00
|
|
|
|
2024-04-30 02:32:42 +02:00
|
|
|
body += "Intensity: <input type='range' id='OutputPWM' name='OutputPWM' min='1' max='255' value='255'/><br>\n";
|
2024-04-29 01:32:17 +02:00
|
|
|
|
2024-04-18 02:13:05 +02:00
|
|
|
body += "<input type='submit' value='Save'>\n";
|
|
|
|
body += "</form>";
|
|
|
|
|
|
|
|
|
2024-04-18 03:38:10 +02:00
|
|
|
|
2024-04-18 02:13:05 +02:00
|
|
|
|
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
body += returnHTMLfooter();
|
|
|
|
|
|
|
|
webserver.send(200, "text/html", body);
|
|
|
|
}
|
2024-04-16 01:51:24 +02:00
|
|
|
}
|
2024-04-14 15:43:18 +02:00
|
|
|
|
2024-04-15 01:53:54 +02:00
|
|
|
/*
|
|
|
|
* Config pages
|
|
|
|
*/
|
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
void WEBwifiSettings() {
|
2024-04-13 21:41:36 +02:00
|
|
|
byte ssidsAvail = WiFi.scanNetworks();
|
2024-04-13 02:38:39 +02:00
|
|
|
String body = FPSTR(HTMLheader);
|
2024-04-17 02:18:01 +02:00
|
|
|
if(FirstRun == true) {
|
2024-04-16 02:33:06 +02:00
|
|
|
body += "<h1>Welcome!</h1>";
|
|
|
|
body += "<p>CanGrow is actually unconfigured. You need to Setup your WiFi first down below.<br>";
|
|
|
|
body += "<br>After you entered your WiFi connection details, you need to restart and are step closer to your grow 🥦";
|
2024-04-16 01:51:24 +02:00
|
|
|
body += "<br>";
|
|
|
|
body += "</p>";
|
|
|
|
}
|
2024-04-16 12:31:03 +02:00
|
|
|
body += "<h2>WiFi config</h2>\n";
|
2024-04-17 01:44:41 +02:00
|
|
|
if(NeedRestart == true) {
|
|
|
|
body += FPSTR(HTMLneedRestart);
|
|
|
|
}
|
2024-04-15 23:51:17 +02:00
|
|
|
if(webserver.hasArg("success")) {
|
2024-04-17 01:44:41 +02:00
|
|
|
body += FPSTR(HTMLsuccess);
|
2024-04-15 23:51:17 +02:00
|
|
|
}
|
2024-04-18 15:15:59 +02:00
|
|
|
|
|
|
|
if(FirstRun == false) {
|
|
|
|
body += "<u>Current Settings:</u><br>";
|
|
|
|
body += "WiFi SSID: <b>";
|
|
|
|
body += WIFIssid;
|
|
|
|
body += "</b><br>\n";
|
|
|
|
body += "Use DHCP: <b>";
|
|
|
|
body += WIFIuseDHCP;
|
|
|
|
body += "</b><br>\n";
|
|
|
|
body += "IP address: <b>";
|
|
|
|
body += WiFi.localIP().toString();
|
|
|
|
body += "</b><br>\n";
|
|
|
|
body += "Subnet mask: <b>";
|
|
|
|
body += WiFi.subnetMask().toString();
|
|
|
|
body += "</b><br>\n";
|
|
|
|
body += "Gateway: <b>";
|
|
|
|
body += WiFi.gatewayIP().toString();
|
|
|
|
body += "</b><br>\n";
|
|
|
|
body += "DNS: <b>";
|
|
|
|
body += WiFi.dnsIP().toString();
|
|
|
|
body += "</b><br><br>\n";
|
|
|
|
}
|
|
|
|
|
2024-04-14 15:43:18 +02:00
|
|
|
body += "<p>Select your wifi network from the SSID list.<br>To use DHCP leave IP, Subnet, Gateway and DNS fields blank!</p>";
|
2024-04-16 01:51:24 +02:00
|
|
|
body += "<form method='post' action='/wifiSettings/save'>\n";
|
2024-04-15 23:51:17 +02:00
|
|
|
body += "SSID: <select id='WIFIssid' name='WIFIssid' required>\n";
|
|
|
|
body += "<option disabled value='' selected hidden>-Select your network-</option>";
|
2024-04-18 15:15:59 +02:00
|
|
|
|
2024-04-14 15:43:18 +02:00
|
|
|
// build option list for selecting wifi
|
2024-04-14 15:13:27 +02:00
|
|
|
Serial.println("Available Wifis: ");
|
2024-04-13 21:41:36 +02:00
|
|
|
for(int i = 0 ; i < ssidsAvail; i++) {
|
2024-04-14 15:13:27 +02:00
|
|
|
String wifiName = WiFi.SSID(i);
|
|
|
|
Serial.println(wifiName);
|
2024-04-16 23:26:58 +02:00
|
|
|
body += "<option value='" + wifiName + "'>";
|
|
|
|
body += wifiName + "</option>\n";
|
2024-04-13 21:41:36 +02:00
|
|
|
}
|
2024-04-14 15:13:27 +02:00
|
|
|
body += "</select><br>\n";
|
|
|
|
body += "Password: <input type='password' name='WIFIpassword'><br>\n";
|
|
|
|
body += "IP: <input type='text' name='WIFIip'><br>\n";
|
|
|
|
body += "Subnet mask: <input type='text' name='WIFInetmask'><br>\n";
|
2024-04-14 15:43:18 +02:00
|
|
|
body += "Gateway: <input type='text' name='WIFIgateway'><br>\n";
|
|
|
|
body += "DNS: <input type='text' name='WIFIdns'><br>\n";
|
2024-04-14 15:13:27 +02:00
|
|
|
body += "<input type='submit' value='Save'>\n";
|
|
|
|
body += "</form>\n";
|
2024-04-19 02:31:15 +02:00
|
|
|
body += returnHTMLfooter("wifiSettings");
|
2024-04-13 02:38:39 +02:00
|
|
|
|
|
|
|
webserver.send(200, "text/html", body);
|
2024-04-13 21:41:36 +02:00
|
|
|
}
|
2024-04-13 19:02:12 +02:00
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
void WEBsystemSettings() {
|
2024-04-17 02:03:45 +02:00
|
|
|
// if wifi settings are unconfigured, we cannot proceed with systemSettings
|
2024-04-17 02:18:01 +02:00
|
|
|
if(FirstRun == true) {
|
2024-04-17 02:03:45 +02:00
|
|
|
webserver.sendHeader("Location", String("/wifiSettings"), true);
|
|
|
|
webserver.send(302, "text/plain", "please configure wifiSettings first");
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String body = FPSTR(HTMLheader);
|
|
|
|
|
|
|
|
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 += FPSTR(HTMLsuccess);
|
|
|
|
}
|
|
|
|
body += "<p>here you can set which features and sensors you use<br>";
|
2024-04-16 12:31:03 +02:00
|
|
|
body += "</p>";
|
2024-04-17 02:03:45 +02:00
|
|
|
|
|
|
|
// form starts
|
|
|
|
body += "<form method='post' action='/systemSettings/save'>\n";
|
|
|
|
|
|
|
|
// UseFan bool
|
|
|
|
body += "Use fan: <select id='UseFan' name='UseFan' required>\n";
|
|
|
|
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
|
|
|
body += "<option value='1'" + returnStrSelected(UseFan, 1) + ">Yes</option>\n";
|
|
|
|
body += "<option value='0'" + returnStrSelected(UseFan, 0) + ">No</option>\n";
|
|
|
|
body += "</select><br>\n";
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
// UsePump bool
|
|
|
|
body += "Use pump: <select id='UsePump' name='UsePump' required>\n";
|
|
|
|
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
|
|
|
body += "<option value='1'" + returnStrSelected(UsePump, 1) + ">Yes</option>\n";
|
|
|
|
body += "<option value='0'" + returnStrSelected(UsePump, 0) + ">No</option>\n";
|
|
|
|
body += "</select><br>\n";
|
|
|
|
|
|
|
|
// UseLEDrelais bool
|
|
|
|
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";
|
2024-04-29 01:32:17 +02:00
|
|
|
|
|
|
|
// UseFANrelais bool
|
|
|
|
body += "Use relais for FAN: <select id='UseFANrelais' name='UseFANrelais' required>\n";
|
|
|
|
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
|
|
|
body += "<option value='1'" + returnStrSelected(UseFANrelais, 1) + ">Yes</option>\n";
|
|
|
|
body += "<option value='0'" + returnStrSelected(UseFANrelais, 0) + ">No</option>\n";
|
|
|
|
body += "</select><br>\n";
|
2024-04-17 02:03:45 +02:00
|
|
|
|
|
|
|
// TODO ugly. can this done be better?
|
|
|
|
// PumpOnTime int
|
2024-04-17 22:33:24 +02:00
|
|
|
body += "Pump on time: <input type='number' name='PumpOnTime' min='0' max='255' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += PumpOnTime;
|
|
|
|
body += "'required><br>\n";
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
// MoistureSensor_Type byte
|
|
|
|
body += "Moisture sensor type: <select id='MoistureSensor_Type' name='MoistureSensor_Type' required>\n";
|
|
|
|
if(configured == false) {
|
|
|
|
body += "<option disabled value='' selected hidden>---</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";
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
// SoilmoistureLow byte
|
2024-04-17 22:23:40 +02:00
|
|
|
body += "Soil moisture low: <input type='number' name='SoilmoistureLow' min='0' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += SoilmoistureLow;
|
|
|
|
body += "' required><br>\n";
|
|
|
|
|
2024-04-17 23:16:44 +02:00
|
|
|
// TemperatureSensor_Type byte
|
|
|
|
body += "Temperature sensor type: <select id='TemperatureSensor_Type' name='TemperatureSensor_Type' required>\n";
|
|
|
|
if(configured == false) {
|
|
|
|
body += "<option disabled value='' selected hidden>---</option>\n";
|
|
|
|
}
|
|
|
|
body += "<option value='1'" + returnStrSelected(TemperatureSensor_Type, 1) + ">DHT11/22</option>\n";
|
|
|
|
body += "<option value='2'" + returnStrSelected(TemperatureSensor_Type, 2) + ">I2C chirp</option>\n";
|
|
|
|
body += "</select><br>\n";
|
|
|
|
|
2024-04-30 00:54:08 +02:00
|
|
|
// NtpOffset int
|
|
|
|
body += "NTP offset: <input type='number' name='NtpOffset' min='-12' max='14' value='";
|
|
|
|
body += NtpOffset;
|
2024-04-17 02:03:45 +02:00
|
|
|
body+= "' required><br>\n";
|
2024-04-13 21:41:36 +02:00
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
body += "<input type='submit' value='Save'>\n";
|
|
|
|
body += "</form>\n";
|
|
|
|
|
2024-04-19 02:31:15 +02:00
|
|
|
body += returnHTMLfooter("systemSettings");
|
2024-04-17 02:03:45 +02:00
|
|
|
|
|
|
|
webserver.send(200, "text/html", body);
|
|
|
|
}
|
2024-04-13 21:41:36 +02:00
|
|
|
}
|
2024-04-15 01:53:54 +02:00
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
/*
|
|
|
|
* Grow pages
|
|
|
|
*/
|
|
|
|
void WEBgrowSettings() {
|
2024-04-17 02:03:45 +02:00
|
|
|
// 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 {
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
String body = FPSTR(HTMLheader);
|
|
|
|
|
|
|
|
if(strlen(GrowName) < 1) {
|
2024-04-17 03:01:21 +02:00
|
|
|
body += "<h1>Final step: Grow settings</h1>";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += "<p>Please configure all settings<br>";
|
|
|
|
body += "</p>";
|
2024-04-17 22:10:02 +02:00
|
|
|
GrowStart = timeClient.getEpochTime();
|
2024-04-17 02:03:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
body += "<h2>Grow Settings</h2>";
|
|
|
|
if(webserver.hasArg("success")) {
|
|
|
|
body += FPSTR(HTMLsuccess);
|
|
|
|
}
|
|
|
|
body += "<p>Here you can set everything grow related, like light hours, how much water, LED brightness<br>";
|
2024-04-16 12:31:03 +02:00
|
|
|
body += "</p>";
|
2024-04-17 02:03:45 +02:00
|
|
|
|
|
|
|
body += "<form method='post' action='/growSettings/save'>\n";
|
|
|
|
|
2024-04-17 01:08:11 +02:00
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
|
2024-04-18 15:15:59 +02:00
|
|
|
body += "Grow name: <input type='text' name='GrowName' maxlength='32' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += GrowName;
|
|
|
|
body+= "' required><br>\n";
|
|
|
|
|
2024-04-17 22:10:02 +02:00
|
|
|
|
|
|
|
// the input field, which calls javascript convertDateToEpoch() to write data to transmit to id GrowStart
|
|
|
|
body += "Grow start date: <input type='date' id='GrowStart_sel' onChange='convertDateToEpoch(\"GrowStart_sel\", \"GrowStart\");' value='";
|
|
|
|
body += returnStrDateFromEpoch(GrowStart);
|
|
|
|
body += "' required><br>\n";
|
|
|
|
|
|
|
|
body += "<input type='hidden' id='GrowStart' name='GrowStart' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += GrowStart;
|
2024-04-17 22:10:02 +02:00
|
|
|
body+= "' required>\n";
|
|
|
|
|
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
|
2024-04-17 22:23:40 +02:00
|
|
|
body += "Days of vegetation: <input type='number' name='DaysVeg' min='0' max='255' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += DaysVeg;
|
|
|
|
body+= "' required><br>\n";
|
|
|
|
|
2024-04-17 22:23:40 +02:00
|
|
|
body += "Days of bloom: <input type='number' name='DaysBloom' min='0' max='255' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += DaysBloom;
|
|
|
|
body+= "' required><br>\n";
|
|
|
|
|
2024-04-17 22:23:40 +02:00
|
|
|
body += "Hours light on vegetation: <input type='number' name='LighthoursVeg' min='0' max='255' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += LighthoursVeg;
|
|
|
|
body+= "' required><br>\n";
|
|
|
|
|
2024-04-17 22:23:40 +02:00
|
|
|
body += "Hours light on bloom: <input type='number' name='LighthoursBloom' min='0' max='255' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += LighthoursBloom;
|
|
|
|
body+= "' required><br>\n";
|
|
|
|
|
2024-04-17 22:23:40 +02:00
|
|
|
body += "Sunrise: <input class='inputShort' type='number' name='SunriseHour' min='0' max='23' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += SunriseHour;
|
|
|
|
body+= "' required>\n";
|
2024-04-17 22:23:40 +02:00
|
|
|
body += " <b>:</b> <input class='inputShort' type='number' name='SunriseMinute' min='0' max='59' value='";
|
2024-04-17 02:03:45 +02:00
|
|
|
body += SunriseMinute;
|
|
|
|
body+= "' required><br>\n";
|
|
|
|
|
2024-04-30 00:54:08 +02:00
|
|
|
// SunFade bool
|
|
|
|
body += "Fade in and out LED?: <select id='SunFade' name='SunFade' required>\n";
|
|
|
|
body += "<option value='1'" + returnStrSelected(SunFade, 1) + ">Yes</option>\n";
|
|
|
|
body += "<option value='0'" + returnStrSelected(SunFade, 0) + ">No</option>\n";
|
|
|
|
body += "</select><br>\n";
|
|
|
|
|
2024-04-30 02:31:55 +02:00
|
|
|
body += "Fading duration (minutes): <input type='number' name='SunFadeDuration' min='1' max='255' value='";
|
2024-04-30 00:54:08 +02:00
|
|
|
body += SunFadeDuration;
|
|
|
|
body+= "' required><br>\n";
|
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
if(UseLEDrelais == false) {
|
2024-04-30 00:54:08 +02:00
|
|
|
body += "Brightness LED: <input type='range' id='PINledPWM' name='PINledPWM' min='1' max='255' value='";
|
|
|
|
body += PINledPWM;
|
2024-04-17 02:03:45 +02:00
|
|
|
body += "'/><br>\n";
|
|
|
|
}
|
|
|
|
|
2024-04-29 01:32:17 +02:00
|
|
|
if(UseFANrelais == false) {
|
2024-04-30 00:54:08 +02:00
|
|
|
body += "Speed FAN: <input type='range' id='PINfanPWM' name='PINfanPWM' min='1' max='255' value='";
|
|
|
|
body += PINfanPWM;
|
2024-04-29 01:32:17 +02:00
|
|
|
body += "'/><br>\n";
|
|
|
|
}
|
|
|
|
|
2024-04-17 02:03:45 +02:00
|
|
|
body += "<input type='submit' value='Save'>\n";
|
|
|
|
body += "</form>\n";
|
2024-04-17 22:10:02 +02:00
|
|
|
body += FPSTR(JSconvertDateToEpoch);
|
2024-04-19 02:31:15 +02:00
|
|
|
body += returnHTMLfooter("growSettings");
|
2024-04-17 02:03:45 +02:00
|
|
|
|
|
|
|
webserver.send(200, "text/html", body);
|
2024-04-17 01:08:11 +02:00
|
|
|
}
|
2024-04-16 01:51:24 +02:00
|
|
|
}
|
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-13 03:24:47 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* POSTs
|
|
|
|
*
|
|
|
|
*/
|
2024-04-16 12:31:03 +02:00
|
|
|
|
|
|
|
void POSTgrowSettings() {
|
2024-04-17 01:08:11 +02:00
|
|
|
|
|
|
|
if(UseLEDrelais == true) {
|
|
|
|
// if a relais is used to turn on grow light, we force PWM to max val
|
2024-04-30 00:54:08 +02:00
|
|
|
PINledPWM = 255;
|
2024-04-17 01:08:11 +02:00
|
|
|
} else {
|
|
|
|
// otherwise just do PWM
|
2024-04-30 00:54:08 +02:00
|
|
|
PINledPWM = webserver.arg("PINledPWM").toInt();
|
2024-04-17 01:08:11 +02:00
|
|
|
}
|
|
|
|
|
2024-04-29 01:32:17 +02:00
|
|
|
if(UseFANrelais == true) {
|
|
|
|
// if a relais is used to turn on grow light, we force PWM to max val
|
2024-04-30 00:54:08 +02:00
|
|
|
PINfanPWM = 255;
|
2024-04-29 01:32:17 +02:00
|
|
|
} else {
|
|
|
|
// otherwise just do PWM
|
2024-04-30 00:54:08 +02:00
|
|
|
PINfanPWM = webserver.arg("PINfanPWM").toInt();
|
2024-04-29 01:32:17 +02:00
|
|
|
}
|
|
|
|
|
2024-04-17 01:08:11 +02:00
|
|
|
String GrowName_tmp = webserver.arg("GrowName");
|
|
|
|
GrowName_tmp.toCharArray(GrowName, 32);
|
|
|
|
|
|
|
|
|
|
|
|
GrowStart = webserver.arg("GrowStart").toInt();
|
|
|
|
DaysVeg = webserver.arg("DaysVeg").toInt();
|
|
|
|
DaysBloom = webserver.arg("DaysBloom").toInt();
|
|
|
|
LighthoursVeg = webserver.arg("LighthoursVeg").toInt();
|
|
|
|
LighthoursBloom = webserver.arg("LighthoursBloom").toInt();
|
|
|
|
SunriseHour = webserver.arg("SunriseHour").toInt();
|
|
|
|
SunriseMinute = webserver.arg("SunriseMinute").toInt();
|
2024-04-30 00:54:08 +02:00
|
|
|
SunFade = webserver.arg("SunFade").toInt();
|
|
|
|
SunFadeDuration = webserver.arg("SunFadeDuration").toInt();
|
2024-04-17 01:08:11 +02:00
|
|
|
|
|
|
|
// size is 32 byte
|
|
|
|
EEPROM.put(170, GrowName);
|
|
|
|
// size is 4 byte
|
|
|
|
EEPROM.put(202, GrowStart);
|
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.put(206, DaysVeg);
|
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.put(207, DaysBloom);
|
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.put(208, LighthoursVeg);
|
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.put(209, LighthoursBloom);
|
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.put(210, SunriseHour);
|
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.put(211, SunriseMinute);
|
|
|
|
// size is 1 byte
|
2024-04-30 00:54:08 +02:00
|
|
|
EEPROM.put(213, PINledPWM);
|
2024-04-29 01:32:17 +02:00
|
|
|
// size is 1 byte
|
2024-04-30 00:54:08 +02:00
|
|
|
EEPROM.put(216, PINfanPWM);
|
|
|
|
EEPROM.put(217, SunFade);
|
|
|
|
EEPROM.put(218, SunFadeDuration);
|
2024-04-17 01:08:11 +02:00
|
|
|
|
|
|
|
EEPROM.commit();
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-30 00:54:08 +02:00
|
|
|
//analogWrite(PINled, PINledPWM);
|
2024-04-13 03:24:47 +02:00
|
|
|
|
2024-04-16 12:31:03 +02:00
|
|
|
Serial.println(":: POSTgrowSettings ::");
|
|
|
|
|
2024-04-17 01:08:11 +02:00
|
|
|
Serial.print("GrowName: ");
|
|
|
|
Serial.println(GrowName);
|
|
|
|
Serial.print("GrowStart: ");
|
|
|
|
Serial.println(GrowStart);
|
|
|
|
Serial.print("DaysVeg: ");
|
|
|
|
Serial.println(DaysVeg);
|
|
|
|
Serial.print("DaysBloom: ");
|
|
|
|
Serial.println(DaysBloom);
|
|
|
|
Serial.print("LighthoursVeg: ");
|
|
|
|
Serial.println(LighthoursVeg);
|
|
|
|
Serial.print("LighthoursBloom: ");
|
|
|
|
Serial.println(LighthoursBloom);
|
|
|
|
Serial.print("SunriseHour: ");
|
|
|
|
Serial.println(SunriseHour);
|
|
|
|
Serial.print("SunriseMinute: ");
|
|
|
|
Serial.println(SunriseMinute);
|
2024-04-30 00:54:08 +02:00
|
|
|
Serial.print("PINledPWM: ");
|
|
|
|
Serial.println(PINledPWM);
|
|
|
|
Serial.print("PINfanPWM: ");
|
|
|
|
Serial.println(PINfanPWM);
|
2024-04-16 12:31:03 +02:00
|
|
|
|
|
|
|
webserver.sendHeader("Location", String("/growSettings?success"), true);
|
2024-04-18 02:24:49 +02:00
|
|
|
webserver.send(302, "text/plain", "growSettings/save: success!\n");
|
2024-04-16 12:31:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void POSTsystemSettings() {
|
2024-04-30 00:54:08 +02:00
|
|
|
NtpOffset = webserver.arg("NtpOffset").toInt();
|
2024-04-16 12:31:03 +02:00
|
|
|
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();
|
2024-04-17 01:08:11 +02:00
|
|
|
UseLEDrelais = webserver.arg("UseLEDrelais").toInt();
|
2024-04-29 01:32:17 +02:00
|
|
|
UseFANrelais = webserver.arg("UseFANrelais").toInt();
|
2024-04-17 23:16:44 +02:00
|
|
|
TemperatureSensor_Type = webserver.arg("TemperatureSensor_Type").toInt();
|
2024-04-17 01:44:41 +02:00
|
|
|
|
2024-04-16 12:31:03 +02:00
|
|
|
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
|
2024-04-30 00:54:08 +02:00
|
|
|
EEPROM.put(167, NtpOffset);
|
2024-04-16 23:26:58 +02:00
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.put(169, UseLEDrelais);
|
2024-04-17 23:16:44 +02:00
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.put(214, TemperatureSensor_Type);
|
2024-04-29 01:32:17 +02:00
|
|
|
// size is 1 byte
|
|
|
|
EEPROM.put(215, UseFANrelais);
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-18 15:26:50 +02:00
|
|
|
// write data to EEPROM
|
2024-04-16 12:31:03 +02:00
|
|
|
EEPROM.commit();
|
|
|
|
|
2024-04-18 15:27:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
// update time with new offset
|
2024-04-30 00:54:08 +02:00
|
|
|
timeClient.setTimeOffset(NtpOffset * 60 * 60);
|
2024-04-18 15:27:58 +02:00
|
|
|
timeClient.update();
|
|
|
|
|
|
|
|
Serial.println(":: POSTsystemSettings ::");
|
|
|
|
|
2024-04-30 00:54:08 +02:00
|
|
|
// when user uses an relais for LED control, we force here PINledPWM to 255
|
2024-04-18 15:26:50 +02:00
|
|
|
// to ensure nothing bad happens
|
|
|
|
if(UseLEDrelais == true) {
|
2024-04-30 00:54:08 +02:00
|
|
|
PINledPWM = 255;
|
|
|
|
EEPROM.put(213, PINledPWM);
|
2024-04-18 15:26:50 +02:00
|
|
|
EEPROM.commit();
|
2024-04-30 00:54:08 +02:00
|
|
|
Serial.println("UseLEDrelais is 1, forcing PINledPWM to max to prevent relais damage");
|
2024-04-18 15:26:50 +02:00
|
|
|
}
|
2024-04-29 01:32:17 +02:00
|
|
|
|
|
|
|
if(UseFANrelais == true) {
|
2024-04-30 00:54:08 +02:00
|
|
|
PINfanPWM = 255;
|
|
|
|
EEPROM.put(215, PINfanPWM);
|
2024-04-29 01:32:17 +02:00
|
|
|
EEPROM.commit();
|
2024-04-30 00:54:08 +02:00
|
|
|
Serial.println("UseFANrelais is 1, forcing PINfanPWM to max to prevent relais damage");
|
2024-04-29 01:32:17 +02:00
|
|
|
}
|
2024-04-18 15:27:58 +02:00
|
|
|
|
2024-04-16 12:31:03 +02:00
|
|
|
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);
|
2024-04-30 00:54:08 +02:00
|
|
|
Serial.print("NtpOffset: ");
|
|
|
|
Serial.println(NtpOffset);
|
2024-04-18 15:26:50 +02:00
|
|
|
Serial.print("UseLEDrelais: ");
|
|
|
|
Serial.println(UseLEDrelais);
|
2024-04-29 01:32:17 +02:00
|
|
|
Serial.print("UseFANrelais: ");
|
|
|
|
Serial.println(UseFANrelais);
|
2024-04-18 15:26:50 +02:00
|
|
|
Serial.print("TemperatureSensor_Type: ");
|
|
|
|
Serial.println(TemperatureSensor_Type);
|
2024-04-16 12:31:03 +02:00
|
|
|
|
2024-04-17 03:01:21 +02:00
|
|
|
if(strlen(GrowName) < 1) {
|
|
|
|
webserver.sendHeader("Location", String("/growSettings?success"), true);
|
|
|
|
} else {
|
|
|
|
webserver.sendHeader("Location", String("/systemSettings?success"), true);
|
|
|
|
}
|
|
|
|
|
2024-04-18 02:24:49 +02:00
|
|
|
webserver.send(302, "text/plain", "systemSettings/save: success!\n");
|
2024-04-16 12:31:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
void POSTwifiSettings() {
|
2024-04-13 03:24:47 +02:00
|
|
|
String WIFIssid_new = webserver.arg("WIFIssid");
|
|
|
|
String WIFIpassword_new = webserver.arg("WIFIpassword");
|
|
|
|
String WIFIip_new = webserver.arg("WIFIip");
|
|
|
|
String WIFInetmask_new = webserver.arg("WIFInetmask");
|
|
|
|
String WIFIgateway_new = webserver.arg("WIFIgateway");
|
2024-04-13 21:41:36 +02:00
|
|
|
String WIFIdns_new = webserver.arg("WIFIdns");
|
2024-04-13 03:24:47 +02:00
|
|
|
|
2024-04-14 15:13:27 +02:00
|
|
|
// convert String we got from webserver.arg to EEPROM friendly char[]
|
2024-04-13 03:24:47 +02:00
|
|
|
WIFIssid_new.toCharArray(WIFIssid, 32);
|
|
|
|
WIFIpassword_new.toCharArray(WIFIpassword, 64);
|
|
|
|
|
2024-04-14 15:13:27 +02:00
|
|
|
// if WIFIip_new was not set, we assume DHCP should be used
|
|
|
|
if(WIFIip_new.length() > 0) {
|
|
|
|
WIFIip.fromString(WIFIip_new);
|
|
|
|
WIFInetmask.fromString(WIFInetmask_new);
|
|
|
|
WIFIgateway.fromString(WIFIgateway_new);
|
|
|
|
WIFIdns.fromString(WIFIdns_new);
|
|
|
|
//
|
|
|
|
WIFIuseDHCP = false;
|
|
|
|
} else {
|
|
|
|
WIFIuseDHCP = true;
|
|
|
|
}
|
2024-04-13 14:39:16 +02:00
|
|
|
|
2024-04-17 01:44:41 +02:00
|
|
|
// restart is needed to load the new settings
|
|
|
|
NeedRestart = true;
|
2024-04-13 15:46:40 +02:00
|
|
|
|
2024-04-13 14:39:16 +02:00
|
|
|
EEPROM.put(0, WIFIssid);
|
|
|
|
EEPROM.put(32, WIFIpassword);
|
2024-04-13 15:46:40 +02:00
|
|
|
EEPROM.put(96, WIFIip);
|
|
|
|
EEPROM.put(112, WIFInetmask);
|
|
|
|
EEPROM.put(128, WIFIgateway);
|
2024-04-13 21:41:36 +02:00
|
|
|
EEPROM.put(144, WIFIdns);
|
2024-04-16 12:31:03 +02:00
|
|
|
EEPROM.put(160, WIFIuseDHCP);
|
2024-04-13 03:24:47 +02:00
|
|
|
EEPROM.commit();
|
2024-04-13 04:27:40 +02:00
|
|
|
|
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
Serial.println(":: POSTwifiSettings ::");
|
2024-04-13 04:27:40 +02:00
|
|
|
|
|
|
|
Serial.print("WIFIssid: ");
|
|
|
|
Serial.println(WIFIssid_new);
|
2024-04-13 14:39:16 +02:00
|
|
|
Serial.println(WIFIssid);
|
2024-04-13 04:27:40 +02:00
|
|
|
Serial.print("WIFIpassword: ");
|
|
|
|
Serial.println(WIFIpassword_new);
|
2024-04-13 14:39:16 +02:00
|
|
|
Serial.println(WIFIpassword);
|
2024-04-13 04:27:40 +02:00
|
|
|
Serial.print("WIFIip: ");
|
|
|
|
Serial.println(WIFIip_new);
|
|
|
|
Serial.print("WIFInetmask: ");
|
|
|
|
Serial.println(WIFInetmask_new);
|
|
|
|
Serial.print("WIFIgateway: ");
|
|
|
|
Serial.println(WIFIgateway_new);
|
2024-04-13 21:41:36 +02:00
|
|
|
Serial.print("WIFIdns: ");
|
|
|
|
Serial.println(WIFIdns_new);
|
2024-04-14 15:13:27 +02:00
|
|
|
Serial.print("WIFIuseDHCP: ");
|
|
|
|
Serial.println(WIFIuseDHCP);
|
2024-04-13 15:46:40 +02:00
|
|
|
|
2024-04-16 01:51:24 +02:00
|
|
|
|
|
|
|
webserver.sendHeader("Location", String("/wifiSettings?success"), true);
|
2024-04-18 02:24:49 +02:00
|
|
|
webserver.send(302, "text/plain", "wifiSettings/save: success!\n");
|
2024-04-13 04:27:40 +02:00
|
|
|
|
2024-04-13 03:24:47 +02:00
|
|
|
}
|
2024-04-18 02:13:05 +02:00
|
|
|
|
2024-04-30 00:54:08 +02:00
|
|
|
void POSTsetOutput() {
|
|
|
|
byte OutputState = webserver.arg("state").toInt();
|
|
|
|
byte OutputNr = webserver.arg("output").toInt();
|
2024-04-30 02:31:55 +02:00
|
|
|
//PINledPWM = webserver.arg("PINledPWM").toInt();
|
|
|
|
byte OutputPWM = webserver.arg("OutputPWM").toInt();
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-30 02:31:55 +02:00
|
|
|
Serial.println(":: POSTsetOutput ::");
|
2024-04-30 00:54:08 +02:00
|
|
|
Serial.print("OutputState: ");
|
|
|
|
Serial.println(OutputState);
|
|
|
|
Serial.print("OutputNr: ");
|
|
|
|
Serial.println(OutputNr);
|
2024-04-18 02:13:05 +02:00
|
|
|
|
2024-04-30 02:31:55 +02:00
|
|
|
if((OutputNr > 3) || (OutputNr < 1) || (OutputState > 255) || (OutputState < 0)) {
|
2024-04-18 02:13:05 +02:00
|
|
|
webserver.send(400, "text/plain", "not valid\n");
|
|
|
|
} else {
|
2024-04-30 00:54:08 +02:00
|
|
|
|
2024-04-30 02:31:55 +02:00
|
|
|
if(OutputState > 0){
|
|
|
|
setOutput(OutputNr, OutputPWM);
|
|
|
|
} else {
|
|
|
|
setOutput(OutputNr, 0);
|
|
|
|
}
|
|
|
|
|
2024-04-30 00:54:08 +02:00
|
|
|
webserver.sendHeader("Location", String("/?success"), true);
|
|
|
|
webserver.send(302, "text/plain", "switch: success!\n");
|
2024-04-18 02:13:05 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-25 01:54:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* API section
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// return as json all sensor readings
|
|
|
|
void APIgetSensors() {
|
|
|
|
|
|
|
|
JsonDocument jsonSensors;
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-25 01:54:14 +02:00
|
|
|
JsonArray arraySoilmoisture = jsonSensors["soilmoisture"].to<JsonArray>();
|
|
|
|
arraySoilmoisture.add(getSoilmoisture(1));
|
|
|
|
arraySoilmoisture.add(getSoilmoisture(2));
|
|
|
|
JsonArray arrayTemperature = jsonSensors["temperature"].to<JsonArray>();
|
|
|
|
arrayTemperature.add(getTemperature(1));
|
|
|
|
arrayTemperature.add(getTemperature(2));
|
|
|
|
jsonSensors["humidity"] = getHumidity();
|
|
|
|
jsonSensors["chirpLight"] = getLightchirp();
|
2024-04-13 02:38:39 +02:00
|
|
|
|
2024-04-25 01:54:14 +02:00
|
|
|
String body;
|
|
|
|
serializeJsonPretty(jsonSensors, body);
|
|
|
|
webserver.send(200, "text/json", body);
|
|
|
|
|
|
|
|
}
|
2024-04-13 02:38:39 +02:00
|
|
|
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-28 22:59:26 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* TODO LIST / NOTES
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* - avoid using javascript to set the GrowName in the Menu and the time
|
|
|
|
* as well
|
2024-04-29 02:23:49 +02:00
|
|
|
* - when PWM for fan is set, set fan speed to regulate humidity and
|
|
|
|
* temperature
|
|
|
|
* - re-organize EEPROM saved values.
|
2024-04-30 00:54:08 +02:00
|
|
|
* - prevent GrowStart to be in the future
|
2024-04-28 22:59:26 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2024-04-13 02:38:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* PLAYGROUND / TRASH
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
unsigned long currentTime = millis();
|
|
|
|
|
2024-04-07 23:56:17 +02:00
|
|
|
int valSoilmoisture0 = getSoilmoisture(0);
|
|
|
|
int valSoilmoisture1 = getSoilmoisture(1);
|
|
|
|
|
2024-04-08 01:28:15 +02:00
|
|
|
float valTemperature0 = getTemperature(0);
|
|
|
|
float valTemperature1 = getTemperature(1);
|
2024-04-07 23:56:17 +02:00
|
|
|
|
|
|
|
float valHumidity = getHumidity();
|
|
|
|
|
|
|
|
int valWaterlevel = getWaterlevel();
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
switch(valWaterlevel) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
digitalWrite(PINled, HIGH);
|
|
|
|
digitalWrite(PINpump, LOW);
|
|
|
|
digitalWrite(PINfan, LOW);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
digitalWrite(PINled, LOW);
|
|
|
|
digitalWrite(PINpump, HIGH);
|
|
|
|
digitalWrite(PINfan, LOW);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
digitalWrite(PINled, LOW);
|
|
|
|
digitalWrite(PINpump, LOW);
|
|
|
|
digitalWrite(PINfan, HIGH);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-13 02:38:39 +02:00
|
|
|
// OUTPUT
|
2024-04-09 13:45:33 +02:00
|
|
|
if(currentTime - outputPrevTime >= 1000) {
|
|
|
|
|
2024-04-07 00:46:27 +02:00
|
|
|
|
2024-03-31 05:53:57 +02:00
|
|
|
// set display cursor to top left
|
2024-03-30 03:04:48 +01:00
|
|
|
display.setCursor(0,0);
|
2024-03-31 05:53:57 +02:00
|
|
|
// display text
|
2024-03-30 03:04:48 +01:00
|
|
|
display.print("I2C: ");
|
2024-04-07 23:56:17 +02:00
|
|
|
display.print(valSoilmoisture1);
|
2024-03-30 03:04:48 +01:00
|
|
|
display.print(", ");
|
2024-04-07 23:56:17 +02:00
|
|
|
display.println(valTemperature1);
|
2024-03-31 05:53:57 +02:00
|
|
|
|
2024-04-07 00:46:27 +02:00
|
|
|
Serial.print("I2C: ");
|
2024-04-07 23:56:17 +02:00
|
|
|
Serial.print(valSoilmoisture1);
|
2024-04-07 00:46:27 +02:00
|
|
|
Serial.print(", ");
|
2024-04-07 23:56:17 +02:00
|
|
|
Serial.println(valTemperature1);
|
2024-04-07 00:46:27 +02:00
|
|
|
|
2024-03-30 01:25:58 +01:00
|
|
|
|
2024-03-30 03:04:48 +01:00
|
|
|
display.print("DHT11: ");
|
2024-04-07 23:56:17 +02:00
|
|
|
display.print(valTemperature0);
|
2024-03-30 03:04:48 +01:00
|
|
|
display.print(", ");
|
2024-04-07 23:56:17 +02:00
|
|
|
display.println(valHumidity);
|
2024-04-07 00:46:27 +02:00
|
|
|
|
|
|
|
Serial.print("DHT11: ");
|
2024-04-07 23:56:17 +02:00
|
|
|
Serial.print(valTemperature0);
|
2024-04-07 00:46:27 +02:00
|
|
|
Serial.print(", ");
|
2024-04-07 23:56:17 +02:00
|
|
|
Serial.println(valHumidity);
|
2024-03-30 01:25:58 +01:00
|
|
|
|
2024-03-31 04:41:50 +02:00
|
|
|
|
2024-03-31 05:53:57 +02:00
|
|
|
display.print("Water Status: ");
|
2024-04-07 23:56:17 +02:00
|
|
|
display.println(valWaterlevel);
|
2024-03-31 05:47:43 +02:00
|
|
|
|
2024-04-07 00:46:27 +02:00
|
|
|
Serial.print("Water Status: ");
|
2024-04-07 23:56:17 +02:00
|
|
|
Serial.println(valWaterlevel);
|
2024-03-31 04:41:50 +02:00
|
|
|
|
2024-04-07 01:18:54 +02:00
|
|
|
display.print("ASM: ");
|
2024-04-07 23:56:17 +02:00
|
|
|
display.print(valSoilmoisture0);
|
2024-04-07 02:10:45 +02:00
|
|
|
display.println(", ");
|
2024-04-07 01:18:54 +02:00
|
|
|
|
|
|
|
Serial.print("ASM: ");
|
2024-04-07 23:56:17 +02:00
|
|
|
Serial.println(valSoilmoisture0);
|
2024-04-07 01:18:54 +02:00
|
|
|
|
2024-03-31 05:53:57 +02:00
|
|
|
// print everything on the display
|
2024-03-31 04:41:50 +02:00
|
|
|
display.display();
|
|
|
|
|
2024-04-07 00:46:27 +02:00
|
|
|
Serial.println("Test");
|
2024-04-07 03:55:17 +02:00
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
outputPrevTime = currentTime;
|
2024-04-13 02:38:39 +02:00
|
|
|
*/
|
2024-04-07 23:56:17 +02:00
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
|
2024-04-07 23:56:17 +02:00
|
|
|
/* if(D6status == true) {
|
2024-04-07 03:55:17 +02:00
|
|
|
digitalWrite(PINled, LOW);
|
|
|
|
digitalWrite(PINpump, LOW);
|
|
|
|
digitalWrite(PINfan, LOW);
|
|
|
|
D6status = false;
|
|
|
|
Serial.println("D6 is off now");
|
|
|
|
} else {
|
|
|
|
digitalWrite(PINled, HIGH);
|
|
|
|
digitalWrite(PINpump, HIGH);
|
|
|
|
digitalWrite(PINfan, HIGH);
|
|
|
|
D6status = true;
|
|
|
|
Serial.println("D6 is ON now");
|
|
|
|
}
|
2024-04-07 23:56:17 +02:00
|
|
|
*/
|
2024-04-07 00:46:27 +02:00
|
|
|
|
2024-04-07 23:56:17 +02:00
|
|
|
/*
|
|
|
|
for(int dutyCycle = 0; dutyCycle < 255; dutyCycle++){
|
|
|
|
// changing the LED brightness with PWM
|
2024-04-09 13:45:33 +02:00
|
|
|
analogWrite(PINled, dutyCycle);
|
2024-04-07 23:56:17 +02:00
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// decrease the LED brightness
|
|
|
|
for(int dutyCycle = 255; dutyCycle > 0; dutyCycle--){
|
|
|
|
// changing the LED brightness with PWM
|
2024-04-09 13:45:33 +02:00
|
|
|
analogWrite(PINled, dutyCycle);
|
2024-04-07 23:56:17 +02:00
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2024-04-09 13:45:33 +02:00
|
|
|
|