-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask_app.py
executable file
·49 lines (40 loc) · 1.21 KB
/
flask_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
from flask import Flask, render_template, send_from_directory
from flask_socketio import SocketIO
import smbus2
import os
bus = smbus2.SMBus(1)
address = 0x04
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
app.config['host'] = '0.0.0.0'
socketio = SocketIO(app)
@socketio.on('message')
def handle_message(message):
print('received message: ' + str(message))
if isinstance(message, int):
if message > -1 and message < 9:
print("sending int " + str(message))
bus.write_byte(address, message)
else:
print("message is not an int?")
@socketio.on('speak')
def handle_message(message):
if isinstance(message, str):
os.system("espeak '" + message + "'")
else:
print("message is not a string")
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.route('/js/<path:path>')
def js_files(path):
return send_from_directory('static/js', path)
@app.route('/css/<path:path>')
def css_files(path):
return send_from_directory('static/css', path)
@app.route('/images/<path:path>')
def image_files(path):
return send_from_directory('static/img', path)
if __name__ == '__main__':
socketio.run(app)