Created
February 25, 2015 04:48
-
-
Save mattyb/4ff1502ee31ac8f0da02 to your computer and use it in GitHub Desktop.
ScatCat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import cherrypy | |
import RPi.GPIO as GPIO | |
import time | |
RELAY_IO = 22 | |
SQUIRT_TIME = 0.5 | |
ON_MODE = GPIO.LOW | |
VALID_USER = "MATTYBE" | |
class ScatCat(object): | |
def index(self): | |
return "Hello World!" | |
def squirt(self, username = "", user_ip = ""): | |
if username == VALID_USER: | |
print("Squirt!") | |
GPIO.output(RELAY_IO, ON_MODE) | |
time.sleep(SQUIRT_TIME) | |
GPIO.output(RELAY_IO, not ON_MODE) | |
return "Squirt!" | |
else: | |
print("Rejected") | |
return "rejected" | |
return "" | |
index.exposed = True | |
squirt.exposed = True | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(RELAY_IO, GPIO.OUT) | |
GPIO.output(RELAY_IO, not ON_MODE) | |
cherrypy.config.update({ 'server.socket_host': '0.0.0.0', | |
'server.socket_port': 9000, | |
}) | |
cherrypy.quickstart(ScatCat()) | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment