Some code experimenting with greenhouse telemetry and featured in my Greenhouse blog series
- Rasberry Pi 3 Model B v1.2
- Programmed in Python (may change later)
Using Trello to keep track of work
We are using the AM2302 wired as follows
VCC -> Pi Pin 1
GND -> Pi Pin 6
DATA -> Pi Pin 7
and the Adafruit Python Drivers which can be set up as follows
(1) Clone the drivers repo
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
(2) Make sure python is up to date
sudo apt-get upgrade
sudo apt-get install build-essential python-dev
(3) Install the Adafruit drivers
sudo python setup.py install
(4) Run the test to make sure it worked
cd examples
sudo ./AdafruitDHT.py 2302 4
Local weather data is retrieved from OpenWeatherMap API and recorded to DB for each reading for comparison.
Data is recorded to a local InfluxDB
{
"coord": {
"lon": -0,
"lat": 0
},
"weather": [
{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}
],
"base": "stations",
"main": {
"temp": 10.49,
"pressure": 1014,
"humidity": 66,
"temp_min": 8,
"temp_max": 12.22
},
"visibility": 10000,
"wind": {
"speed": 3.1,
"deg": 240
},
"clouds": {
"all": 75
},
"dt": 1559121266,
"sys": {
"type": 1,
"id": 1442,
"message": 0.0063,
"country": "GB",
"sunrise": 1559101162,
"sunset": 1559162573
},
"timezone": 3600,
"id": 1,
"name": "Location",
"cod": 1
}
Install InfluxDB:
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
lsb_release -a
And with the Linux release codename
sudo apt install apt-transport-https
echo "deb https://repos.influxdata.com/debian <CODENAME> stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt update
sudo apt-get install influxdb
sudo service influxdb start
or automatically run on startup
sudo systemctl enable influxdb
Install Grafana
wget https://dl.grafana.com/oss/release/grafana_6.6.0_armhf.deb
sudo dpkg -i grafana_6.6.0_armhf.deb
sudo systemctl start grafana-server
or automatically run on startup
sudo systemctl enable grafana-server
Should be running on :3000
python3 -m venv .venv
.venv/bin/pip3 install -r requirements.txt
Install sshfs, link development machine to Pi by mounting the source directory and open in development environment
dnf install sshfs
mkdir /mnt/pi/gh
sshfs pi@<PI_IP>:/mnt/pi/gh /home/src/pi/gh
You will need to fill config.properties with
[Deploy]
name = "my deployment name"
[AM2302]
pin = <pin thhat AM2302 is attached to>
[Weather]
location = <location for querying>
open_weather_map_app_id = <your personal app.id>
Delete and recreate a new InfluxDb database
python init_db.py
Run the peripheral read loop
python read_cycle.py
which will start to fill up a specified InfluxDB
Running in a test environment (not on a Raspberry Pi with a AM2302 sensor) will require swapping out the used of TestClimateDataSource
for the AM2302DataSource
. I'm yet to figure out a nice way to automate this.
There's a simple control cycle in place in run_greenhouse.py. This will turn a light on during daylight hours and keep track of soil moisture. It also has the ability to turn on water which hasn't been included in the cycle quite yet.
- Add power generation and usage monitoring
- Add light sensors, window state/control and perhaps automated watering
- Add camera