-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.py
executable file
·63 lines (48 loc) · 1.44 KB
/
webserver.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
import rospy
from std_msgs.msg import String
from diagnostic_msgs.msg import DiagnosticArray
from std_msgs.msg import Float32MultiArray
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
import json
import yaml
app = Flask(__name__)
app.config['SECRET_KEY'] = 'pepper'
socketio = SocketIO(app)
@socketio.on('connect')
def test_connect():
print("Connected")
emit('res', {'text': 'Connected'})
@socketio.on('disconnect')
def test_disconnect():
print('Client disconnected')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/diagnostics')
def diagnostics():
return render_template('diagnostics.html')
@app.route('/audio')
def audio():
return render_template('audio.html')
def callback(data):
new_data = dict()
new_data['data'] = data.data
socketio.emit('ros_msg', new_data)
def diagnostics(data):
y = yaml.load(str(data))
j = json.dumps(y, indent=4)
socketio.emit('ros_diagnostics', j)
def audio(data):
socketio.emit('ros_audio', json.dumps(data.data))
if __name__ == '__main__':
rospy.init_node('webserver', anonymous=True)
rospy.Subscriber("/speech", String, callback)
rospy.Subscriber("/diagnostics", DiagnosticArray, diagnostics)
rospy.Subscriber('/audio_localization', Float32MultiArray, audio)
try:
app.run(host='0.0.0.0', port=5010)
except KeyboardInterrupt:
pass
# rospy.spin()