main.py 928 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import threading
  2. from flask import Flask, render_template
  3. from gevent.pywsgi import WSGIServer
  4. from common.read_config import ReadConfig
  5. from dao import machinery_dao
  6. from device import machinery_service
  7. main = Flask(__name__)
  8. @main.route('/')
  9. def index():
  10. model = "后台数据"
  11. return render_template('index.html', model=[model])
  12. @main.route('/load_data', methods=['POST'])
  13. def load_data():
  14. show_val = machinery_dao.query_machinery()
  15. if len(show_val) == 0:
  16. show_val = {}
  17. return show_val
  18. def startHttp():
  19. serverip = "0.0.0.0"
  20. http_port = ReadConfig().get_common_port("http_port")
  21. print("启动HTTP:" + serverip + ":" + http_port)
  22. WSGIServer((serverip, int(http_port)), main).serve_forever()
  23. if __name__ == '__main__':
  24. thread_web = threading.Thread(target=machinery_service.lora_db, name='lora_db')
  25. thread_web.daemon = True
  26. thread_web.start()
  27. startHttp()