July 25, 2013 at 1:40 am #22552
I’ve created an alternative control software module to control the Raspberry Pi OpenSprinkler system. It’s entirely self contained and doesn’t require python, a web server, or any other heavy software to operate. It can also be compiled to run on the Atmel AVR / Arduino platforms, so theoretically it should run on the AVR OpenSprinkler as well.
I created this a few months back before I had seen the web code created by Samer. The look and feel are pretty similar mainly due to the use of the same mobile web library (jQuery Mobile).
Here are the features:
- Fully contained system with control logic and web serving.[/*:6euc590i]
- Same code can be compiled to run on the Atmel/AVR/Arduino platform.[/*:6euc590i]
- Web based control (including mobile Android iOS)[/*:6euc590i]
- Automatic adjustment of intervals based on weather conditions. (weather underground API)[/*:6euc590i]
- Weather conditions can be pulled from individual personal weather stations or from general weather data based on zipcode.
- Manual Control[/*:6euc590i]
- Scheduled Control[/*:6euc590i]
- Quick Schedule[/*:6euc590i]
- Named Zones[/*:6euc590i]
- Full Graphing feature of historic logs[/*:6euc590i]
- Ability to run with OpenSprinkler module or direct relay outputs.[/*:6euc590i]
- Supports master valve/pump output
- Supports expansion zone board (up to 15 zones)
- Very simple installation
- Seasonal adjustment.
Plus I’m working on a few other things…
Here are a few screen shots from the software:
- Start with a generally clean instance of Raspberry Pi Raspbian system. If you have a web server installed, you’ll want to avoid port conflicts (i.e. make sure it’s not running on 8080— the default for this software). If you’ve already installed the python interval program, disable it while you’re running this.
- Install the wiring pi module. Details are here: http://wiringpi.com/download-and-install/
- Install the sqlite3 library (technically optional, but why not do it anyway?), and the build tools
sudo apt-get install libsqlite3-dev build-essential
- Download the source tarball by typing:
- Unpack the source tarball:
tar -xzvf sprinklers_pi-1.0.7.tar.gz
- Build and install the module:
sudo make install
That’s it! If you want to start it, simply reboot or just run the following:
sudo /etc/init.d/sprinklers_pi start
If something goes wrong on startup you can get some diagnostic information at /var/log/sprinklers_pi.
Once you’ve started things up, browse to port 8080 with a web browser. The system starts up in demo mode (i.e. it won’t actually switch outputs). To change the output type go to the Settings and change the Output type to “OpenSprinkler” (assuming you’re using the OpenSprinklerPi module).
For those who are particularly adventurous, the sprinkling logs are stored in sqlite3 database format, so if you really care, you can query them with SQL using the database at /usr/local/etc/sprinklers_pi/db.sql
Upgrading from a previous Version:
If you are upgrading from version 1.0.1 please note that upgrading will erase your settings and load the default settings. BE FOREWARNED. Upgrading from version 1.0.3 onward will not require reloading settings.
To upgrade, run the following
tar -xzvf sprinklers_pi-1.0.7.tar.gz
sudo make upgrade
You should erase your browser cache when you start. I’ve got a fix for that in the works, but it’s not there right now. In chrome you do this by pressing Ctrl-Shift-Delete, make sure the “empty the cache” checkbox is checked, and click “Clear Browsing Data”. On IE, press Ctrl-Shift-Delete and make sure ‘Temporary Internet Files and website files” is selected. On the iPhone you do this in the Settings->Safari window.
There’s a wiki for the program up at: https://github.com/rszimm/sprinklers_pi/wiki
There’s also a github repository of the code at: https://github.com/rszimm/sprinklers_piJuly 25, 2013 at 4:05 am #24926
Looks great – does it support a master valve?July 25, 2013 at 5:21 am #24927
Yes. Master valve / pump. You can selectively define which zones require the master valve and which ones do not.July 25, 2013 at 1:25 pm #24928
Thanks for sharing! The best part about about Raspberry Pi’s and the OpenSprinkler is that it almost exclusively attracts DIYers, so we’ll have a lot of diverse solutions available. How does your system utilize the wunderground data (e.g., what is it pulling down and in what way does it alter the watering schedule)?July 25, 2013 at 3:34 pm #24929
Average Humidity, Average Temperature and rainfall. If it’s a hot dry day, it adds in some time. If it’s a cool, humid day, or it rains, it subtracts some time.
To make it work you need to get a free API key from Weather Underground at api.wunderground.com/weather/api/July 26, 2013 at 12:24 am #24930
First of all, awesome work! I am trying to get started with this but unfortunately can’t seem to. Here is what I have done and where I am:
I don’t have a Raspberry Pi so I am just compiling on my MBP. I commented out all the digitWrite calls, OUTPUT and pushpin call. I also commented the reboot call. I removed the -lwiringPi in the Makefile, as well. After all of this it compiled successfully:
Building target: sprinklers_pi
g++ -o "sprinklers_pi" build/Event.o build/Logging.o build/Weather.o build/core.o build/port.o build/settings.o build/sprinklers_pi.o build/sysreset.o build/web.o -lsqlite3
Finished building target: sprinklers_pi
After that I ran the program and it seems to run fine:
2013/07/25 19:19:29 Starting v1.0.1..
2013/07/25 19:19:29 Turning Off All Zones
2013/07/25 19:19:29 Listening on Port 8080
2013/07/25 19:19:29 Turning Off All Zones
2013/07/25 19:19:32 Got a client
2013/07/25 19:19:32 Page:
2013/07/25 19:19:32 Serving Page: /web/index.htm
2013/07/25 19:19:32 Got a client
2013/07/25 19:19:32 Page:favicon.ico
2013/07/25 19:19:32 Serving Page: /web/favicon.ico
As you can see, it even sees connections coming in! However, all I get in the browser is: “NOT FOUND”
Any advice? I tried changing permissions and also running as sudo.
Update: I understand this environment is very unique and I have VERY little experience with C and portability. With that said, I am going to try this on Debian instead since that is a closer environment it might work better.
Update 2: Same thing with my Debian 7 box.
Update 3: Figured out it is checking absolute path so I moved /web there and it works now.
Update 4: Haha we went with the same Day/Interval switch 😛
Update 5: In case anyone cares I changed web.cpp so the prefix is web/ not /web/ and changed the appropriate memcpy length.July 26, 2013 at 1:06 am #24931
The logging is absolutely impressive! I am actually learning flot now and hoping you wouldn’t mind if I try to incorporate the graph logging into my app. Still trying to figure out how to convert my data into the appropriate JSON but hoping I can make it work!July 26, 2013 at 4:57 pm #24932
By all means, go ahead and take what you want!
Be a bit careful with that relative path thing. The path cstring (sPage) is pretty darn short in length (only 30 bytes), which is why I chose an absolute path right off the root FS (i.e. /web). As you surmised, the memcpy protects the memory outside the cstring, so make sure if you change the memcpy length, you also change the cstring length. From your post I think you just pulled off the forward slash and changed the 5 to a 4 in the memcpy. That should be totally fine…
BTW (tech speak here…): There are a bunch of these little optimizations in there. This is because it’s designed to run inside the small address space of the Atmel Arduino platform. They only give you 4k of RAM over there. That’s right, 4096 bytes of RAM! It’s hard to implement a web server and a FAT file system retrieval library, as well as a NTP time keeping library and a TFTP server all in 4k of RAM (not to mention the actual sprinkler code) That means that there are tons of little size optimizations and limitations to keep the stack size from growing (I don’t use any heap in this application). If I didn’t want to cross-develop here there are a LOT of things I would have done differently.July 26, 2013 at 6:15 pm #24933
Very impressed with this solution, I have to admit! I have never even looked at code in C so this is exciting since I am now going through your code to learn 😛
Thanks again for sharing this!July 26, 2013 at 8:27 pm #24934
Is there a line in the code that I need to change for the pins? Like in the python pi interval program, I have to change a line in the code for the program to know the difference between pi rev 1 and pi rev 2 for the shift register.
Edit I found it in core.cpp. Is this the only place where the pins are defined?July 26, 2013 at 10:24 pm #24935
mattguy, I don’t believe you should have to do that. It should be taken care of with the wiringPi library automatically. I’ve only tried it with the Rev 1 though. Let me know how things turn out.July 27, 2013 at 6:43 am #24936
Thanks so much for this version. I’ve been fighting for days to get the python version going, without success. I loaded this in about an hour. Wow.
I do have a question, however. I have a zone extension box hooked into my RPi but the the web interface is only showing 7 zones. Should it automagically show the extension box? Do I have to manually add the extensions?
One other question, using your software, how do I adjust for my rain sensor?
I am also wondering what I need to do to get the Wunderground IP, but I’ll search elsewhere for that.
Thanks for all your work on this. IT’s amazing. Things like this are essential if we are to leave a healthy environment for our kids.July 27, 2013 at 7:42 pm #24937
Wunderground IP: You can get it by resolving api.wunderground.com. It’s 188.8.131.52.
There’s not currently support for a rain sensor. How is your rain sensor wired up? I don’t have a rain sensor, but adding support should be pretty simple. Anyone know what the optimal logic is w.r.t. a rain sensor? Rain the last 24 hours just don’t run any schedules?
There’s also not currently support for more than 7 zones (plus a master valve or pump). Shouldn’t be difficult to add in though. Most of the logic is already there and it’s just a matter of changing a constant, but I’ll have to shift some stuff a bit in how schedules are stored because I only allowed room for the 7 zones. Not a big deal really, but some work… Plus I don’t actually own an expansion board so I’ll have to get you to test things out when I’ve got something to test.July 27, 2013 at 8:04 pm #24938
As a followup, rather than hardwiring a rain sensor to your sprinkler controller, I could actually pull data from your internet connected personal weather station assuming you’ve got one that’s reporting to Weather Underground. That would actually be pretty trivial, and would be MUCH more complete than just a rain sensor because I could do different things based on temperature, humidity and exactly how MUCH rain was received.
That’s not to say I shouldn’t support hardwired rain sensors anyway… Just a thought…July 27, 2013 at 8:05 pm #24939
You should check out this thread for hardware/hardwire rain sensor method without any software: viewtopic.php?t=218July 28, 2013 at 6:20 am #24940
Thanks all for your help and thoughts!
Regarding the Wunderground IP, that’s perfect.
Regarding the rain sensor, I’ll get it going. Between your suggestions and that of salbahra, I can make it happen. It was just a difference I noticed between the Python version and your C version.
About the zones, this is surprising given that there is an expansion module. When you note that there’s not currently support for more than 7 zones, do you mean with your c version, or with the Python version as well? How about the Arduino version of OpenSprinkler?
In any case, if it can be programmed, I’m certainly willing to help test. I’m working on getting this all set up in the garage. It’s really pretty cool. Let me know how I can help.
MikeJuly 29, 2013 at 4:37 am #24941
Great program. I awoke this morning with the sprinklers running with your program doing the work. The interface is good but I would like to make a few suggestions.
A status page would be useful that shows the next schedule to run and when it is set to start. It might also include an indication of what zones will run and the time for each. Also some display that shows the status of the weather underground link would be helpful. As it stands I have no way of knowing whether it is configured correctly or not. The status display could also show when a schedule is delayed due to weather. This should be the first page seen when accessing the website.
Also, where is zone 0? The interface board supports 8 zones but I only see 7 on your interface. (Is it for a pump control?)July 29, 2013 at 3:56 pm #24942
Great ideas! Pretty busy today but I’ll dig into this tomorrow.
Oh, and yes, the first output of the board is reserved for the “pump” or “master valve” output. That’s why there are only 7 zones.July 30, 2013 at 6:48 pm #24943
Amazing code, where is the “donate the beer” button?July 30, 2013 at 10:31 pm #24944
I’ll contribute.July 31, 2013 at 9:54 pm #24945
Nice work! I have everything working except one thing – running schedules. I’m able to run a schedule manually but when it’s time comes up it just doesn’t go – Any suggestions?July 31, 2013 at 11:48 pm #24946
Is the “Run Schedules” on the front page set to “ON”? It turns off every time you activate something in manual mode. I’ve been thinking that there should be a better use case here because I’ve been victim to forgetting to turn it back on but I haven’t come up with something that makes sense yet.
If it is “ON” and it’s still not working then there’s probably a bug somewhere, can you send me your settings and log file (settings is at /usr/local/etc/sprinklers_pi/settings. Log is at /var/log/sprinklers_pi.August 1, 2013 at 12:22 am #24947
Yes, run schedules is on. I’ve done numerous combinations of turning it off and on, created multiple schedules, changed the start time, etc. so hopefully the files aren’t too cluttered. Both are in the attached zip file. Thanks!
Edit – removed the zip file…August 1, 2013 at 1:33 am #24948
I appreciate this more than you know! Thanks.
OK, I’m still not 100% certain what’s going on, but it sort of looks like a timezone issue. What time and timezone do you have your raspberrypi set to? Can you browse to the ShowEvent page (e.g. on my system it’s at raspberrypi1:8080/ShowEvent ). It will show exactly what the software thinks the local time is, and every upcoming event scheduled for the rest of the day. For instance, on mine right now it shows this:
18:29:10 2013/7/31 (4)
Event  Time:19:00(1140) Command 3 data 2,2
This indicates that the local time is 6:29 PM on August 31, 2013 and that at 19:00 (7pm) I’m going to run schedule #2 (that’s what command 3 means). Events that have passed will not show up in this listing…August 1, 2013 at 2:37 am #24949
OK, I have the following on my ShowEvent page:
02:30:50 2013/8/1 (5)
Event  Time:06:00(360) Command 3 data 0,0
Event  Time:12:40(760) Command 3 data 1,0
This was just now at 8:30pm Mountain time which is I’m sure the timezone the Pi is set to. The main page shows “Wed Jul 31 2013 20:33:20 GMT-0600 (Mountain Daylight Time)” at the bottom of the screen so I suppose the time listed above is UTC?
- You must be logged in to reply to this topic.