The "chilli" plant water system is controlled by an Raspbery PI 3 with the Grove Base Hat and several connected sensors of Grove's ecosystem as well as Xiaomi Mi Flora Plant Sensor. The irrigation is electrically opererated by 5V water pumps which are controlled by 3.3V and 5V relays. Application Architecture:
- Water System Runner
- Plant Water System API
- Plant Water Admin APP (Progressive Web App) TODO
The water system runner is a simple Python 3.7 application running several jobs scheduled with the Python library Advanced Python Scheduler.
The first job is reading and persisting values from various sensors with a time stamp into a tinyDB table named sensor_history. Note: For certain sensor values it converts and round them to legbible units.
The second job is reading the most recent data entry (by time stamp) from table sensor_history and compares them with the defined threshold values. For plants that fall below this threshold value the water pump is started. The threshold values are defined in a table named plants_configuration among other configurations for sensor channels, relay pins and watering duration/iteration etc.
A third job is cleaning up the sensor_history database from old values. The max age of sensor_history values can be configured in a table named jobs_configuration.
All actions, warnings and errors are logged in water_system.log
An interface for the Chilli Plant Water System REST-API is implemented with FastAPI. It provides Endpoints to manage plant configurtions, read logs, start/pause the water system etc. See full API documentation: http://{API_URI}/docs.
The API is operated on a ASGI server by uvicorn
All actions, api accesses and errors are logged in api.log
- Groove Py: https://github.com/Seeed-Studio/grove.py
- temp & humidity sensor: https://github.com/Seeed-Studio/Seeed_Python_DHT
- sunlight sensor: https://github.com/Seeed-Studio/Seeed_Python_SI114X
- MiFlora: https://github.com/basnijholt/miflora
- Advanced Python Scheduler: https://apscheduler.readthedocs.io/en/stable/
- tinyDB: https://tinydb.readthedocs.io/en/stable/
- logging: https://docs.python.org/3/library/logging.html
- dateTime: https://docs.python.org/3/library/datetime.html
- FastAPI: https://fastapi.tiangolo.com/
- Allow sibling packages in python with virtual environment (venv): stack overflow thread
- Install all depenet libraries in venv (except for native python libraries)
- Activate venv:
source ~/Projects/plantWaterSystem/venv/bin/activate
- Start API server with water system in dev environment:
uvicorn api:app --reload
Use bash script start_water_system_main.sh
for running water system as standalone or start_water_system_with_api.sh
for running water system with api.