#啟動和管理項目 from app import create_app app, db, mqtt = create_app() #mqtt訂閱 @mqtt.on_connect() def handle_connect(client, userdata, flags, rc): mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:b7:52:9c/Log') #調用日誌訊息 @mqtt.on_log() def handle_logging(client, userdata, level, buf): print(level, buf) #自動關閉所有未使用、掛著的連接 @app.teardown_appcontext def shutdown_session(exception=None): db.session.remove() if __name__ == '__main__': app.run(debug=False, threaded=True, host='0.0.0.0', port=5000)