Raspberry-Pi-Sonoff
October 29, 2022
from flask import Flask, render_template, request, redirect
from gpiozero import LED
from time import sleep
led = LED(2)
# http://www.pillalamarri.in/python/raspberry-pi-sonoff/
app = Flask(__name__)
@app.route("/")
def home():
if led.value == 1:
status = 'ON'
else:
status = 'OFF'
return render_template('home.html', status=status)
@app.route("/on")
def on():
led.on()
return "LED on"
@app.route("/off")
def off():
led.off()
return "LED off"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8000)
# http://www.pillalamarri.in/python/raspberry-pi-sonoff/
Posted in Python