我有一个处理传感器数据的本地烧瓶服务器。当温度大于某个阈值时,它会获取温度值并调整灯光。到目前为止,它仅在一个客户端保持浏览器打开该页面时才有效。如果服务器可以在不一直打开浏览器的情况下更新温度值并调整光线,那就太好了。如何让它在后台运行?temperture = 0threshold_temp = 0def read_temp(): #read temperature valuesserver = Flask(__name__)socketio = SocketIO(server)app = dash.Dash(__name__, server = server, url_base_pathname="/dash/")@server.route('/_stuff')def stuff(): global threshold_temp temperature = read_temp() if temperature >= threshold_temp: #change light else: #do not change light return jsonify(result = temperature)#Change Threshold@socketio.on('message')def handleMessage(msg): global threshold_temp threshold_temp = float(msg) send(msg, broadcast=True) f = open("Threshold.txt", "w") f.write(msg) f.close()#Adjust Threshold on Connection of Client@socketio.on('connect')def on_connect(): global threshold_temp f = open("Threshold.txt", "r") threshold_temp = float(f.read()) send(threshold_temp, broadcast=True)@server.route('/')def index(): return render_template('index.html')if __name__ == '__main__': socketio.run(server, host='0.0.0.0', port=80, debug=False)
添加回答
举报
0/150
提交
取消