Aggiunta webapp con Flask.

This commit is contained in:
Emiliano Vavassori 2024-09-04 16:53:56 +02:00
parent b06470d57f
commit 25cb3c95f0
3 changed files with 39 additions and 2 deletions

7
led.py
View File

@ -5,6 +5,10 @@ import wiringpi
import click
import time
def setup() -> None:
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(18, 1)
def pin_on() -> None:
# Attiva uscita GPIO18
wiringpi.digitalWrite(18, 1)
@ -31,8 +35,7 @@ def toggle() -> None:
@click.command()
@click.argument('op')
def cli(op):
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(18, 1)
setup()
if op in [ "accendi", "on" ]:
pin_on()

View File

@ -1,2 +1,3 @@
wiringpi
click
flask

33
webapp.py Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
# encoding: utf-8
from flask import Flask
import led
app = Flask(__name__)
@app.route('/')
def index():
return "Benvenuto nel raspberry."
@app.route('/accendi')
@app.route('/on')
def accendi() -> None:
led.pin_on()
@app.route('/spegni')
@app.route('/off')
def spegni() -> None:
led.pin_off()
@app.route('/toggle')
def toggle() -> None:
led.toggle()
@app.route('/lampeggia')
def lampeggia():
led.lampeggia()
if __name__ == '__main__':
led.setup()
app()