Last active
January 15, 2018 08:32
-
-
Save teru01/917b8b63f05c58a93ddabce6d0f5ea60 to your computer and use it in GitHub Desktop.
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
from bottle import Bottle, run, post, request, redirect | |
import wiringpi as wp | |
app = Bottle() | |
state = 0 | |
stdict = {0:"turn off", 1:"turn on"} | |
wp.wiringPiSetupGpio() | |
wp.pinMode(2, 1) | |
@app.route('/') | |
def handle(): | |
global state | |
state = not(state) | |
return """<form action="/" method="post"> | |
<input name="lednextstate" value={} type="hidden" /> | |
<input value={} type="submit" /> | |
</form>""".format(state ,stdict[state]) | |
@app.route('/', method='POST') | |
def lchika(): | |
lednextstate = int(request.forms.get('lednextstate')) | |
wp.digitalWrite(2, lednextstate) | |
print(stdict[lednextstate]) | |
redirect('/') | |
run(app, host='192.168.11.24', port=8080) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment