2018-04-26 14:45:28 +00:00
|
|
|
import atexit
|
|
|
|
from flask import Blueprint
|
2018-04-27 08:47:24 +00:00
|
|
|
from .. import db
|
2018-04-26 12:12:20 +00:00
|
|
|
|
2018-04-26 14:45:28 +00:00
|
|
|
devices = Blueprint('devices', __name__)
|
2018-04-26 12:12:20 +00:00
|
|
|
|
2018-04-27 08:47:24 +00:00
|
|
|
from .models import Recording
|
2018-04-27 14:06:16 +00:00
|
|
|
# Models
|
|
|
|
|
|
|
|
# Mqtt
|
|
|
|
from .mqtt_client import tear_down_mqtt, setup_mqtt
|
2018-04-27 08:47:24 +00:00
|
|
|
|
2018-04-27 09:15:44 +00:00
|
|
|
# When app dies, stop mqtt connection
|
2018-04-26 14:45:28 +00:00
|
|
|
def on_stop():
|
|
|
|
tear_down_mqtt()
|
2018-04-26 13:03:38 +00:00
|
|
|
|
2018-04-26 14:45:28 +00:00
|
|
|
atexit.register(on_stop)
|
|
|
|
|
2018-04-27 09:15:44 +00:00
|
|
|
# Routes
|
2018-04-26 14:45:28 +00:00
|
|
|
@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
|
|
|
|