From f415eeec61699c1357f58dbeabeffff43a4b9418 Mon Sep 17 00:00:00 2001 From: chl33 <64091421+chl33@users.noreply.github.com> Date: Sat, 19 Oct 2024 08:43:35 -0400 Subject: [PATCH] Make seconds between pump does configurable. (#16) Also: - version -> 0.7.2 - move example .ini files into place before platformio test build in CI --- .github/workflows/platformio-run.yaml | 3 +++ lib/watering/watering.cpp | 8 +++++--- lib/watering/watering.h | 1 + lib/watering/watering_constants.h | 2 +- secrets-usb.ini | 4 ---- secrets.ini | 3 --- src/main.cpp | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 secrets-usb.ini delete mode 100644 secrets.ini diff --git a/.github/workflows/platformio-run.yaml b/.github/workflows/platformio-run.yaml index 94aa83d..202fa86 100644 --- a/.github/workflows/platformio-run.yaml +++ b/.github/workflows/platformio-run.yaml @@ -20,5 +20,8 @@ jobs: - name: Install PlatformIO Core run: pip install --upgrade platformio + - name: Setup secrets for build + run: cp secrets.ini.example secrets.ini && cp secrets-usb.ini.example secrets-usb.ini + - name: Build PlatformIO Project run: pio run diff --git a/lib/watering/watering.cpp b/lib/watering/watering.cpp index 33ffd5e..d2e0b05 100644 --- a/lib/watering/watering.cpp +++ b/lib/watering/watering.cpp @@ -94,6 +94,8 @@ Watering::Watering(unsigned index, const char* name, uint8_t moisture_pin, uint8 kCfgSet, 0, m_cfg_vg), m_pump_dose_msec("pump_on_msec", 3 * kMsecInSec, units::kMilliseconds, "Pump on time", kCfgSet, 0, m_cfg_vg), + m_between_doses_sec("between_doses_sec", kPumpOffSec, units::kSeconds, "Wait between doses", + kCfgSet, 0, m_cfg_vg), m_state("watering_state", kStateWaitForNextCycle, "", "watering state", 0, m_vg), m_watering_enabled("watering_enabled", false, "watering enabled", kCfgSet, m_cfg_vg), m_reservoir_check_enabled("res_check_enabled", false, "reservior check enabled", kCfgSet, @@ -193,7 +195,7 @@ void Watering::loop() { // before the watering by more than they were during watering mode. // The time in seconds that the state machine might have switched out of watering mode. const float stateChangeSec = - static_cast(m_pump.lastOnMsec() + kPumpOffMsec) / kMsecInSec; + static_cast(m_pump.lastOnMsec()) / kMsecInSec + kPumpOffSec; const float secSinceStateChange = static_cast(nowMsec) / kMsecInSec - stateChangeSec; // The growing sigma value that should be kKernelWateringSec when the state changed. const float sigma1 = secSinceStateChange + kKernelWateringSec; @@ -231,7 +233,7 @@ void Watering::loop() { m_pump.turnOff(); // Don't consider turning the pump back on until it has been off for the // required amount of time. - if (msecSincePump < kPumpOffMsec) { + if (msecSincePump < (m_between_doses_sec.value() * kMsecInSec)) { setState(kStateEval, kWaitForNextCycleMsec, "pump not off for long enough"); } else if (reservoirCheckEnabled() && isReservoirEmpty()) { // Reservoir may be low, so don't consider using the pump. @@ -270,7 +272,7 @@ void Watering::loop() { if (m_reservoir_check) { m_reservoir_check->pumpRanForMsec(m_pump_dose_msec.value()); } - // Eval mode will wait until kPumpOffMsec until it will allow the pump to run again. + // Eval mode will wait until kPumpOffSec until it will allow the pump to run again. setState(kStateEval, kWaitForNextCycleMsec, "continue watering"); break; diff --git a/lib/watering/watering.h b/lib/watering/watering.h index ddad7c2..51ad63e 100644 --- a/lib/watering/watering.h +++ b/lib/watering/watering.h @@ -118,6 +118,7 @@ class Watering : public Module { FloatVariable m_max_moisture_target; FloatVariable m_min_moisture_target; FloatVariable m_pump_dose_msec; + FloatVariable m_between_doses_sec; StateVariable m_state; BoolVariable m_watering_enabled; BoolVariable m_reservoir_check_enabled; diff --git a/lib/watering/watering_constants.h b/lib/watering/watering_constants.h index 966a0ce..a768382 100644 --- a/lib/watering/watering_constants.h +++ b/lib/watering/watering_constants.h @@ -15,7 +15,7 @@ constexpr long kWaitBetweenPumpAndMoisureReadingMsec = kMsecInSec; // < 5% means the sensor is probably not in soil. constexpr float kMinPlausibleMoisture = 5.0f; // Always wait 15 minutes between pump cycles. -constexpr long kPumpOffMsec = 15 * kMsecInMin; +constexpr long kPumpOffSec = 15 * kSecInMin; // Wait 1 minute between checks in eval mode while waiting for moisture level to drop. constexpr long kWaitForNextCycleMsec = 1 * kMsecInMin; diff --git a/secrets-usb.ini b/secrets-usb.ini deleted file mode 100644 index d93c761..0000000 --- a/secrets-usb.ini +++ /dev/null @@ -1,4 +0,0 @@ -[secrets] -uploadProtocol = esptool -uploadPort = /dev/ttyUSB0 -uploadAuth = diff --git a/secrets.ini b/secrets.ini deleted file mode 100644 index 302476f..0000000 --- a/secrets.ini +++ /dev/null @@ -1,3 +0,0 @@ -[secrets] -udpLogTarget = 192, 168, 1, 10 -otaPassword = passwordhere diff --git a/src/main.cpp b/src/main.cpp index ef61446..0657762 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,7 @@ #include "watering.h" -#define SW_VERSION "0.7.1" +#define SW_VERSION "0.7.2" namespace {