Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template
- from flask import request
- from flask_socketio import SocketIO, emit
- from OpenSSL import SSL
- temperature_value = 0
- app = Flask(__name__, template_folder='.')
- app.config['SECRET_KEY'] = 'secret!'
- context = SSL.Context(SSL.SSLv23_METHOD)
- context.use_privatekey_file('/home/zoltan/www.cog-dev.xyz.key')
- context.use_certificate_file('/home/zoltan/www_cog-dev_xyz.crt')
- socketio = SocketIO(app)
- @app.route('/postjson', methods = ['POST'])
- def postJsonHandler():
- global temperature_value
- content = request.get_json()
- print (content, flush = True)
- temperature_value = content['temperature']
- socketio.emit('temperature', {'data': temperature_value})
- return 'JSON posted'
- @socketio.on('my event')
- def test_message(message):
- global temperature_value
- print ("Send", flush = True)
- emit('temperature', {'data': message[temperature_value]})
- @app.route('/')
- @app.route('/index')
- def index():
- global temperature_value
- return render_template('index.html',
- async_mode=socketio.async_mode)
- if __name__ == "__main__":
- context = ('/home/zoltan/www_cog-dev_xyz.crt', '/home/zoltan/www.cog-dev.xyz.key')
- socketio.run(app, host='0.0.0.0', debug=True, ssl_context=context)
- # app.run(host='0.0.0.0')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement