WillemVH commited on
Commit
c7bf148
·
verified ·
1 Parent(s): 63b370c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -45
app.py CHANGED
@@ -1,53 +1,16 @@
1
  from flask import Flask, request
2
  import requests
3
  import time
4
-
5
- ESP_IP = ''
6
- pending_commands = []
7
-
8
- app = Flask(__name__)
9
-
10
- def send_servo_command(servo_num, angle):
11
- try:
12
- print(ESP_IP)
13
- url = f"http://{ESP_IP}/{servo_num}?angle={angle}"
14
- response = requests.get(url, timeout=1)
15
- time.sleep(60/angle)
16
- print(servo_num)
17
- url = f"http://{ESP_IP}/stop"
18
- response = requests.get(url, timeout=1)
19
- return f"Servo {servo_num} → {angle}°"
20
- except Exception as e:
21
- return f"Error: {e}"
22
-
23
  @app.route('/')
24
- def the():
25
- pending_commands.extend(["servo1_180", "servo2_180", "servo3_180"])
26
- return 'hello worlddd'
27
 
28
  @app.route('/input')
29
- def get_input():
30
- global ESP_IP
31
- data = request.args.get('data')
32
- ESP_IP = data.replace('_','.')
33
- print(ESP_IP)
34
- return ESP_IP
35
-
36
- @app.route('/get_commands')
37
- def get_commands():
38
- device_id = request.args.get('device_id')
39
- if pending_commands:
40
- command = pending_commands.pop(0)
41
- return command
42
- return ""
43
-
44
- @app.route('/send_command')
45
- def send_command():
46
- command = request.args.get('command')
47
- if command:
48
- pending_commands.append(command)
49
- return f"Command '{command}' queued"
50
- return "No command provided"
51
-
52
  if __name__ == '__main__':
53
  app.run(host='0.0.0.0', port=5000, debug=False)
 
1
  from flask import Flask, request
2
  import requests
3
  import time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  @app.route('/')
5
+ def main():
6
+ return 'a very nice page, you must admit'
 
7
 
8
  @app.route('/input')
9
+ def apirequests():
10
+ # =?id,servo
11
+ full_query = request.query_string.decode('utf-8')
12
+ if full_query.startswith('='):
13
+ data = full_query[1:]
14
+ return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  if __name__ == '__main__':
16
  app.run(host='0.0.0.0', port=5000, debug=False)