Aggiunta webapp con Flask.
This commit is contained in:
parent
b06470d57f
commit
25cb3c95f0
7
led.py
7
led.py
@ -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()
|
||||
|
@ -1,2 +1,3 @@
|
||||
wiringpi
|
||||
click
|
||||
flask
|
||||
|
33
webapp.py
Normal file
33
webapp.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user