This repository was archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
56 lines (46 loc) · 1.34 KB
/
server.py
File metadata and controls
56 lines (46 loc) · 1.34 KB
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
# Group: 24
# Names: Divy, Elio, Kelvin, Matthew
from flask import Flask, request
from flask_cors import CORS
"""
Server that runs on a laptop and controls the robot's movement.
Devices can sent and receive data from the server via connecting
to the server's IP address and port 5000 via the laptop's wifi
hotspot.
"""
app = Flask(__name__)
CORS(app)
"""
For individual move selection
-1: Return to sequence
1-6: Specific move
"""
move = -1
@app.route('/move', methods=['GET'], defaults={'path': ''})
def get_move(path):
"""Returns the current move as a string"""
global move
return str(move)
@app.route('/move', methods=['POST'], defaults={'path': ''})
def post_move(path):
"""Sets the current move"""
global move
if request.is_json:
content = request.json
if content is not None:
field = content['move']
print(f"Received: {field}")
if isinstance(field, int) and field >= 1 and field <= 6:
move = field
return f"Move {field} Sent"
elif field == -1:
move = field
return "Returning to sequence"
else:
return "Invalid move"
else:
return "Invalid JSON"
else:
return "Not JSON"
if __name__ == '__main__':
app.run(port=5000, host="192.168.137.1")