Configuration moved into seperate header file

This commit is contained in:
c3ma 2020-10-16 15:03:51 +02:00
parent 8043263772
commit 368d7f050d
4 changed files with 64 additions and 40 deletions

View File

@ -13,7 +13,8 @@
"limits": "cpp", "limits": "cpp",
"streambuf": "cpp", "streambuf": "cpp",
"functional": "cpp", "functional": "cpp",
"string": "cpp" "string": "cpp",
"typeinfo": "cpp"
} }
} }
} }

View File

@ -0,0 +1,61 @@
/**
* @file HomieConfiguration.h
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2020-10-16
*
* @copyright Copyright (c) 2020
* All Settings, configurable in Homie
*/
#ifndef HOMIE_PLANT_CONFIG_H
#define HOMIE_PLANT_CONFIG_H
#include <Homie.h>
/**
*********************************** Attributes *******************************
*/
HomieNode plant0("plant0", "Plant 0", "Plant");
HomieNode plant1("plant1", "Plant 1", "Plant");
HomieNode plant2("plant2", "Plant 2", "Plant");
HomieNode plant3("plant3", "Plant 3", "Plant");
HomieNode plant4("plant4", "Plant 4", "Plant");
HomieNode plant5("plant5", "Plant 5", "Plant");
HomieNode plant6("plant6", "Plant 6", "Plant");
HomieNode sensorLipo("lipo", "Battery Status", "Lipo");
HomieNode sensorSolar("solar", "Solar Status", "Solarpanel");
HomieNode sensorWater("water", "WaterSensor", "Water");
HomieNode sensorTemp("temperature", "Temperature", "temperature");
HomieNode stayAlive("stay", "alive", "alive");
/**
*********************************** Settings *******************************
*/
HomieSetting<long> deepSleepTime("deepsleep", "time in milliseconds to sleep (0 deactivats it)");
HomieSetting<long> deepSleepNightTime("nightsleep", "time in milliseconds to sleep (0 usese same setting: deepsleep at night, too)");
HomieSetting<long> wateringDeepSleep("pumpdeepsleep", "time seconds to sleep, while a pump is running");
HomieSetting<long> waterLevelMax("watermaxlevel", "distance at maximum water level");
HomieSetting<long> waterLevelMin("waterminlevel", "distance at minimum water level (pumps still covered)");
HomieSetting<long> waterLevelWarn("waterlevelwarn", "warn if below this water level %");
HomieSetting<long> waterLevelVol("waterVolume", "ml between minimum and maximum");
/** Plant specific ones */
#define GENERATE_PLANT(plant) \
HomieSetting<long> mSensorDry##plant = HomieSetting<long>("moistdry##plant", "Moist sensor dry threshold"); \
HomieSetting<long> mSensorWet##plant = HomieSetting<long>("moistwet##plant", "Moist sensor wet threshold"); \
HomieSetting<long> mPumpAllowedHourRangeStart##plant = HomieSetting<long>("rangehourstart##plant", "Range pump allowed hour start"); \
HomieSetting<long> mPumpAllowedHourRangeEnd##plant = HomieSetting<long>("rangehourend##plant", "Range pump allowed hour end"); \
HomieSetting<bool> mPumpOnlyWhenLowLight##plant = HomieSetting<bool>("onlyWhenLowLightZ##plant", "Enable the Pump only, when there is light but not enought to charge battery"); \
HomieSetting<long> mPumpCooldownInHours##plant = HomieSetting<long>("cooldownpump##plant", "How long to wait until the pump is activated again");
GENERATE_PLANT(0);
GENERATE_PLANT(1);
#endif /* HOMIE_PLANT_CONFIG_H */

View File

@ -16,8 +16,6 @@ Plant::Plant(int pinSensor, int pinPump,int plantId) {
this->mPinSensor = pinSensor; this->mPinSensor = pinSensor;
this->mPinPump = pinPump; this->mPinPump = pinPump;
char plantIdChar = plantId+'0';
/* /*
{ {
char* name = "moistZdry"; char* name = "moistZdry";

View File

@ -13,7 +13,7 @@
#include "DS18B20.h" #include "DS18B20.h"
#include <Homie.h> #include <Homie.h>
#include "esp_sleep.h" #include "esp_sleep.h"
#include "HomieConfiguration.h"
const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */ const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */
@ -42,42 +42,6 @@ bool mConfigured = false;
RTC_DATA_ATTR int gBootCount = 0; RTC_DATA_ATTR int gBootCount = 0;
RTC_DATA_ATTR int gCurrentPlant = 0; /**< Value Range: 1 ... 7 (0: no plant needs water) */ RTC_DATA_ATTR int gCurrentPlant = 0; /**< Value Range: 1 ... 7 (0: no plant needs water) */
#if (MAX_PLANTS >= 1)
HomieNode plant0("plant0", "Plant 0", "Plant");
#endif
#if (MAX_PLANTS >= 2)
HomieNode plant1("plant1", "Plant 1", "Plant");
#endif
#if (MAX_PLANTS >= 3)
HomieNode plant2("plant2", "Plant 2", "Plant");
#endif
#if (MAX_PLANTS >= 4)
HomieNode plant3("plant3", "Plant 3", "Plant");
#endif
#if (MAX_PLANTS >= 5)
HomieNode plant4("plant4", "Plant 4", "Plant");
#endif
#if (MAX_PLANTS >= 6)
HomieNode plant5("plant5", "Plant 5", "Plant");
#endif
#if (MAX_PLANTS >= 7)
HomieNode plant6("plant6", "Plant 6", "Plant");
#endif
HomieNode sensorLipo("lipo", "Battery Status", "Lipo");
HomieNode sensorSolar("solar", "Solar Status", "Solarpanel");
HomieNode sensorWater("water", "WaterSensor", "Water");
HomieNode sensorTemp("temperature", "Temperature", "temperature");
HomieNode stayAlive("stay", "alive", "alive");
HomieSetting<long> deepSleepTime("deepsleep", "time in milliseconds to sleep (0 deactivats it)");
HomieSetting<long> deepSleepNightTime("nightsleep", "time in milliseconds to sleep (0 usese same setting: deepsleep at night, too)");
HomieSetting<long> wateringDeepSleep("pumpdeepsleep", "time seconds to sleep, while a pump is running");
HomieSetting<long> waterLevelMax("watermaxlevel", "distance at maximum water level");
HomieSetting<long> waterLevelMin("waterminlevel", "distance at minimum water level (pumps still covered)");
HomieSetting<long> waterLevelWarn("waterlevelwarn", "warn if below this water level %");
HomieSetting<long> waterLevelVol("waterVolume", "ml between minimum and maximum");
Ds18B20 dallas(SENSOR_DS18B20); Ds18B20 dallas(SENSOR_DS18B20);