Garden sensors/watering with web interface
Posted: Tue Jun 21, 2016 8:10 pm
Hello!
I'm thinking of bringing out my old Pi for a gardening project.
What I want to do (These are wishes, I'm open for compromise if some things seem too complicated. They are somewhat ordered in descending priority.) :
1. Log soil and air temperature and soil moisture data, say once every five or ten minutes, and store in a database.
2. Use this data to control one or more pumps connected to a watering system.
3. Display sensor data and watering statistics on a web interface.
4. Control moisture thresholds, extra watering etc through the same interface.
5. Use a web camera to take pictures of the garden for a time-lapse
What hardware I already have:
- Original version Raspberry Pi model B with 256 mb ram. I'll probably have this outdoors in some waterproof container and connect it via wifi.
- Odroid U3 currently acting as an HTPC/file server. I'd like to be able to continue using it as such. Will be indoors connected to LAN and USB hard drive.
- Some temperature sensors working through dallas one wire protocol.
Now, a while back I started doing a test setup with just "objectives" 1 and 3. I used python to log data into a SQLite database and then PHP and Nginx to display this on the web with google charts. Being a hobbyist and never having used any of these technologies I must admit it took some effort and the project kind of stranded when I succeeded. To not waste time learning new technologies only to realize they were not meant to do this at all, I thought I should discuss the whole project with some people who actually know what they're doing first.
These are my first thoughts about how to set it up this time:
- Raspberry Pi running a c++ or python program logging sensor data into a database located on the Odroid (i'm probably more comfortable writing in c++ but the code should be simple so it mostly depends on which one is easier to hook up to both the sensors and the DB)
- Odroid running the database. Also running nginx and PHP displaying the data. Settings and "commands" to the system can also be loaded into a separate table on the db.
- A separate program on the Raspberry Pi that intermittently reads the commands and the sensor data and figures out if its time to water or not. Also loads watering statistics into a third table of the DB.
Considerations:
- The whole thing would probably have been a lot easier using only one computer. However, I'm quite certain the Pi will have a hard time serving PHP graphs from data with 5 or 10 minute precision spanning months or years. Furthermore I already have an nginx/PHP web server on the odroid.
- Connecting to the database over network might be hard. mySQL has this feature but I'm worried it will take to much resources. SQLite can only do this via network file systems but they say this is resource inefficient. If I'm watching something on the Odroid I don't want it to hang every five minutes just because the Pi is accessing the database. An option might be to cache the data on the Pi and flush it to the Odroid every night at 4 am or so. Data transfer the other way will suffer though (only reacting to a command the next day) but this might be solved by placing the "commands" DB on the Pi and having the PHP control panel access it when needed but this needs network file systems both ways. How much resources does that take?
- Thought about making two C++ programs that communicated directly through network but decided that it would be too complicated. Correct assumption?
- Are there any existing technologies doing what I want that I can benefit from?
- What soil sensors are the best? Should I buy an ADC and make my own?
- I have barely begun thinking of how to connect the pump(s).
So these are my thoughts, what are yours?
Björn
I'm thinking of bringing out my old Pi for a gardening project.
What I want to do (These are wishes, I'm open for compromise if some things seem too complicated. They are somewhat ordered in descending priority.) :
1. Log soil and air temperature and soil moisture data, say once every five or ten minutes, and store in a database.
2. Use this data to control one or more pumps connected to a watering system.
3. Display sensor data and watering statistics on a web interface.
4. Control moisture thresholds, extra watering etc through the same interface.
5. Use a web camera to take pictures of the garden for a time-lapse
What hardware I already have:
- Original version Raspberry Pi model B with 256 mb ram. I'll probably have this outdoors in some waterproof container and connect it via wifi.
- Odroid U3 currently acting as an HTPC/file server. I'd like to be able to continue using it as such. Will be indoors connected to LAN and USB hard drive.
- Some temperature sensors working through dallas one wire protocol.
Now, a while back I started doing a test setup with just "objectives" 1 and 3. I used python to log data into a SQLite database and then PHP and Nginx to display this on the web with google charts. Being a hobbyist and never having used any of these technologies I must admit it took some effort and the project kind of stranded when I succeeded. To not waste time learning new technologies only to realize they were not meant to do this at all, I thought I should discuss the whole project with some people who actually know what they're doing first.
These are my first thoughts about how to set it up this time:
- Raspberry Pi running a c++ or python program logging sensor data into a database located on the Odroid (i'm probably more comfortable writing in c++ but the code should be simple so it mostly depends on which one is easier to hook up to both the sensors and the DB)
- Odroid running the database. Also running nginx and PHP displaying the data. Settings and "commands" to the system can also be loaded into a separate table on the db.
- A separate program on the Raspberry Pi that intermittently reads the commands and the sensor data and figures out if its time to water or not. Also loads watering statistics into a third table of the DB.
Considerations:
- The whole thing would probably have been a lot easier using only one computer. However, I'm quite certain the Pi will have a hard time serving PHP graphs from data with 5 or 10 minute precision spanning months or years. Furthermore I already have an nginx/PHP web server on the odroid.
- Connecting to the database over network might be hard. mySQL has this feature but I'm worried it will take to much resources. SQLite can only do this via network file systems but they say this is resource inefficient. If I'm watching something on the Odroid I don't want it to hang every five minutes just because the Pi is accessing the database. An option might be to cache the data on the Pi and flush it to the Odroid every night at 4 am or so. Data transfer the other way will suffer though (only reacting to a command the next day) but this might be solved by placing the "commands" DB on the Pi and having the PHP control panel access it when needed but this needs network file systems both ways. How much resources does that take?
- Thought about making two C++ programs that communicated directly through network but decided that it would be too complicated. Correct assumption?
- Are there any existing technologies doing what I want that I can benefit from?
- What soil sensors are the best? Should I buy an ADC and make my own?
- I have barely begun thinking of how to connect the pump(s).
So these are my thoughts, what are yours?
Björn