manage.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:c1:72:0c/Log')
  9. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:84:e9:3f/Log')
  10. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:95:00:53/Log')
  11. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:e7:51:44/Log')
  12. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:ce:a5:35/Log')
  13. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:fc:9d:34/Log')
  14. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:86:00:c9/Log')
  15. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:df:4b:0f/Log')
  16. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:6a:5d:17/Log')
  17. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:d2:d0:8f/Log')
  18. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:57:3c:da/Log')
  19. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:bd:29:b1/Log')
  20. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:7c:f6:06/Log')
  21. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:59:9d:bd/Log')
  22. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:e7:21:e5/Log')
  23. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:34:9e:39/Log')
  24. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:e3:f1:f4/Log')
  25. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:f8:24:92/Log')
  26. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:9d:68:05/Log')
  27. mqtt.subscribe('AISKY/AppleFarm/MK-G/b8:27:eb:4d:e4:34/Log')
  28. #調用日誌訊息
  29. @mqtt.on_log()
  30. def handle_logging(client, userdata, level, buf):
  31. print(level, buf)
  32. #自動關閉所有未使用、掛著的連接
  33. @app.teardown_appcontext
  34. def shutdown_session(exception=None):
  35. db.session.remove()
  36. if __name__ == '__main__':
  37. app.run(debug=False, host='0.0.0.0', port=5555)