OK, sat down over the weekend and did a bit of pseudo code for the watering program.
Easy when you think of it:
- Grab command line to see what watering schedule to run
- Load system config so I understand my hardware
- Load the designated watering schedule
- Set up a loop to run all of the zones, if zone is not active or does not have any more water time go, loop to next zone, else:
- Check the global gauges to see if we can water, if not exit program with reason
- Check zone gauges to see if the zone can be watered, if the zone gauges say no water, zero the zone and go back to the top of the loop
- Determine how long to water, either to the limit of the soil or for the full zone time
- Start watering the zone
- Sleep for the determined time
- Stop watering the zone
- Go back to the top of the loop and keep doing it until all water delivered to all zones or we are bumped by gauges.
- Shutdown any specific hardware as necessary (make sure the water and the pump (if you have one) are off.)
- Exit program with status
Now there are some nuances there, logging and other bits but really that is it. Overly simplistic and lots of detail to pay attention to but at the highest level no need to check things second by second. And if for some reason I determine I have to check things more frequently than at each zone change I can by using threading but I don’t currently see the need for it.
So the first thing I decided to have a look at is what format are my data files? Gave that a lot of thought, XML, YAML, JSON or some home cooked format. After careful consideration of both the input web program and the watering program I decided on JSON for a bunch of reasons, its light weight, there are standard validation tools that can easily tell me if the file if formatted correctly, and its easy to write a json file from web software and their are a bunch of parsers under open source licenses so I don’t need to reinvent the wheel. Finally it’s pretty easy to hand craft a json file and get it correct so I can get the watering program done and tested without the web front end.
In some ways I don’t love JSON, the pure form does not support comments in the file. Several parsers do support C and C++ style comments but its not part of the standard as best I can tell. Of course some people don’t believe in comments so it matters not to them but I do like them.. Oh well the rest of the file format I like well enough.
The other thing I thought about was possible devices attached to the sprinkler system to determine if I should actually water now, or things on the Internet I can reach out to, they are:
- Weather report
- Temperature gauge (don’t water if too cold)
- Rain moisture gauge (don’t water if raining right now)
- Rain metering gauge (don’t water if we got enough water in the last day, tricker as we have to have something monitor this all the time)
- Wind gauge (don’t water if the wind is blowing too hard, you will just water the neighbors yard)
- Ground moisture gauge (one for the entire yard or one per zone, if the ground has enough water now why add more?)
Additionally some things you need to know are:
- How many zones are active in the system
- Does the system use a pump to pressurize the water, if it does you need to turn it on for each zone to water
- Do you want info logged about how much water is put out and what was skipped (if anything because of gauges)
The metering rain gauge is bothering me, I thought I’d only need a web front end and a watering program but to track a metering gauge will require monitoring it all the time. So I guess that will call for a daemon program that watches the gauge if you have one and accumulates water over time so you can decide if you need to water at all. Hmm, I think I leave that to last, or maybe someone else will code that since I don’t even have such a gauge, though I know they exist.
On to the next step coding the load the config.json file into memory and parse it. Language well that will be “C” since I prefer that over Python. IMHO Python is nice for proof of concept and quick one off scripts but I really prefer “C” for the watering program.