Truly own that which is yours!
If you are interested in collaborating please review the CONTRIBUTORS for commit styling guides.
Work in progress. We should be picking up some steam here to give the DYI community the features you deserve.
- Garden of Eden
Start with a clean install of Linux. Use the RaspberryPi Imager. Ensure ssh and wifi is setup. Once the image is written, pop the SDcard into the pi and ssh into it.
# clone repo
git clone [email protected]:iot-root/garden-of-eden.git
cd garden-of-eden
Update the .env
with mqtt broker info
cp .env-dist .env
nano .env
Install dependencies, and run services pigpiod, mqtt.service
./bin/setup.sh`
Ensure the pigpiod daemon is running
sudo systemctl status pigpiod
sudo systemctl status mqtt.service
Ensure your press is quick and within the time frame for the action to register correctly. The press time window can be modified directly in the
mqtt.py
file.
-
One Press (within 1 second):
- Action: Toggles the Lights on or off.
- Description: A single, swift press will illuminate or darken your space with ease.
-
Two Presses (within 1 second):
- Action: Toggles the Pump on or off.
- Description: Need to water the garden or fill up the pool? Double tap for action!
For homeassistant:
You need a mqtt broker either on the gardyn pi or homeassistant.
To install on the pi run
sudo apt-get install mosquitto mosquitto-clients
Add mqtt-broker username and password:
sudo mosquitto_passwd -c /etc/mosquitto/passwd <USERNAME>
Note: make sure to update the .env file which is used by
config.py
formqtt.py
Run sudo nano /etc/mosquitto/mosquitto.conf
and change the following lines to match:
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883
Here are some additional options that you could set in /etc/mosquitto/mosquitto.conf
:
pid_file /run/mosquitto/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
listener 1883 0.0.0.0
allow_anonymous false
password_file /etc/mosquitto/passwd
include_dir /etc/mosquitto/conf.d
Restart the service
sudo systemctl restart mosquitto
you just need to edit the .env
with the mosquitto username and password created above in /etc/mosquitto/passwd.
Check the configuration works:
sudo journalctl -xeu mosquitto.service
If you havent already, run ./bin/setup.sh
, this will install all OS dependencies, install the python libs, and run services pigpiod, mqtt.service
Ensure the pigpiod, mqtt, and broker daemon is running
sudo systemctl status pigpiod
sudo systemctl status mqtt.service
sudo systemctl status mosquitto
Go to your homeassistant instance: If your broker is on the gardyn pi, make sure to install the service mqtt, go to settings->devices&services->mqtt and add your gardyn pi host, port, username and password. The device should then appear in your homeassistant discovery settings.
To test locally on gardyn pi:
Pump:
mosquitto_pub -t "gardyn/light/command" -m "ON" -u gardyn -P "somepassword"
mosquitto_pub -t "gardyn/light/command" -m "OFF" -u gardyn -P "somepassword"
Light:
mosquitto_pub -t "gardyn/pump/command" -m "ON" -u gardyn -P "somepassword"
mosquitto_pub -t "gardyn/pump/command" -m "OFF" -u gardyn -P "somepassword"
Sensors:
Open two terminals on the gardyn pi, in one run:
mosquitto_sub -t "gardyn/water/level" -u gardyn -P "wowcow2019"
In the second gardyn pi terminal, run:
mosquitto_pub -t "gardyn/water/level/get" -m ""-r -u gardyn -P "wowcow2019"
### Testing
Activate python venv `source venv/bin/activate`
Start the Flask REST API `python run.py`
Test options:
```bash
# REST endpoints
./bin/api-test.sh
# unit test
python -m unittest -v
# individual tests
python tests/test_distance.py
Activate python venv source venv/bin/activate
Examples:
python app/sensors/distance/distance.py
python app/sensors/humidity/humidity.py
python app/sensors/light/light.py [--on] [--off] [--brightness INT%]
python app/sensors/pcb_temp/pcb_temp.py
python app/sensors/pump/pump.py [--on] [--off] [--speed INT%] [--factory-host STR%] [--factory-port INT%]
python app/sensors/temperature/temperature.py
Activate python venv source venv/bin/activate
Then Run python run.py
, this will print the ip to send requests.
Note: if run.py errors with: AttributeError: module 'dotenv' has no attribute 'find_dotenv'
pip uninstall python-dotenv
python run.py
[GET] http://<pi-ip>:5000/distance
[GET] http://<pi-ip>:5000/humidity
[POST] http://<pi-ip>:5000/light/on
[POST] http://<pi-ip>:5000/light/off
[POST] http://<pi-ip>:5000/light/brightness body:{"value": 50 }
[GET] http://<pi-ip>:5000/light/brightness
[GET] http://<pi-ip>:5000/temperature
[GET] http://<pi-ip>:5000/pcb-temp
[POST] http://<pi-ip>:5000/pump/on
[POST] http://<pi-ip>:5000/pump/off
[POST] http://<pi-ip>:5000/pump/speed body:{"value": 50 }
[GET] http://<pi-ip>:5000/pump/speed
[GET] http://<pi-ip>:5000/pump/stats
Export this Postman collection, add to your private workspace, add the pi-ip
env variable and you should be good to go.
Run crontab -e
, select your preferred editor and then add the following job. Edit as needed.
Note: update your paths for the following...
# †urn on lights at 6am, 9am, 5pm, and turn off at 8pm
0 6 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/light/light.py --on --brightness 50
0 9 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/light/light.py --on --brightness 70
0 17 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/light/light.py --on --brightness 50
0 20 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/light/light.py --off
# Pump run at 8am for 5 minutes
0 8 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/pump/pump.py --on --speed 100
5 8 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/pump/pump.py --off
# Pump run at 4pm 5 minutes
0 16 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/pump/pump.py --on --speed 100
5 16 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/pump/pump.py --off
# Pump run at 9pm for 5 minutes
0 21 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/pump/pump.py --on --speed 100
5 21 * * * /home/gardyn/projects/garden-of-eden/venv/bin/python /home/gardyn/projects/garden-of-eden/app/sensors/pump/pump.py --off
# Collect sensor data every 30 mins
*/30 * * * * /home/gardyn/projects/garden-of-eden/bin/get-sensor-data.sh
Depending on the system you have, here is a breakdown of the hardware.
Notes:
- GPIO num is different than pin number. See (https://pinout.xyz/)
- temp/humidity sensor AM2320 at address of
0x38
- motor power usage sensor INA219 at address of
0x40
- pcb temp sensor PCT2075 at address
pf 0x48
When you run sudo i2cdetect -y 1
, you should see something like:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- 38 -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
LED full spectrum lights.
- Lights are driven by PWM duty and a frequency of 8 kHz.
- The pump is driven by PWM with max duty of 30% and frequency of 50 Hz
- There is a current sensor to measure pump draw and a overtemp sensor to determine if board monitor PCB temp.
Notes:
- Pump duty cycle is limited, likely full on is too much current draw for the system.
Two USB cameras.
- image capture with fswebcam
- /dev/video0
- /dev/video1
Uses the ultrasonic distance sensor DYP-A01-V2.0.
- GPIO-19 | PIN-35: water level in (trigger)
- GPIO-26 | PIN-37: water level out (echo)
- Uses time between the echo and response to deterine the distances.
<section incomplete>
Incase you need to troubleshoot any problems with your system.
For better performance, the Pi Zero can be replaced with a Pi Zero 2. This will enable the use of VS Code Remote Server to edit files and debug the python code remotely. The VS Code remote server uses OpenSSH and the minimum architecture is ARMv7.
Buy one without a header, you will need to solder one on in the opposite direction.
Minimum python version of 3.6 to support printf()
Reading sensor values with inherently long delays and responding to the REST API. To minimize the delay in subsequent readings the value is cached and given if another read occurs within two seconds.
Using gpiozero
to leverage pigpio
daemon which is hardware driven and more efficient.This ensures better accuracy of the distance sensor and is less cpu intensive when using PWMs.
<gardyn-of-eden>
├── run.py
├── app
│ ├── __init__.py
│ └── sensors
│ ├── config.py
│ ├── distance
│ │ ├── distance.py
│ │ ├── __init__.py
│ │ └── routes.py
│ ├── __init__.py
│ ├── light
│ │ ├── __init__.py
│ │ ├── light.py
│ │ └── routes.py
│ └── pump
│ ├── __init__.py
│ ├── pump.py
│ └── routes.py
└── tests
├── __init__.py
├── test_distance.py
├── test_light.py
└── test_pump.py