Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import *
- import door_open
- from door_open import LEDInit
- from time import sleep
- import pickle
- LEDInit('starting')
- app = Flask(__name__)
- pibtn = door_open
- lstatus = 0
- def writestatus(ledst):
- with open('status.pickle', 'wb') as filef:
- pickle._dump(ledst, filef)
- def loadststus():
- with open('status.pickle', 'rb') as filel:
- status = pickle.load(filel)
- return status
- writestatus(lstatus)
- print(loadststus())
- @app.route("/")
- def index():
- return render_template('index.html', ledstat=loadststus())
- LEDInit('init')
- @app.route("/led/<int:state>")
- def led(state):
- if state == 0:
- writestatus(state)
- door_open.__init__()
- door_open.set_led(False)
- print(loadststus())
- elif state == 1:
- writestatus(state)
- door_open.__init__()
- door_open.set_led(True)
- print(loadststus())
- else:
- return ('Unknown LED statement', 400)
- return ('', 204)
- @app.route("/switch")
- def switcΡ():
- def ReadLedState():
- while True:
- ledstatement = loadststus()
- yield 'data: {0}\n\n'.format(ledstatement)
- sleep(1)
- return Response(loadststus(), mimetype='text/event-stream')
- if __name__ == "__main__":
- app.run(host='0.0.0.0', debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement