31 lines
538 B
Python
31 lines
538 B
Python
import atexit
|
|
from flask import Blueprint
|
|
from .mqtt_client import MqttClient
|
|
|
|
devices_bp = Blueprint('devices', __name__)
|
|
mqtt_client = None
|
|
|
|
|
|
# When app dies, stop mqtt connection
|
|
def on_stop():
|
|
if mqtt_client:
|
|
mqtt_client.tear_down()
|
|
|
|
|
|
atexit.register(on_stop)
|
|
|
|
|
|
# Routes
|
|
@devices_bp.route("/")
|
|
def hello():
|
|
return "Hello from devices!"
|
|
|
|
|
|
@devices_bp.record
|
|
def on_blueprint_setup(setup_state):
|
|
print('Blueprint setup')
|
|
mqtt_client = MqttClient()
|
|
|
|
if mqtt_client:
|
|
mqtt_client.setup(setup_state.app)
|