university-final-iot-backend/app/mod_devices/__init__.py

27 lines
459 B
Python
Raw Normal View History

import atexit
from flask import Blueprint
2018-04-27 08:47:24 +00:00
from .. import db
2018-04-27 09:15:44 +00:00
from .mqtt_client import tear_down_mqtt, setup_mqtt
2018-04-26 12:12:20 +00:00
devices = Blueprint('devices', __name__)
2018-04-26 12:12:20 +00:00
2018-04-27 09:15:44 +00:00
# Models
2018-04-27 08:47:24 +00:00
from .models import Recording
2018-04-27 09:15:44 +00:00
# When app dies, stop mqtt connection
def on_stop():
tear_down_mqtt()
2018-04-26 13:03:38 +00:00
atexit.register(on_stop)
2018-04-27 09:15:44 +00:00
# Routes
@devices.route("/")
def hello():
return "Hello from devices!"
@devices.record
2018-04-27 09:15:44 +00:00
def on_blueprint_setup(setup_state):
setup_mqtt(setup_state.app)
2018-04-27 08:47:24 +00:00