182 lines
4.4 KiB
C
182 lines
4.4 KiB
C
/*
|
|
*
|
|
* Constants
|
|
*
|
|
*/
|
|
const char* APssid = "CanGrow-unconfigured";
|
|
/*
|
|
* TODO - does not work atm. idk why.
|
|
* const char* APpass = "CanGrow";
|
|
const int APchannel = 6;
|
|
const bool APhidden = false;
|
|
*
|
|
*/
|
|
|
|
/*
|
|
*
|
|
* Variables
|
|
*
|
|
*/
|
|
|
|
// valSoilmoisture - contains the value of getSoilmoisture()
|
|
unsigned short valSoilmoisture;
|
|
// valTemperature - contains the value of getTemperature()
|
|
float valTemperature;
|
|
// valTemperature - contains the value of getHumidity()
|
|
float valHumidity;
|
|
// valWaterlevel - contains the value of getWaterlevel()
|
|
byte valWaterlevel;
|
|
// do we need a restart? (e.g. after wifi settings change)
|
|
bool NeedRestart;
|
|
bool FirstRun;
|
|
// which screen should be actually displayed
|
|
byte ScreenToDisplay = 0;
|
|
byte DisplayScreenDuration = 3;
|
|
// how many seconds actual screen got displayed
|
|
byte ScreenIterationPassed = 0;
|
|
|
|
bool MaintenanceMode = false;
|
|
unsigned long MaintenanceStarted = 0;
|
|
|
|
// helper variable to remember how many seconds the pump was
|
|
// already on within the actual watering cycle
|
|
byte PumpOnTimePassed = 0;
|
|
bool PumpOnManual = false;
|
|
|
|
// helper variable for pump control with soilmoisture
|
|
// average of last readings
|
|
unsigned short valSoilmoistureAvg = 0;
|
|
unsigned short valSoilmoistureAvg_tmp = 0;
|
|
byte valSoilmoistureAvg_count = 0;
|
|
//unsigned short
|
|
|
|
/*
|
|
* millis timer
|
|
*
|
|
*/
|
|
unsigned long outputPrevTime = 0;
|
|
|
|
|
|
/*
|
|
*
|
|
* EEPROM saved variables
|
|
*
|
|
*/
|
|
|
|
//
|
|
// WiFi
|
|
//
|
|
|
|
// if empty, CanGrow start in AccessPoint mode
|
|
char WIFIssid[32];
|
|
char WIFIpassword[64];
|
|
// WIFIuseDHCP - if true, get IP by DHCP
|
|
bool WIFIuseDHCP;
|
|
IPAddress WIFIip(192,168,4,20);
|
|
IPAddress WIFInetmask(255,255,255,0);
|
|
IPAddress WIFIgateway(192,168,4,254);
|
|
IPAddress WIFIdns(0,0,0,0);
|
|
//char WebUiUsername[16] = "cangrow";
|
|
//char WebUiPassword[32] = "cangrow";
|
|
|
|
//
|
|
// System
|
|
//
|
|
// configured - if false, let the user configure system settings first
|
|
bool configured = false;
|
|
// NTP Offset
|
|
short NtpOffset;
|
|
// MoistureSensor_Type - contains which moisture sensor to use
|
|
// 1: analog capacitive sensor
|
|
// 2: I2C chirp sensor from catnip electronics
|
|
byte MoistureSensor_Type;
|
|
// SoilmoistureLow - contains the value , when soil moisture is assumed to be low,
|
|
byte SoilmoistureLow = 80;
|
|
// UsePump - is the pump used? bool
|
|
// PumpMode (short) 1: Pump on every n days, 2: Pump on when Soilmoisture <= SoilmoistureLow, 3: Both
|
|
byte UsePump;
|
|
// UseFan - is the fan used? bool
|
|
// PumpOnTime in seconds
|
|
byte PumpOnTime = 3;
|
|
byte UseFan;
|
|
// In case the user uses no 12V LED on the LED output and an relais instead
|
|
// we have to disable PWM. So we ask here for what kind of light user is going
|
|
bool UseLEDrelais;
|
|
bool UseFANrelais;
|
|
// Which temperature sensor to use?
|
|
byte TemperatureSensor_Type;
|
|
unsigned short MaintenanceDuration = 300;
|
|
char Esp32CamIP[16];
|
|
// PumpLastOn (long) timestamp
|
|
unsigned long PumpLastOn;
|
|
bool OutputInvert;
|
|
unsigned short SoilmoistureWet;
|
|
unsigned short SoilmoistureDry;
|
|
|
|
|
|
|
|
//
|
|
// Grow Stuff
|
|
//
|
|
|
|
// GrowName - contains the name of the grow/plant. Up to 32 byte
|
|
// if empty, let the user setup grow settings first
|
|
char GrowName[32];
|
|
// GrowStart - contains unix timestamp from date where grow starts (00:00)
|
|
// unsigned long is 8 byte
|
|
unsigned long GrowStart;
|
|
// DayOfGrow contains on which day the grow is
|
|
byte DayOfGrow;
|
|
// DaysVeg - contains how many days to be in vegetation phase
|
|
byte DaysVeg = 35;
|
|
// DaysBloom - contains how many days to be in bloom phase
|
|
byte DaysBloom = 49;
|
|
// LighthoursVeg - contains how many hours the Growlight is on in Veg
|
|
byte LighthoursVeg = 16;
|
|
// LighthoursBloom - contains how many hours the Growlight is on in Bloom
|
|
byte LighthoursBloom = 12;
|
|
// SunriseHour - contains to which hour of day the growlight turns on
|
|
byte SunriseHour = 7;
|
|
// SunriseHour - contains to which minute of SunriseHour the growlight turns on
|
|
byte SunriseMinute = 0;
|
|
// PinLEDPWM - contains the PWM value for dimming the grow light
|
|
// default is 255 to ensure it is just on for the case UseLEDrelais is true
|
|
byte PinLEDPWM = 0;
|
|
byte PinFANPWM = 0;
|
|
byte PinFAN2PWM = 0;
|
|
|
|
// fade in and out sunrise and sunset?
|
|
bool SunFade;
|
|
byte SunFadeDuration = 30;
|
|
|
|
// PumpIntervalVeg (int) in days
|
|
byte PumpIntervalVeg = 5;
|
|
byte PumpIntervalBloom = 3;
|
|
|
|
/*
|
|
*
|
|
* NTP
|
|
*
|
|
*/
|
|
|
|
WiFiUDP ntpUDP;
|
|
NTPClient timeClient(ntpUDP);
|
|
|
|
/*
|
|
*
|
|
* Webserver
|
|
*
|
|
*/
|
|
|
|
ESP8266WebServer webserver(80);
|
|
ESP8266HTTPUpdateServer webUpdater;
|
|
|
|
/* I2C Stuff
|
|
*
|
|
*/
|
|
#define WIRE Wire
|
|
|
|
/*
|
|
* Display Stuff
|
|
*/
|
|
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &WIRE);
|