Skip to content

Latest commit

 

History

History
222 lines (162 loc) · 4.35 KB

README.md

File metadata and controls

222 lines (162 loc) · 4.35 KB

Greenhouse Telemetry

Some code experimenting with greenhouse telemetry and featured in my Greenhouse blog series

Grafana Screenshot Sample

Controller

  • Rasberry Pi 3 Model B v1.2
  • Programmed in Python (may change later)

Progress

Using Trello to keep track of work

Temp/Humidity

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 Temp/Humidity

Local weather data is retrieved from OpenWeatherMap API and recorded to DB for each reading for comparison.

Recording

Data is recorded to a local InfluxDB

Sample Weather JSON Data

{
	"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
}

Setup

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
Start InfluxDD
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
Start Grafana
sudo systemctl start grafana-server

or automatically run on startup

sudo systemctl enable grafana-server

Should be running on :3000

Setup a Python environment
python3 -m venv .venv
.venv/bin/pip3 install -r requirements.txt

Developing / Debugging

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

Running

Setup config

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>

Setup Database

Delete and recreate a new InfluxDb database

python init_db.py

Running Telemetry

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.

Experimental Control

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.

Plans

  • Add power generation and usage monitoring
  • Add light sensors, window state/control and perhaps automated watering
  • Add camera