Sensoren für Garage
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 617 KiB After Width: | Height: | Size: 748 KiB |
+56
-28
@@ -13,49 +13,57 @@ cherrypy.config.update({
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s - %(message)s')
|
||||
|
||||
|
||||
PIN_MOTOR_BUTTON = 23
|
||||
PIN_REMOTE_BUTTON = 24
|
||||
PIN_MOTOR = 21
|
||||
PIN_REMOTE = 26
|
||||
PIN_GARAGE_BUTTON = 23
|
||||
PIN_GATE_BUTTON = 24
|
||||
PIN_GARAGE = 21
|
||||
PIN_GATE = 26
|
||||
PIN_LED = 11
|
||||
PIN_DOOR_OPEN = 13
|
||||
PIN_DOOR_CLOSED = 6
|
||||
PIN_SENSOR_GATE= 19
|
||||
|
||||
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(PIN_MOTOR_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
GPIO.setup(PIN_REMOTE_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
GPIO.setup(PIN_MOTOR, GPIO.OUT)
|
||||
GPIO.setup(PIN_REMOTE, GPIO.OUT)
|
||||
GPIO.setup(PIN_GARAGE_BUTTON, GPIO.IN, GPIO.PUD_UP)
|
||||
GPIO.setup(PIN_GATE_BUTTON, GPIO.IN, GPIO.PUD_UP)
|
||||
GPIO.setup(PIN_GARAGE, GPIO.OUT)
|
||||
GPIO.setup(PIN_GATE, GPIO.OUT)
|
||||
GPIO.setup(PIN_LED, GPIO.OUT)
|
||||
GPIO.setup(PIN_DOOR_OPEN, GPIO.IN, GPIO.PUD_UP)
|
||||
GPIO.setup(PIN_DOOR_CLOSED, GPIO.IN, GPIO.PUD_UP)
|
||||
GPIO.setup(PIN_SENSOR_GATE, GPIO.IN, GPIO.PUD_UP)
|
||||
|
||||
|
||||
def motor_button(channel):
|
||||
def garage_button(channel):
|
||||
time.sleep(0.01) # el cheapo relay module creates lots of interference, so we check again after a waiting period (see https://electronics.stackexchange.com/a/361793/253533)
|
||||
if channel == 0 or GPIO.input(PIN_MOTOR_BUTTON) == False:
|
||||
if channel == 0 or GPIO.input(PIN_GARAGE_BUTTON) == False:
|
||||
logging.info("trigger motor")
|
||||
GPIO.output(PIN_MOTOR, GPIO.LOW)
|
||||
GPIO.output(PIN_GARAGE, GPIO.LOW)
|
||||
GPIO.output(PIN_LED, GPIO.HIGH)
|
||||
time.sleep(0.4)
|
||||
GPIO.output(PIN_MOTOR, GPIO.HIGH)
|
||||
GPIO.output(PIN_GARAGE, GPIO.HIGH)
|
||||
GPIO.output(PIN_LED, GPIO.LOW)
|
||||
else:
|
||||
logging.info("flare (motor button)")
|
||||
|
||||
def remote_button(channel):
|
||||
def gate_button(channel):
|
||||
time.sleep(0.01)
|
||||
if channel == 0 or GPIO.input(PIN_REMOTE_BUTTON) == False:
|
||||
logging.info("trigger remote 0.8")
|
||||
GPIO.output(PIN_REMOTE, GPIO.HIGH)
|
||||
if channel == 0 or GPIO.input(PIN_GATE_BUTTON) == False:
|
||||
logging.info("trigger remote")
|
||||
GPIO.output(PIN_GATE, GPIO.HIGH)
|
||||
GPIO.output(PIN_LED, GPIO.HIGH)
|
||||
time.sleep(0.8)
|
||||
GPIO.output(PIN_REMOTE, GPIO.LOW)
|
||||
time.sleep(0.4)
|
||||
GPIO.output(PIN_GATE, GPIO.LOW)
|
||||
GPIO.output(PIN_LED, GPIO.LOW)
|
||||
else:
|
||||
logging.info("flare (remote button)")
|
||||
|
||||
GPIO.add_event_detect(PIN_MOTOR_BUTTON, GPIO.FALLING, callback=motor_button, bouncetime=250)
|
||||
GPIO.add_event_detect(PIN_REMOTE_BUTTON, GPIO.FALLING, callback=remote_button, bouncetime=250)
|
||||
GPIO.add_event_detect(PIN_GARAGE_BUTTON, GPIO.FALLING, callback=garage_button, bouncetime=250)
|
||||
GPIO.add_event_detect(PIN_GATE_BUTTON, GPIO.FALLING, callback=gate_button, bouncetime=250)
|
||||
|
||||
GPIO.output(PIN_MOTOR, GPIO.HIGH)
|
||||
GPIO.output(PIN_REMOTE, GPIO.LOW)
|
||||
GPIO.output(PIN_GARAGE, GPIO.HIGH)
|
||||
GPIO.output(PIN_GATE, GPIO.LOW)
|
||||
GPIO.output(PIN_LED, GPIO.LOW)
|
||||
|
||||
|
||||
@@ -64,21 +72,41 @@ class GarageService(object):
|
||||
def index(self):
|
||||
return "Hello World!"
|
||||
|
||||
# deprecated
|
||||
@cherrypy.expose
|
||||
def motor(self):
|
||||
Thread(target=motor_button,args=[0]).start()
|
||||
return "trigger motor"
|
||||
Thread(target=garage_button,args=[0]).start()
|
||||
return "trigger garage door"
|
||||
|
||||
# deprecated
|
||||
@cherrypy.expose
|
||||
def remote(self):
|
||||
Thread(target=remote_button,args=[0]).start()
|
||||
return "trigger remote"
|
||||
Thread(target=gate_button,args=[0]).start()
|
||||
return "trigger gate"
|
||||
|
||||
@cherrypy.expose
|
||||
def garage(self):
|
||||
Thread(target=garage_button,args=[0]).start()
|
||||
return "trigger garage door"
|
||||
|
||||
@cherrypy.expose
|
||||
def gate(self):
|
||||
Thread(target=gate_button,args=[0]).start()
|
||||
return "trigger gate"
|
||||
|
||||
@cherrypy.expose
|
||||
def all(self):
|
||||
Thread(target=motor_button,args=[0]).start()
|
||||
Thread(target=remote_button,args=[0]).start()
|
||||
Thread(target=garage_button,args=[0]).start()
|
||||
Thread(target=gate_button,args=[0]).start()
|
||||
return "trigger all"
|
||||
|
||||
@cherrypy.expose
|
||||
def garage_status(self):
|
||||
if (GPIO.input(PIN_DOOR_OPEN) and GPIO.input(PIN_DOOR_CLOSED)):
|
||||
return "moving"
|
||||
elif (GPIO.input(PIN_DOOR_OPEN) and not GPIO.input(PIN_DOOR_CLOSED)):
|
||||
return "closed"
|
||||
return "open"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user