-
Notifications
You must be signed in to change notification settings - Fork 1
/
webserver.py
95 lines (76 loc) · 2.8 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from flask import Flask, render_template, jsonify, request
from flask_socketio import SocketIO, emit, send
import eventlet
import time
from serverbrain import ServerBrain
import socket
# Allow us to reuse sockets after the are bound.
# http://stackoverflow.com/questions/25535975/release-python-flask-port-when-script-is-terminated
app = Flask(__name__)
socketio = SocketIO(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/getDrones')
def getDrones():
return jsonify(results=brain.getDroneNames())
@app.route('/checkOldSurvey', methods=['GET'])
def checkOldSurvey():
return jsonify({'data': brain.checkOldSurvey()})
@app.route('/connectDrone', methods=['POST'])
def connectDrone():
data = request.get_json()
message = brain.connectDrone(data['droneName'])
return jsonify({'data' : message})
@app.route('/buildPath', methods=['POST'])
def buildPath():
data = request.get_json()
path = brain.buildPath(data['droneName'], data['locationsList'])
return jsonify({'path' : path})
@app.route('/buildRectangularPath', methods=['POST'])
def buildRectangularPath():
data = request.get_json()
dataToReturn = brain.buildRectangularSurveyPointsReal(data)
return jsonify({'data' : dataToReturn})
@app.route('/flight', methods=['POST'])
def flight():
print "Inside flight"
data = request.get_json()
brain.takeAFlight(data['name'])
return 'Flight started'
@app.route('/oscillationFlight', methods=['POST'])
def oscillationFlight():
print "Inside oscillation flight"
data = request.get_json()
rData = brain.takeAnOscillationFlight(data['name'])
return jsonify({'data' : rData})
@app.route('/rectangularFlight', methods=['POST'])
def rectangularFlight():
print "Inside rectangular flight"
brain.takeARectangularFlight()
return "rectangular flight launched"
@app.route('/twoPointsFlight', methods=['POST'])
def twoPointsFlight(data):
print "Two points flight for ", data['name']
brain.takeATwoPointsFlight(data['name'])
return 'Two Points Flight Completed'
@app.route('/buildRandomPath', methods=['POST'])
def buildRandomPath():
drone = request.get_json()['drone']
randomPoints = brain.buildRandomPath(drone)
return jsonify({'data': randomPoints})
@socketio.on('response for live information')
def receive_live_info(message):
print "##########################################"
print "Just received the ack from client for arrived live information.."
print "Message says: " + message
print "##########################################"
print "\n"
@socketio.on('refreshing')
def refreshing():
print "stopping the server.."
if __name__ == '__main__':
print "Running the server..."
brain = ServerBrain(socketio)
app.threaded = True
socketio.run(app, use_reloader=True, debug=True)