Skip to content

Instantly share code, notes, and snippets.

@mattyb
Created February 25, 2015 04:48
Show Gist options
  • Save mattyb/4ff1502ee31ac8f0da02 to your computer and use it in GitHub Desktop.
Save mattyb/4ff1502ee31ac8f0da02 to your computer and use it in GitHub Desktop.
ScatCat
#!/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