Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,12 @@
|
|
| 1 |
from flask import Flask, request
|
| 2 |
import requests
|
| 3 |
import time
|
|
|
|
| 4 |
ESP_IP = ''
|
|
|
|
|
|
|
| 5 |
app = Flask(__name__)
|
|
|
|
| 6 |
def send_servo_command(servo_num, angle):
|
| 7 |
try:
|
| 8 |
print(ESP_IP)
|
|
@@ -18,9 +22,7 @@ def send_servo_command(servo_num, angle):
|
|
| 18 |
|
| 19 |
@app.route('/')
|
| 20 |
def the():
|
| 21 |
-
|
| 22 |
-
send_servo_command(2, 180)
|
| 23 |
-
send_servo_command(3, 180)
|
| 24 |
return 'hello worlddd'
|
| 25 |
|
| 26 |
@app.route('/input')
|
|
@@ -31,5 +33,21 @@ def get_input():
|
|
| 31 |
print(ESP_IP)
|
| 32 |
return ESP_IP
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
if __name__ == '__main__':
|
| 35 |
app.run(host='0.0.0.0', port=5000, debug=False)
|
|
|
|
| 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)
|
|
|
|
| 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')
|
|
|
|
| 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)
|