Skip to content

Instantly share code, notes, and snippets.

@teru01
Last active January 15, 2018 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teru01/917b8b63f05c58a93ddabce6d0f5ea60 to your computer and use it in GitHub Desktop.
Save teru01/917b8b63f05c58a93ddabce6d0f5ea60 to your computer and use it in GitHub Desktop.
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