OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) Python interval program update 9/23/13 Re: Re: Python interval program update 9/23/13

#25582

dennyfmn
Participant

Hi Dan,

Thanks so much for adding the per station rain sensor option. That’s great! Plus all the other fixes and updates.

It took me a while to feel confident to do the “git pull” to bring in your commits and merge them with my local changes for the garage door and rain sensor. I’m new to git. I’ve been reading a really good on-line free book, http://git-scm.com/book, which has helped me quite a bit. http://genomewiki.ucsc.edu/index.php/Resolving_merge_conflicts_in_Git also helped with understanding what I needed to do to fix the conflicts I had in ospi.py and home.js.

Since the rain sensor is functional now, I wonder if you would consider adding code to ospi.py to define the pin, set up the gpio, read the pin, and poll it.

Here’s the way I’ve done it, adding to the appropriate sections:


def getRainState():
if GPIO.input(pin_rain_sense):
res2 = 0
else:
res2 = 1
return res2

pin_rain_sense = 25

GPIO.setup(pin_rain_sense, GPIO.IN, pull_up_down=GPIO.PUD_UP)

And inserting a call to get the rain sensor state in the main loop:


def main_loop(): # Runs in a seperate thread
""" ***** Main algorithm.***** """
print 'Starting main loop n'
last_min = 0
while True: # infinite loop

gv.sd=getRainState()

gv.now = time.time()+((gv.sd/4)-12)*3600 # Current time based on UTC time from the Pi adjusted by the Time Zone setting from options. updated once per second.

Other folks might choose a different input pin for the rain sensor, but the rest of the code would be there.

[attachment=1:2ozylmh5]Update-20130926.JPG[/attachment:2ozylmh5]

[attachment=0:2ozylmh5]StationsRainSensor.JPG[/attachment:2ozylmh5]

Thanks again!

Denny