Skip to content

Instantly share code, notes, and snippets.

@FuriosoJack
Created June 11, 2018 02:22
Show Gist options
  • Save FuriosoJack/909e46f5df87a00bfa3214b198d68697 to your computer and use it in GitHub Desktop.
Save FuriosoJack/909e46f5df87a00bfa3214b198d68697 to your computer and use it in GitHub Desktop.
from modules.debounce_handler import debounce_handler
from modules.fauxmo import *
import logging
import time
import RPi.GPIO as GPIO
logging.basicConfig(level=logging.DEBUG)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.OUT)
class device_handler(debounce_handler):
"""Publishes the on/off state requested,
and the IP address of the Echo making the request.
"""
TRIGGERS = {"desk ligth": 52000}
def act(self, client_address, state, name):
print "State", state, "on ", name, "from client @", client_address
GPIO.output(17,state)
return True
if __name__ == "__main__":
# Startup the fauxmo server
fauxmo.DEBUG = True
p = poller()
u = upnp_broadcast_responder()
u.init_socket()
p.add(u)
# Register the device callback as a fauxmo handler
d = device_handler()
for trig, port in d.TRIGGERS.items():
fauxmo(trig, u, p, None, port, d)
# Loop and poll for incoming Echo requests
logging.debug("Entering fauxmo polling loop")
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)
time.sleep(0.1)
except Exception, e:
logging.critical("Critical exception: " + str(e))
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment