Skip to content

Commit

Permalink
Merge pull request #179 from calvinmclean/feature/controller-wifimanager
Browse files Browse the repository at this point in the history
Controller firmware overhaul (part 1)
  • Loading branch information
calvinmclean authored Sep 13, 2024
2 parents 1f7e538 + 02a8b1e commit c36b137
Show file tree
Hide file tree
Showing 58 changed files with 711 additions and 1,327 deletions.
5 changes: 5 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,8 @@ tasks:
dir: ./garden-app
cmds:
- flyctl deploy

pio:
dir: ./garden-controller
cmds:
- pio {{ .CLI_ARGS | default "run" }}
1 change: 0 additions & 1 deletion deploy/base/configs/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
topics = [
"+/data/water",
"+/data/light",
"+/data/moisture",
"+/data/temperature",
"+/data/humidity",
"+/data/logs",
Expand Down
3 changes: 0 additions & 3 deletions deploy/configs/garden-app/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ storage:
controller:
topic_prefix: "garden"
num_zones: 3
moisture_strategy: increasing
moisture_value: 0
moisture_interval: 30s
publish_water_event: true
publish_health: true
health_interval: 1m
1 change: 0 additions & 1 deletion deploy/configs/telegraf/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
topics = [
"+/data/water",
"+/data/light",
"+/data/moisture",
"+/data/temperature",
"+/data/humidity",
"+/data/logs",
Expand Down
3 changes: 0 additions & 3 deletions deploy/overlays/dev/configs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ mqtt:
controller:
topic_prefix: "garden"
num_zones: 3
moisture_strategy: increasing
moisture_value: 0
moisture_interval: 30s
publish_water_event: true
publish_health: true
health_interval: 1m
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Key features include:
- Control valves or devices (only limited by number of output pins)
- Queue up water events to water multiple zones one after the other
- Publish data and logs to InfluxDB via Telegraf + MQTT
- Respond to buttons to water individual zones and cancel watering

## Core Technologies
- Arduino/FreeRTOS
Expand Down
1 change: 0 additions & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@
* Examples
* [Indoor Herb Garden](indoor_example.md)
* [Indoor Hydroponics](hydroponics_example.md)
* [Sensors-Only Garden Add-on](sensors_only_example.md)
42 changes: 3 additions & 39 deletions docs/controller_advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ This section provides more details on the features, code organization, and confi
## Features
- Highly configurable and flexible
- Number of connected pumps/valves is only limited by the number of pins on your controller (and memory)
- Optionally control watering with connected buttons
- Collect moisture data from connected sensors
- Connect to MQTT to publish periodic health check-ins, moisture sensor data, logs, and event data for watering and lighting
- Connect to MQTT to publish periodic health check-ins, logs, and event data for watering and lighting

## Code Organization
This code is split up into different `.ino` and header files to improve organization and separate logic.
Expand All @@ -25,8 +23,6 @@ These are the basic options that are required and do not fit in specific categor

`QUEUE_SIZE`: maximum number of messages that can be queued in FreeRTOS queues. 10 is a sensible default that should never overflow unless you have a large number of Zones

`JSON_CAPACITY`: Size of JSON object calculated using Arduino JSON Assistant. This should not be changed

### MQTT/WiFi Options
These are all the configurations for setting up MQTT publish/subscribe.

Expand Down Expand Up @@ -60,52 +56,20 @@ The following options should be left as defaults, unless you have a good reason
#### Health Publishing Options
These options are used for enabled/configuring publishing of health check-ins to MQTT.

`ENABLE_MQTT_HEALTH`: Enables periodic publishing of health check-ins when defined

`MQTT_HEALTH_DATA_TOPIC`: Topic to publish health check-ins on

`HEALTH_PUBLISH_INTERVAL`: Time, in milliseconds, to wait between publishing of health check-ins

### Zone Options
These options are related to the actual pins and other necessary information for watering zones.

`DISABLE_WATERING`: Allows disabling Pump/Valve pins and doesn't listen on relevant MQTT topics. This allows a sensor-only Garden. If you are running this alongside a separate `garden-controller` that handles watering, please remember to change the `MQTT_CLIENT_NAME` to be different

`NUM_ZONES`: Number of zones connected to this Garden

`PUMP_PIN`: Optional configuration that makes organization better if you use the same pump for all zones

`ZONE_1`, `ZONE_2`, ..., `ZONE_N`: These are optional configurations that will be included in `ZONES` below, but make it a bit easier to organize the configuration. Use the following format:
```
{PUMP_PIN, VALVE_PIN, BUTTON_PIN, MOISTURE_SENSOR_PIN}
```

`ZONES`: This is a list of all zones managed by this controller. It contains the pin details for pump, valve, button, and moisture sensor. The button and sensor pins are ignored if not enabled (see sections below). If you are not using a pump, or not using a valve, just use the same pin for both. Use the following format:
`ZONES`: This is a list of all zones managed by this controller. It contains the pin details for following format:
```
{ {PUMP_PIN, VALVE_PIN, BUTTON_PIN, MOISTURE_SENSOR_PIN} }
{ ZONE1_PIN, ZONE2_PIN, ... }
```
**note**: Use `GPIO_NUM_MAX` to disable moisture sensing for only certain Zones.

`DEFAULT_WATER_TIME`: The default amount of time to water for, in milliseconds, if one is not defined in the command. This is also used to determine how long button-presses will water for

`LIGHT_PIN`: Pin used to control grow light relay

#### Button Options
These options allow optionally enabling button control. The buttons pins are defined as a part of the zones configuration.

`ENABLE_BUTTONS`: Enables reading input from buttons when defined

`STOP_BUTTON_PIN`: Button pins are usually defined for each individual zone, but this is a separate button that will cancel in-progress watering

#### Moisture Sensor Options
These options allow optionally enabling moisture data publishing. WiFi + MQTT are also required for this since the data must be published for storage. The value configurations below are used for calibrating the sensor. The moisture sensor pins are configured as part fo the zones configuration.

`ENABLE_MOISTURE_SENSORS`: Enables moisture sensors when defined

`MQTT_MOISTURE_DATA_TOPIC`: MQTT topic to publish moisture data to

`MOISTURE_SENSOR_AIR_VALUE`: Value to use for a dry sensor

`MOISTURE_SENSOR_WATER_VALUE`: Value to use for a fully-submerged sensor

`MOISTURE_SENSOR_INTERVAL`: Time, in milliseconds, to wait between sensor readings
13 changes: 1 addition & 12 deletions docs/controller_quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ In this interactive mode, the CLI will walk you through each required configurat
garden-app controller generate-config --config config.yaml
```

The following `config.yaml` file creates the necessary configuration for a 3-zone garden with moisture sensing, buttons, and light control:
The following `config.yaml` file creates the necessary configuration for a 3-zone garden with light control:

```YAML
mqtt:
Expand All @@ -49,25 +49,14 @@ controller:
zones:
- pump_pin: GPIO_NUM_18
valve_pin: GPIO_NUM_16
button_pin: GPIO_NUM_19
moisture_sensor_pin: GPIO_NUM_36
- pump_pin: GPIO_NUM_18
valve_pin: GPIO_NUM_17
button_pin: GPIO_NUM_21
moisture_sensor_pin: GPIO_NUM_39
- pump_pin: GPIO_NUM_18
valve_pin: GPIO_NUM_5
button_pin: GPIO_NUM_22
moisture_sensor_pin: GPIO_NUM_34
enable_moisture_sensor: true
enable_buttons: true
stop_water_button: GPIO_NUM_23
light_pin: GPIO_NUM_32
topic_prefix: "garden"
default_water_time: 5s
publish_health: true
health_interval: 1m
moisture_interval: 5s
```
## Advanced
Expand Down
39 changes: 1 addition & 38 deletions docs/hydroponics_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,7 @@ This has a very basic setup since it just consists of the ESP32 and a single rel
<!-- tabs:start -->
#### **`garden-controller/config.h`**
```c
#ifndef config_h
#define config_h

#define TOPIC_PREFIX "aerogarden"

#define QUEUE_SIZE 10

#define ENABLE_WIFI
#ifdef ENABLE_WIFI
#define MQTT_ADDRESS "192.168.0.107"
#define MQTT_PORT 30002
#define MQTT_CLIENT_NAME TOPIC_PREFIX
#define MQTT_WATER_TOPIC TOPIC_PREFIX"/command/water"
#define MQTT_STOP_TOPIC TOPIC_PREFIX"/command/stop"
#define MQTT_STOP_ALL_TOPIC TOPIC_PREFIX"/command/stop_all"
#define MQTT_LIGHT_TOPIC TOPIC_PREFIX"/command/light"
#define MQTT_LIGHT_DATA_TOPIC TOPIC_PREFIX"/data/light"
#define MQTT_WATER_DATA_TOPIC TOPIC_PREFIX"/data/water"

#define ENABLE_MQTT_HEALTH
#ifdef ENABLE_MQTT_HEALTH
#define MQTT_HEALTH_DATA_TOPIC TOPIC_PREFIX"/data/health"
#define HEALTH_PUBLISH_INTERVAL 60000
#endif

#define ENABLE_MQTT_LOGGING
#ifdef ENABLE_MQTT_LOGGING
#define MQTT_LOGGING_TOPIC TOPIC_PREFIX"/data/logs"
#endif

#define JSON_CAPACITY 48
#endif

#define NUM_ZONES 1
#define ZONES { { GPIO_NUM_18, GPIO_NUM_16, GPIO_NUM_19, GPIO_NUM_36 } }
#define DEFAULT_WATER_TIME 5000

#endif
WIP
```

#### **`garden-app/config.yaml`**
Expand Down
51 changes: 1 addition & 50 deletions docs/indoor_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ This small garden has worked really well for growing herbs or even cherry tomato

### 3D Printed
- Electronics case
- Buttons case
- Hose splitter
- Hose routing clips
- Grow light mounts
Expand All @@ -34,55 +33,7 @@ Then there are two 6-pin JST connectors that provide power (ground/5V) and 4 dat
<!-- tabs:start -->
#### **`garden-controller/config.h`**
```c
#ifndef config_h
#define config_h

#define TOPIC_PREFIX "garden"

#define QUEUE_SIZE 10

#define ENABLE_WIFI
#ifdef ENABLE_WIFI
#define MQTT_ADDRESS "192.168.0.107"
#define MQTT_PORT 30002
#define MQTT_CLIENT_NAME TOPIC_PREFIX
#define MQTT_WATER_TOPIC TOPIC_PREFIX"/command/water"
#define MQTT_STOP_TOPIC TOPIC_PREFIX"/command/stop"
#define MQTT_STOP_ALL_TOPIC TOPIC_PREFIX"/command/stop_all"
#define MQTT_LIGHT_TOPIC TOPIC_PREFIX"/command/light"
#define MQTT_LIGHT_DATA_TOPIC TOPIC_PREFIX"/data/light"
#define MQTT_WATER_DATA_TOPIC TOPIC_PREFIX"/data/water"

#define ENABLE_MQTT_HEALTH
#ifdef ENABLE_MQTT_HEALTH
#define MQTT_HEALTH_DATA_TOPIC TOPIC_PREFIX"/data/health"
#define HEALTH_PUBLISH_INTERVAL 60000
#endif

#define ENABLE_MQTT_LOGGING
#ifdef ENABLE_MQTT_LOGGING
#define MQTT_LOGGING_TOPIC TOPIC_PREFIX"/data/logs"
#endif

#define JSON_CAPACITY 48
#endif

#define NUM_ZONES 3
#define PUMP_PIN GPIO_NUM_18
#define ZONE_1 { PUMP_PIN, GPIO_NUM_16, GPIO_NUM_19, GPIO_NUM_36 }
#define ZONE_2 { PUMP_PIN, GPIO_NUM_17, GPIO_NUM_21, GPIO_NUM_39 }
#define ZONE_3 { PUMP_PIN, GPIO_NUM_5, GPIO_NUM_22, GPIO_NUM_34 }
#define ZONES { ZONE_1, ZONE_2, ZONE_3 }
#define DEFAULT_WATER_TIME 5000

#define LIGHT_PIN GPIO_NUM_32

#define ENABLE_BUTTONS
#ifdef ENABLE_BUTTONS
#define STOP_BUTTON_PIN GPIO_NUM_23
#endif

#endif
WIP
```

#### **`garden-app/config.yaml`**
Expand Down
1 change: 0 additions & 1 deletion docs/rest_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ A `Zone` represents a resource that can be watered. It may contain zero or more
"start_time": "2021-07-24T19:00:00-07:00"
}
```
- Control of watering based on moisture using `minimum_moisture` in the `water_schedule`. This sets the moisture percentage the zone's soil must drop below to enable watering
- On-demand control of watering using a `WaterAction` to the `/action` endpoint
- Access to a Zone's watering history from InfluxDB using `/history` endpoint

Expand Down
59 changes: 0 additions & 59 deletions docs/sensors_only_example.md

This file was deleted.

14 changes: 0 additions & 14 deletions docs/weather_control.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,6 @@ Temperature control usese the average daily high temperatures for scaling contro

In the above example, there is a baseline value of 30C (86F) and range of 10 degrees. If the average daily high temperatures in the last 3 days (72h) are >= 40C (104F), watering will be scaled to 1.5 (1h30m). If the average daily high is <= 20C (68F), watering is scaled to 0.5 (30m). The scaling is proportional between these values.

## Moisture Control

If a Zone is configured with a moisture sensor, it can be configured to use moisture-based watering. Unlike the other controls, this will skip watering completely rather than proportionally scaling it. The following example shows that watering should be skipped when soil moisture is > 50%.

```json
{
"weather_control": {
"moisture_control": {
"minimum_moisture": 50
}
}
}
```

## Viewing Weather and Scaling Data

Sometimes it might be hard to know what the total rainfall was or the recent average highs and it would also be useful to see how exactly that data is going to impact the next watering. Luckily, this information is included in the Zone API. The following example shows these relevant parts of a Zone response:
Expand Down
Loading

0 comments on commit c36b137

Please sign in to comment.