Go to the Home Page
Light Led Trough Web
.py
from bottle import route,run,template,request
import RPi.GPIO as GPIO
LED1=14
LED2=15
LED3=12
LED4=16
@route("/")
def toppage():
return template("toppage")
@route("/led",method="get")
def led():
led_value=request.query.get("led1")
if led_value=="0":
GPIO.output(LED1,GPIO.LOW)
if led_value=="1":
GPIO.output(LED1,GPIO.HIGH)
return template("toppage")
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED1,GPIO.OUT,initial=GPIO.LOW)
try:
run(host="localhost",port=8080,debug=True)
finally:
GPIO.cleanup()
print("GPIO clean up!")
.html
<!DOCTYPE html>
<html lang="ja">
<head><meta charset="utf-8"><title>Web LED</title></head>
<body>
<h1>Top Page</h1>
<form action="/led">
<input name="led1" type="hidden" value="1">
<input type="submit" value="LED1 ON">
</form>
<form action="/led">
<input name="led1" type="hidden" value="0">
<input type="submit" value="LED1 OFF">
</form>
</body>
</html>