Merge branch 'master' of https://github.com/0110/PlantCtrl into master

This commit is contained in:
c3ma 2020-10-14 17:09:33 +02:00
commit c470ba6dc7
7 changed files with 64 additions and 10 deletions

View File

@ -0,0 +1,9 @@
# Filesystem
## Configuration
Use the config-example.json from the host folder and create here a config.json file.
## HowTo upload
Start Platform.io
Open a new Atom-Terminal and generate the filesystem with the following command :
```pio run -t buildfs```
Upload this new generated filesystem with:
```pio run -t uploadfs```

View File

@ -18,19 +18,32 @@
"enabled": true "enabled": true
}, },
"settings": { "settings": {
"deepsleep": 60000, "deepsleep" : 60000,
"nightsleep" : 60000,
"pumpdeepsleep": 1000, "pumpdeepsleep": 1000,
"watermaxlevel": 50, "watermaxlevel": 50,
"watermin" : 5, "watermin" : 5,
"plants" : 3, "plants" : 3,
"moist0" : 2000,
"moist1" : 2000, "moist1" : 2000,
"moist2" : 2000, "moist2" : 2000,
"moist3" : 2000, "moist3" : 2000,
"moist4" : 2000,
"moist5" : 2000,
"moist6" : 2000,
"plant0MaxPumpTime": 1000,
"plant1MaxPumpTime": 1000, "plant1MaxPumpTime": 1000,
"plant2MaxPumpTime": 1000, "plant2MaxPumpTime": 1000,
"plant3MaxPumpTime": 1000, "plant3MaxPumpTime": 1000,
"plant4MaxPumpTime": 1000,
"plant5MaxPumpTime": 1000,
"plant6MaxPumpTime": 1000,
"plant0MinPumpIdle": 10000,
"plant1MinPumpIdle": 10000, "plant1MinPumpIdle": 10000,
"plant2MinPumpIdle": 10000, "plant2MinPumpIdle": 10000,
"plant3MinPumpIdle": 10000 "plant3MinPumpIdle": 10000,
"plant4MinPumpIdle": 10000,
"plant5MinPumpIdle": 10000,
"plant6MinPumpIdle": 10000
} }
} }

View File

@ -11,7 +11,7 @@
#ifndef CONTROLLER_CONFIG_H #ifndef CONTROLLER_CONFIG_H
#define CONTROLLER_CONFIG_H #define CONTROLLER_CONFIG_H
#define FIRMWARE_VERSION "1.0.1" #define FIRMWARE_VERSION "1.0.2"
#define ADC_TO_VOLT(adc) ((adc) * 3.3 ) / 4095) #define ADC_TO_VOLT(adc) ((adc) * 3.3 ) / 4095)
#define ADC_TO_VOLT_WITH_MULTI(adc, multi) (((adc) * 3.3 * (multi)) / 4095) #define ADC_TO_VOLT_WITH_MULTI(adc, multi) (((adc) * 3.3 * (multi)) / 4095)

View File

@ -18,4 +18,4 @@ board_build.partitions = huge_app.csv
; the latest development brankitchen-lightch (convention V3.0.x) ; the latest development brankitchen-lightch (convention V3.0.x)
lib_deps = https://github.com/homieiot/homie-esp8266.git#v3.0 lib_deps = https://github.com/homieiot/homie-esp8266.git#v3.0
OneWire OneWire
upload_port = /dev/ttyUSB0 upload_port = /dev/ttyUSB1

View File

@ -25,6 +25,7 @@ const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minut
bool mLoopInited = false; bool mLoopInited = false;
bool mDeepSleep = false; bool mDeepSleep = false;
bool mAlive=false; /**< Controller must not sleep */
int plantSensor1 = 0; int plantSensor1 = 0;
@ -67,6 +68,7 @@ HomieNode sensorLipo("lipo", "Battery Status", "Lipo");
HomieNode sensorSolar("solar", "Solar Status", "Solarpanel"); HomieNode sensorSolar("solar", "Solar Status", "Solarpanel");
HomieNode sensorWater("water", "WaterSensor", "Water"); HomieNode sensorWater("water", "WaterSensor", "Water");
HomieNode sensorTemp("temperature", "Temperature", "temperature"); HomieNode sensorTemp("temperature", "Temperature", "temperature");
HomieNode stayAlive("stay", "alive", "alive");
HomieSetting<long> deepSleepTime("deepsleep", "time in milliseconds to sleep (0 deactivats it)"); 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> deepSleepNightTime("nightsleep", "time in milliseconds to sleep (0 usese same setting: deepsleep at night, too)");
@ -238,7 +240,6 @@ void loopHandler() {
/* Pump is running, go to sleep after defined time */ /* Pump is running, go to sleep after defined time */
if (millis() >= ((MIN_TIME_RUNNING + 5) && if (millis() >= ((MIN_TIME_RUNNING + 5) &&
(deepSleepTime.get() > 0))) { (deepSleepTime.get() > 0))) {
Serial << "No sleeping activated (maximum)" << endl;
mDeepSleep = true; mDeepSleep = true;
} else if ((millis() >= ((MIN_TIME_RUNNING * MS_TO_S) + 0)) && } else if ((millis() >= ((MIN_TIME_RUNNING * MS_TO_S) + 0)) &&
(deepSleepTime.get() > 0)) { (deepSleepTime.get() > 0)) {
@ -285,6 +286,26 @@ bool switchGeneralPumpHandler(const int pump, const HomieRange& range, const Str
} }
} }
/**
* @brief Handle Mqtt commands to keep controller alive
*
* @param range multiple transmitted values (not used for this function)
* @param value single value
* @return true when the command was parsed and executed succuessfully
* @return false on errors when parsing the request
*/
bool aliveHandler(const HomieRange& range, const String& value) {
if (range.isRange) return false; // only one controller is present
if (value.equals("ON") || value.equals("On") || value.equals("1")) {
mAlive=true;
} else {
mAlive=false;
}
Serial << "HOMIE | Controller " << (mAlive ? " has coffee" : " is tired") << endl;
return true;
}
/** /**
* @brief Handle Mqtt commands for the pumpe, responsible for the first plant * @brief Handle Mqtt commands for the pumpe, responsible for the first plant
* *
@ -380,10 +401,10 @@ void setup() {
/* activate Wifi again */ /* activate Wifi again */
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS) { if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS) {
Serial << "HOMIE | Settings: " << HomieInternals::MAX_CONFIG_SETTING_SIZE << "/" << MAX_CONFIG_SETTING_ITEMS << endl; Serial << "HOMIE | Settings: " << HomieInternals::MAX_CONFIG_SETTING_SIZE << "/" << MAX_CONFIG_SETTING_ITEMS << endl;
Serial << " | Update Limits.hpp : MAX_CONFIG_SETTING_SIZE to " << MAX_CONFIG_SETTING_ITEMS << endl; Serial << " | Update Limits.hpp : MAX_CONFIG_SETTING_SIZE to " << MAX_CONFIG_SETTING_ITEMS << endl;
Serial << " | Update Limits.hpp : MAX_JSON_CONFIG_FILE_SIZE to 3000" << endl;
} }
Homie_setFirmware("PlantControl", FIRMWARE_VERSION); Homie_setFirmware("PlantControl", FIRMWARE_VERSION);
@ -479,6 +500,8 @@ void setup() {
.setDatatype("number") .setDatatype("number")
.setUnit("V"); .setUnit("V");
sensorWater.advertise("remaining").setDatatype("number").setUnit("%"); sensorWater.advertise("remaining").setDatatype("number").setUnit("%");
stayAlive.advertise("alive").setName("Alive").setDatatype("number").settable(aliveHandler);
} }
Homie.setup(); Homie.setup();
@ -645,8 +668,17 @@ void loop() {
} }
} else { } else {
if (!mAlive) {
Serial << (millis()/ 1000) << "s running; sleeeping ..." << endl; Serial << (millis()/ 1000) << "s running; sleeeping ..." << endl;
Serial.flush(); Serial.flush();
esp_deep_sleep_start(); esp_deep_sleep_start();
} else {
mDeepSleep = false;
if (((millis()) % 10000) == 0) {
/* tell everybody how long we are awoken */
stayAlive.setProperty("alive").send( String(millis()/ 1000) );
}
}
} }
} }