Browse Source

上傳檔案到 ''

rita 2 years ago
parent
commit
8cced300c3
1 changed files with 35 additions and 34 deletions
  1. 35 34
      coffee_manage.py

+ 35 - 34
coffee_manage.py

@@ -1,35 +1,36 @@
-#啟動和管理項目
-from app import create_app
-from flask import request
-from gevent import pywsgi
-
-# Rita 原本都是 app = Flask(name), 若要建立多個"工廠", 則使用 create_app() 函式(在 __init__.py 中)
-app, db, mqtt = create_app()
-
-#mqtt訂閱
-@mqtt.on_connect()
-def handle_connect(client, userdata, flags, rc):
-    # Rita MQTT 是以 broker 做分發, subscribe 接收 'Topic' 的資料
-    # 'AISKY/Coffee/MK-G/b8:27:eb:b4:59:3e/Log' 就是本次的 Topic, 此命名也有 AISKY 公司 Coffee 專案 MK-G ... 這樣的階層關係(不影響 Topic 和 MQTT 傳輸)
-    mqtt.subscribe('AISKY/Coffee/MK-G/b8:27:eb:b4:59:3e/Log')
-
-
-#調用日誌訊息
-@mqtt.on_log()
-def handle_logging(client, userdata, level, buf):
-    print(client, userdata, level, buf)
-
-#自動關閉所有未使用、掛著的連接
-@app.teardown_appcontext
-def shutdown_session(exception=None):
-    db.session.remove()
-
-
-
-if __name__ == '__main__':
-    # Benson 測試網頁 http://192.168.50.65:5010/login
-    app.run(host='0.0.0.0', port=5010, debug=False, threaded=True)
-    #使用WSGI開關,避免出現WARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.
-    # server = pywsgi.WSGIServer(('0.0.0.0', 5006), app)
-    # server.serve_forever()
+#啟動和管理項目
+from sqlalchemy import true
+from app import create_app
+from flask import request
+from gevent import pywsgi
+
+# Rita 原本都是 app = Flask(name), 若要建立多個"工廠", 則使用 create_app() 函式(在 __init__.py 中)
+app, db, mqtt = create_app()
+
+#mqtt訂閱
+@mqtt.on_connect()
+def handle_connect(client, userdata, flags, rc):
+    # Rita MQTT 是以 broker 做分發, subscribe 接收 'Topic' 的資料
+    # 'AISKY/Coffee/MK-G/b8:27:eb:7e:24:78/Log' 就是本次的 Topic, 此命名也有 AISKY 公司 Coffee 專案 MK-G ... 這樣的階層關係(不影響 Topic 和 MQTT 傳輸)
+    mqtt.subscribe('AISKY/Coffee/MK-G/b8:27:eb:7e:24:78/Log')
+
+
+#調用日誌訊息
+@mqtt.on_log()
+def handle_logging(client, userdata, level, buf):
+    print(client, userdata, level, buf)
+
+#自動關閉所有未使用、掛著的連接
+@app.teardown_appcontext
+def shutdown_session(exception=None):
+    db.session.remove()
+
+
+
+if __name__ == '__main__':
+    # Benson 測試網頁 http://192.168.50.65:5010/login
+    app.run(host='0.0.0.0', port=5010, debug=True, threaded=True)
+    #使用WSGI開關,避免出現WARNING: This is a development server. Do not use it in a production deployment.Use a production WSGI server instead.
+    # server = pywsgi.WSGIServer(('0.0.0.0', 5006), app)
+    # server.serve_forever()
     # 加上 threaded=True, 就會以多線程啟動, 以支持網頁 ajax 請求