I've implemented logging, wonder if I can access the schedule via HTTP interface too?

208 views
Skip to first unread message

David Gustavson

unread,
Oct 22, 2012, 4:09:04 PM10/22/12
to rays...@googlegroups.com, d...@scizzl.com
I am soooo happy with my new sprinkler controller! What an improvement over my old timer-based system! I've wanted a system like this for years!

The one additional thing I felt was essential is to have a log--my wife is always asking "when was the ... watered last?", and it was very hard (in practice impossible) to figure that out in the timer-based system. Answering that question requires a log--the schedules say what might have happened, but given rain delays etc, only a log can tell what actually happened.

I was intending to modify the sprinkler firmware to add this log facility, but noticed that it is approaching memory limits, and then looked at its direct web interface, and realized I didn't need to change the sprinkler code at all to make a nice log facility.

The way it works is to have a cron (actually launchd) task running all the time on my Mac, which uses the sn0 command via html to get the current valve state, every 20 seconds. If the state has changed, it is recorded along with the date and time by appending it to the log file. The previous value is saved in another file, to remember it for 20 seconds for comparison purposes.

It did take me a long time to figure out the right configuration for the task so it would run whether or not anyone was logged in (had to get the file locations and permissions right, as well as the form of the plist that submits the task via launchctl).

I wrote the little logger that the cron task runs using PHP, just because I was familiar with it and it's included in all Macs. 
The log display is a web page served by my Mac, written in HTML and (mainly) PHP. 
(In the new Mountain Lion system, Personal Web Sharing is still available, but the interface for enabling it is missing, so a few Terminal commands are now needed to get Apache, PHP, etc running.)
The programs are quite small, and I'm happy to post or share them if anyone wants to do something similar. (I did search here for a similar project so I wouldn't have to do my own--if I missed it, I apologize!)
It should be even easier to make this stuff work in Linux or Windows, as the Mac Cron stuff has evolved to be rather sophisticated.

I also set up my router so port forwarding makes my personal web server accessible from anywhere. I also set up a port for accessing the sprinkler controller web features from anywhere.

The log display took several forms during development, but the one I converged on goes through the most recent N days of log, collecting information about time of occurrence, duration, and identity of the valve. It then presents the information sorted by valve and time. It also checks the current state, and marks the current watering flow (if any) as being in progress. This web page updates itself every 20 seconds also, which normally wouldn't be necessary but is useful for checking current activity while walking around the yard viewing it on my iPhone.

It's really lovely being able to control the sprinklers manually by phone while out in the yard!!

One feature I'd still like to add would show the upcoming scheduled events for the next day or so, and I'm wondering if there is any way to extract that via the controller's web interface?

The current log display looks like: (missing the table format, bold headings, etc. The valves I used for this debugging are unused ones, hence the boring names. I didn't want to run actual water while debugging! The real valves have descriptive names (no length limits in this software)

Valve Operations Date/Time (last 7 days)
V08=Unused, 2 run periods, ending at
0.2 min Sat, Oct 20, 2012, 4:11 PM
4.0 min Sun, Oct 21, 2012, 8:37 PM
V14=Unused, 2 run periods, ending at
0.2 min Sat, Oct 20, 2012, 1:11 PM
0.6 min Sun, Oct 21, 2012, 12:04 PM
V15=Unused, 6 run periods, ending at
0.2 min Sat, Oct 20, 2012, 4:05 PM
0.6 min Sun, Oct 21, 2012, 12:06 PM
0.3 min Sun, Oct 21, 2012, 4:48 PM
6.7 min Sun, Oct 21, 2012, 8:37 PM
1.0 min Sun, Oct 21, 2012, 8:42 PM
0.7 min Sun, Oct 21, 2012, 10:53 PM
0.2 min Mon, Oct 22, 2012, 12:23 PM Running Now
V16=Unused, 6 run periods, ending at
0.2 min Sat, Oct 20, 2012, 4:06 PM
0.4 min Sun, Oct 21, 2012, 12:06 PM
0.3 min Sun, Oct 21, 2012, 12:18 PM
21.3 min Sun, Oct 21, 2012, 8:37 PM
9.3 min Sun, Oct 21, 2012, 10:53 PM
0.3 min Sun, Oct 21, 2012, 11:01 PM

Ray

unread,
Oct 22, 2012, 10:59:16 PM10/22/12
to rays...@googlegroups.com, d...@scizzl.com
Hi David,

Awesome! Logging has been a much-wanted feature and seems you've figured out a easy and practical way. To summarize, this is a polling-based method which uses a cron task to check the controller status at regular interval, and log the changes. This way, no change needs to be done on the OpenSprinkler side. I will forward your post on my blog.

Do you plan to share your PHP script? You can either share a link, or I can upload your script to the GitHub repository. Let me know if I can help.

Regarding showing the future schedules, you can visually check any day's schedule by using the program preview feature (just change the date in the url link). It currently only shows per-day schedule, not weekly or monthly calendar. All the data needed to construct each day's schedule is in the program data array (Javascript array 'pd'). The format of pd is a bit awkward, for the reason of saving memory and transfer bandwidth. But it's not difficult to figure out. I can explain the details.

Again, thanks for contributing the logging feature!

David Gustavson

unread,
Oct 25, 2012, 6:40:03 AM10/25/12
to rays...@googlegroups.com, d...@scizzl.com
OK, I'm happy with the current version.
It shows all the watering events in the last week, and all the scheduled events in the next week, in one page.
It still has some silliness, because it sends the dates to the controller and gets the schedule back for each day--I hadn't realized until later that the schedule doesn't change, it includes everything. So I only needed to change the mm, yy, and dd variables before re-invoking the simulation to get a given day's schedule.
I just incorporated Ray's simulator bodily, so as not to introduce discrepancies. 
I've emailed the files to Ray (they're not very big) so he can post them as he likes.
If someone wants them as an email with attachments, I can do that.
This makes the system just about perfect, in my book... (the only flaw that bugs me is that the case screws come in from the back, so it has to be unmounted before it can be opened. No biggie. I love the connector system, and everything else. And I realize it looks nicer this way, and besides probably it will never need to be opened.
Dave
Reply all
Reply to author
Forward
0 new messages