36 lines
818 B
Python
36 lines
818 B
Python
import os
|
|
|
|
from flask import Flask
|
|
|
|
def create_app():
|
|
app = Flask(__name__, instance_relative_config=True)
|
|
app.config.from_mapping(
|
|
SECRET_KEY=os.urandom(24),
|
|
DATABASE=os.path.join(app.instance_path, 'data.db'),
|
|
)
|
|
|
|
try:
|
|
os.makedirs(app.instance_path)
|
|
except OSError:
|
|
pass
|
|
|
|
from . import db
|
|
db.init_app(app)
|
|
|
|
from . import controller
|
|
app.register_blueprint(controller.bp)
|
|
|
|
from .mqttHandler import mqtt, bp as mqtt_bp
|
|
app.register_blueprint(mqtt_bp)
|
|
|
|
app.config['MQTT_BROKER_URL'] = 'localhost'
|
|
app.config['MQTT_BROKER_PORT'] = 1883
|
|
app.config['MQTT_USERNAME'] = 'user'
|
|
app.config['MQTT_PASSWORD'] = 'test'
|
|
app.config['MQTT_KEEPALIVE'] = 5
|
|
app.config['MQTT_TLS_ENABLED'] = False
|
|
|
|
mqtt.init_app(app)
|
|
|
|
return app
|