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

31 lines
538 B
Python
Raw Normal View History

import atexit
from flask import Blueprint
2018-05-03 20:30:34 +00:00
from .mqtt_client import MqttClient
2018-04-26 12:12:20 +00:00
2018-05-06 19:42:21 +00:00
devices_bp = Blueprint('devices', __name__)
2018-05-04 06:35:26 +00:00
mqtt_client = None
2018-04-26 12:12:20 +00:00
2018-05-03 07:48:24 +00:00
2018-04-27 09:15:44 +00:00
# When app dies, stop mqtt connection
def on_stop():
2018-05-04 06:35:26 +00:00
if mqtt_client:
mqtt_client.tear_down()
2018-04-26 13:03:38 +00:00
2018-05-03 07:48:24 +00:00
atexit.register(on_stop)
2018-05-03 07:48:24 +00:00
2018-04-27 09:15:44 +00:00
# Routes
2018-05-06 19:42:21 +00:00
@devices_bp.route("/")
def hello():
return "Hello from devices!"
2018-05-06 19:42:21 +00:00
@devices_bp.record
2018-04-27 09:15:44 +00:00
def on_blueprint_setup(setup_state):
2018-05-04 06:35:26 +00:00
print('Blueprint setup')
mqtt_client = MqttClient()
if mqtt_client:
mqtt_client.setup(setup_state.app)