2024-09-04 16:53:56 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
from flask import Flask
|
|
|
|
import led
|
2024-09-04 17:20:18 +02:00
|
|
|
import os
|
2024-09-04 16:53:56 +02:00
|
|
|
|
2024-09-04 17:20:18 +02:00
|
|
|
class MyFlask(Flask):
|
|
|
|
|
|
|
|
def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):
|
|
|
|
if not self.debug or os.getenv("WERKZEUG_RUN_MAIN") == 'true':
|
|
|
|
with self.app_context():
|
|
|
|
led.setup()
|
|
|
|
super(MyFlask, self).run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options)
|
|
|
|
|
|
|
|
app = MyFlask(__name__)
|
2024-09-04 16:53:56 +02:00
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def index():
|
|
|
|
return "Benvenuto nel raspberry."
|
|
|
|
|
|
|
|
@app.route('/accendi')
|
|
|
|
@app.route('/on')
|
2024-09-04 17:04:12 +02:00
|
|
|
def accendi():
|
2024-09-04 16:53:56 +02:00
|
|
|
led.pin_on()
|
2024-09-04 17:04:12 +02:00
|
|
|
if led.stato_pin():
|
|
|
|
return "LED acceso."
|
|
|
|
|
|
|
|
return "LED Spento."
|
|
|
|
|
2024-09-04 16:53:56 +02:00
|
|
|
@app.route('/spegni')
|
|
|
|
@app.route('/off')
|
2024-09-04 17:04:12 +02:00
|
|
|
def spegni():
|
2024-09-04 16:53:56 +02:00
|
|
|
led.pin_off()
|
2024-09-04 17:11:19 +02:00
|
|
|
if led.stato_pin():
|
|
|
|
return "LED acceso."
|
|
|
|
|
|
|
|
return "LED spento."
|
2024-09-04 16:53:56 +02:00
|
|
|
|
|
|
|
@app.route('/toggle')
|
2024-09-04 17:04:12 +02:00
|
|
|
def toggle():
|
2024-09-04 16:53:56 +02:00
|
|
|
led.toggle()
|
2024-09-04 17:04:12 +02:00
|
|
|
if led.stato_pin():
|
|
|
|
return "Il LED è acceso."
|
|
|
|
|
|
|
|
return "Il LED è spento."
|
|
|
|
|
2024-09-04 16:53:56 +02:00
|
|
|
@app.route('/lampeggia')
|
|
|
|
def lampeggia():
|
|
|
|
led.lampeggia()
|
2024-09-04 17:04:12 +02:00
|
|
|
return "LED ha lampeggiato."
|
2024-09-04 16:53:56 +02:00
|
|
|
|
2024-09-04 17:20:18 +02:00
|
|
|
app.run()
|