manage.py 570 B

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