Pseudo Code of the watering program

Posted: June 24, 2014 in Hacking, Hardware, Linux, Raspberry PI, RPi, Software
Tags: , , ,

OK, sat down over the weekend and did a bit of pseudo code for the watering program.

Easy when you think of it:

  1. Grab command line to see what watering schedule to run
  2. Load system config so I understand my hardware
  3. Load the designated watering schedule
  4. 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:
    1. Check the global gauges to see if we can water, if not exit program with reason
    2. 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
    3. Determine how long to water, either to the limit of the soil or for the full zone time
    4. Start watering the zone
    5. Sleep for the determined time
    6. Stop watering the zone
    7. 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.
  5. Shutdown any specific hardware as necessary (make sure the water and the pump (if you have one) are off.)
  6. 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:

  1. Weather report
  2. Temperature gauge (don’t water if too cold)
  3. Rain moisture gauge (don’t water if raining right now)
  4. 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)
  5. Wind gauge (don’t water if the wind is blowing too hard, you will just water the neighbors yard)
  6. 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:

  1. How many zones are active in the system
  2. Does the system use a pump to pressurize the water, if it does you need to turn it on for each zone to water
  3. 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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s