Hello Community,
I’d like to first start off that I struggle understanding how HTML, JSCRIPT and REST work so in no way I try to sell myself as a pro. For the most part I have been able to take the templates provided by http://webiopi.trouch.com and get them to work for what I need...until now.
I added a relay bank to my Webiopi system. My relay’s work great, they control what I need with the Rpi libraries. The problem is when I send a command to the Pi from a script outside of the webiopi script.py, the whole webiopi seems to loose the ‘link’ which updates the pin’s state.
From what I understand webiopi has a way to create functions in the script.py . My goal is to create an instruction which runs my ‘rf1OFF.py’ script for 2 seconds after 8pm.
rf1OFF.py
import RPi.GPIO as GPIO
import time
relayPin= 9
# Pin Setup:
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
GPIO.setup(relayPin, GPIO.OUT) # relay pin as output
GPIO.output(relayPin, GPIO.LOW)
time.sleep(2)
GPIO.output(relayPin, GPIO.HIGH)
# GPIO.cleanup()
import webiopiimport datetime
GPIO = webiopi.GPIO
LIGHT = 17 # GPIO pin using BCM numbering
HOUR_ON = 8 # Turn Light ON at 08:00HOUR_OFF = 18 # Turn Light OFF at 18:00
# setup function is automatically called at WebIOPi startupdef setup(): # set the GPIO used by the light to output GPIO.setFunction(LIGHT, GPIO.OUT)
# retrieve current datetime now = datetime.datetime.now()
# test if we are between ON time and tun the light ON if ((now.hour >= HOUR_ON) and (now.hour < HOUR_OFF)): GPIO.digitalWrite(LIGHT, GPIO.HIGH)
# loop function is repeatedly called by WebIOPi def loop(): # retrieve current datetime now = datetime.datetime.now()
# toggle light ON all days at the correct time if ((now.hour == HOUR_ON) and (now.minute == 0) and (now.second == 0)): if (GPIO.digitalRead(LIGHT) == GPIO.LOW): GPIO.digitalWrite(LIGHT, GPIO.HIGH)
# toggle light OFF if ((now.hour == HOUR_OFF) and (now.minute == 0) and (now.second == 0)): if (GPIO.digitalRead(LIGHT) == GPIO.HIGH): GPIO.digitalWrite(LIGHT, GPIO.LOW)
# gives CPU some time before looping again webiopi.sleep(1)
# destroy function is called at WebIOPi shutdowndef destroy(): GPIO.digitalWrite(LIGHT, GPIO.LOW)