- Agontile's Raspberry Pi based sprinkler controller
- Uses hardware interface from OpenSprinkler Pi: http://rayshobby.net/?p=5339
- Note: I am not a professional programmer. I know exactly enough about Linux to be dangerous.
- My approach uses the Unix crontab as the timer for my sprinklers. I placed the file "sprinkler-init.sh" in /etc/init.d and set it to run at startup. This script gets the current time from the hardware clock, and uses it to set the system time. After that, time is adjusted by the network NTP service, but this makes sure the clock is close even if the network is down.
- (Note that my Pi is an early version. The current version has different pins for its GPIO. These scripts will need to be adjusted, as discussed here: http://rayshobby.net/phpBB3/viewtopic.php?f=28&t=51 )
- The actual operation of the sprinklers is controlled by the two scripts, "sprinkler-on.sh" and "sprinklers-off.sh". The 'on' script is called with a single argument, the number of the sprinkler circuit desired: "sprinkler-on.sh 1". It will only allow one circuit to be on at a time. The 'off' script does not take any arguments, and turns all circuits off together. These two scripts were my "phase 1" installation. They allowed me to manually install a crontab that would run my sprinklers at fixed times.
- My "phase 2" was to fetch a weather forecast from the internet, using the script "get-forecast.sh". I registered for a free 'developer' account at wunderground.com and got an API key. If you want to use my script, you'll need to get your own free API key, and edit it into the two URLs in the script. If you don't live in California zip-91205, you'll also probably want to change the "/CA/91205" part of the URLs to your own location. The script doesn't program any sprinklers, it just fetches the forecast, and writes a single parameter into each of four tiny text files: "forecast-high", "forecast-precip", "forecast-sunrise-hour", and "forecast-sunrise-minute". This script is run as a crontab entry every day at 4AM.
- As of this time, the final pieces of the puzzle are "sprinkler-durations.txt" and "forecast-program.c". Together, they read the forecast files, and create and install a custom crontab. To allow other entries to exist unchanged in the crontab, I inserted 'start' and 'end' headers in my crontab, so the program would know what portion to update. These headers must exactly match the code in the C source file.
- The file "sprinkler-durations.txt" has a few parameters to make it easy to change the watering pattern. Among them are the names of each sprinkler circuit. These names must exactly match the names in the C file.
- EDIT: Originally there was a warning here about the last line in main(). That has now been successfully tested, and the warning removed.
- Files used:
- sprinkler-init.sh http://pastebin.com/AAR65mtf
- sprinkler-on.sh http://pastebin.com/XBLMptiH
- sprinklers-off.sh http://pastebin.com/Lcbm9UQC
- get-forecast.sh http://pastebin.com/wc4qHKvR
- sprinkler-durations.txt http://pastebin.com/UJVgVs9u
- forecast-program.c http://pastebin.com/JG5d46YM
- To do:
- * Allow start times other than 'sunrise'
- * Allow multiple start times in same day
- * Fetch time from hardware clock sooner in boot sequence
- * Web page front end to create sprinkler-durations.txt
Agontile's Raspberry Pi based sprinkler controller
Agontile May 28th, 2013 1,617 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data