-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
60 lines (46 loc) · 1.78 KB
/
server.py
File metadata and controls
60 lines (46 loc) · 1.78 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
57
58
59
60
from flask import Flask, request
import subprocess
import json
app = Flask(__name__, template_folder='templates', static_folder='static')
@app.route("/postStart/", methods=['GET', 'POST'])
def post_start():
#START
#Main dosyasını çalıştırmak
try:
subprocess.Popen("py -3.7 main.py", shell=True)
##Burada python 3.7 nin bilgisayarda kurulu oldugu dizin gereklidir.
#subprocess.run(["python", "C:/Users/egezt/OneDrive/Masaüstü/Mostra Klasör/WindowsNoEditor/PythonAPI/ControllerTest/main.py"])
return "python file worked"
except Exception as e:
print("Error:", str(e))
return "Error"
@app.route("/postStop/", methods=['GET', 'POST'])
def post_stop():
with open('coordinates.txt', 'w') as f:
f.write("Stop") # Koordinatları dosyaya yaz
##STOP ###TXT File
return "Stop"
@app.route("/postredLight/", methods=['GET', 'POST'])
def post_redLight():
return "Red Light"
@app.route("/postgreenLight/", methods=['GET', 'POST'])
def post_greenLight():
return "Green Light"
@app.route("/postCoordinates/", methods=['GET','POST'])
def post_sendCoordinates():
try:
data = request.json
coordinates = data.get('coordinates')
print("Received coordinates:", coordinates)
coordinates_list = coordinates.split()
#print("Received coordinates:", coordinates_list)
with open('coordinates.txt', 'w') as f:
f.write(coordinates) # Koordinatları dosyaya yaz
#json_veri = json.dumps(coordinates_list)
return data
except Exception as e:
print("Error:", str(e))
return "Error"
if __name__ == '__main__':
# Uygulamayı 0.0.0.0 adresine yayınla ve portu belirt
app.run(host='0.0.0.0', port=5000, debug=True)