status update consumption done
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
22
src/app.py
22
src/app.py
@@ -8,6 +8,8 @@ from sentry_sdk.integrations.flask import FlaskIntegration
|
||||
from config import *
|
||||
from db import db
|
||||
from marshm import ma
|
||||
from mqtt_flask_instance import mqtt
|
||||
|
||||
"""
|
||||
Main Flask RESTful API
|
||||
"""
|
||||
@@ -28,11 +30,17 @@ if SENTRY_DSN:
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['MQTT_BROKER_URL'] = MQTT_HOSTNAME
|
||||
app.config['MQTT_BROKER_PORT'] = MQTT_PORT
|
||||
app.config['MQTT_USERNAME'] = MQTT_USERNAME
|
||||
app.config['MQTT_PASSWORD'] = MQTT_PASSWORD
|
||||
app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}"
|
||||
|
||||
api = Api(app)
|
||||
db.init_app(app)
|
||||
ma.init_app(app)
|
||||
mqtt.init_app(app)
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
@@ -48,6 +56,17 @@ logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(handler)
|
||||
|
||||
|
||||
@mqtt.on_log()
|
||||
def handle_logging(client, userdata, level, buf):
|
||||
logger.log(level, buf)
|
||||
|
||||
|
||||
@mqtt.on_connect()
|
||||
def handle_connect(client, userdata, flags, rc):
|
||||
mqtt.subscribe(MQTT_STATUS_TOPIC)
|
||||
|
||||
|
||||
# api.add_resource(SampleResource, "/sample")
|
||||
# api.add_resource(SampleParameterResource, '/sample/<tag>')
|
||||
|
||||
@@ -55,5 +74,6 @@ if __name__ == "__main__":
|
||||
app.run(
|
||||
debug=bool(DEBUG),
|
||||
host="0.0.0.0",
|
||||
use_reloader=False,
|
||||
port=int(PORT),
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user