Sprinkler logging interface works well now (tested with firmware 1.8.1)

75 views
Skip to first unread message

David Gustavson

unread,
Oct 30, 2012, 3:20:35 PM10/30/12
to
I've posted my Sprinkler Logging software files in a shared Google Drive folder: 

There's a screen shot file that shows what the user sees, namely a list of all valve operations over the last week and a list of all scheduled operations for the next week, with rain delays shown by red color for the watering cycles that will be skipped.

I find the log very useful for answering questions from my wife (our garden person) like "when did the vegetables get watered last?"--in this case they were skipped for a week because of rain delay being set for several days, and they were only set to be watered every 6 days, one of which was during the rain delay period.

I still use Ray's software for controlling the system, setting up the programs etc., and my code stole major blocks from his, so that I could be sure of getting the schedule info interpreted correctly.
I didn't do anything about the Master valve, nor the rain sense, neither of which I use. However, all valve actuations are logged, so the logs will show what actually happened, I think.

Here's how it works:
On my always-on computer (a Mac) I've set up a Cron task (launchd on a Mac) to run a PHP program "SprinklerWatcher.php" every 20 seconds. This program is very simple, and just uses Ray's web interface to discover the current sprinkler actuations. Whenever those are seen to have changed, a line is written to a file "SprinklerChanges.txt" that records the new value and the time/date. Another tiny file "SprinklerPrevious.txt" is used to save the previous value, for comparing with to detect changes.
One shortcoming of the present code is that it never deletes anything from SprinklerChanges.txt, so that file will grow indefinitely. However, it is so small that it won't matter for years, in my case, and if it gets to be a space or performance issue one can simple use a text editor to delete all lines older than some cutoff date. It would be easy enough to do this automatically once one decides how much history is appropriate to keep, but at present one can modify the displaying program Sprinklers.php to show the history as far back as one wishes, so I just left the history to accumulate for now.

To see the actual valve operation history (currently set for 7 days) and future scheduled operations (currently also 7 days), you use your browser to view your web page
This will display as shown in the screen shot.
(In reality, I've set my router to give the serving computer a fixed local IP address, as I also did for the sprinkler controller, and set up port forwarding so that I can access the logging interface or Ray's interface from anywhere, including from my iPhone. I use Dyn.com to give me the effect of an external static IP address, since my DSL provider changes my IP address frequently.)

The file SprinklerWatcher.php includes comments that explain where the files should be placed, and discusses permissions and ownership. This all got more complicated because I wanted it to run even if nobody is logged in to my computer, so some files have to belong to root (even though I don't have root enabled on my Mac). It also includes the .plist file that sets up launchd to run the repeating task.

The software is obscured somewhat by being a mixture of PHP and JavaScript. I didn't know JavaScript, or I could have done the whole job using that. Maybe someday I'll rewrite it. So for now, the PHP code runs first and emits the javascript code and data it gets from querying the sprinkler controller, along with slightly modified code from Ray (the code his interface supplies from his server when you run his interface). I gathered that code just putting its URL in a browser, which then listed the .js file as text, and I copied/pasted it into my file, where I could hack it slightly for my purposes. E.g., I needed the schedule plotter to run multiple times, to do multiple days, and I changed the bar plotting routine to instead generate the schedule lines you see in my screenshot instead.

For my display, I use my own array of sprinkler valve names, which have no length limits. Probably that is a mistake, as I still need to know the short names (12 characters) while using the programming interface Ray provides. Could be fixed easily.

I use BBEdit and (usually) Safari on the Mac for editing and debugging. BBEdit is able to edit system files that don't belong to you, by entering an admin password on each save. (The version sold in the app store has that feature removed, which is an enormous pain until you learn that there's a script you can download from BareBones software that restores the feature, which Apple forced to be removed because it's (obviously) a security hole.)

I'll be grateful for any bug reports or suggestions for improvement, or for improved versions others may evolve.

Dave Gustavson


Ray

unread,
Nov 2, 2012, 10:24:39 PM11/2/12
to rays...@googlegroups.com
Hi David,

Thanks a lot for the details description. One minor issue: could you check the 'share' settings of the google docs? It looks like I need to request permission from you to view the files (which I just requested). If you want the files to be publicly available, see if you can change the share setting to 'public on the web'. Thanks.

Ray

unread,
Nov 6, 2012, 1:00:48 AM11/6/12
to rays...@googlegroups.com
I've received the updated version from David and it has been checked into the OpenSprinkler GitHub repository.
Reply all
Reply to author
Forward
0 new messages