-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcherry_server.py
More file actions
44 lines (34 loc) · 1.08 KB
/
cherry_server.py
File metadata and controls
44 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python3
#encoding:utf-8
#Tutorial: http://www.knight-of-pi.org/cherrypy-an-elegant-python-webserver-for-raspberry-pi-remote-controls/
#Licence: http://creativecommons.org/licenses/by-nc-sa/3.0/
# Author: Johannes Bergs
import random, string
from time import sleep
import cherrypy
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
class RaspiServer(object):
@cherrypy.expose
def index(self):
return """<html>
<head></head>
<body>
<form method="get" action="blink">
<input type="text" value="13" name="pin_str" />
<button type="submit">Blink!</button>
</form>
</body>
</html>"""
@cherrypy.expose
def blink(self, pin_str="13"):
pin = int(pin_str)
GPIO.setup(pin, GPIO.OUT)
sleep(0.5)
GPIO.output(pin, GPIO.HIGH)
sleep(0.5)
GPIO.output(pin, GPIO.LOW)
return "Blinked on Pin " + str(pin)
if __name__ == '__main__':
cherrypy.config.update({'server.socket_host': '0.0.0.0'})
cherrypy.quickstart(RaspiServer())