mirror of
https://codeberg.org/mclemens/hr50-api.git
synced 2024-12-22 16:16:39 -05:00
added new method "exec"
This commit is contained in:
parent
a0112821f2
commit
c3932ce4eb
31
hr50api.py
31
hr50api.py
@ -3,9 +3,11 @@ import sys
|
|||||||
import getopt
|
import getopt
|
||||||
import time
|
import time
|
||||||
import serial
|
import serial
|
||||||
|
from subprocess import check_output
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
exec_cmd = "/home/pi/bin/toggle_antenna.sh"
|
||||||
serial_port = '/dev/ttyUSB0'
|
serial_port = '/dev/ttyUSB0'
|
||||||
baud = 19200
|
baud = 19200
|
||||||
|
|
||||||
@ -107,19 +109,26 @@ def get_status():
|
|||||||
return jsonify(vlcd)
|
return jsonify(vlcd)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET'])
|
@app.route('/exec')
|
||||||
def send_command():
|
def exec_shell_command():
|
||||||
try:
|
out = check_output([exec_cmd, ""])
|
||||||
cmd = request.args.get('cmd', default="", type=str)
|
'''
|
||||||
data = send_cmd_via_serial(cmd)
|
x = jsonify(isError= False,
|
||||||
return jsonify(isError= False,
|
|
||||||
message= "Success",
|
message= "Success",
|
||||||
statusCode= 200,
|
statusCode= 200,
|
||||||
data= data), 200
|
data= out.decode("utf-8") ), 200
|
||||||
|
print(x)
|
||||||
|
'''
|
||||||
|
return out
|
||||||
|
|
||||||
|
@app.route('/', methods=['GET'])
|
||||||
|
def send_command():
|
||||||
|
ret = ""
|
||||||
|
try:
|
||||||
|
ret = request.args.get('cmd', default="", type=str)
|
||||||
|
send_cmd_via_serial(ret)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify(isError= True,
|
ret = "ERROR"
|
||||||
message= "Error",
|
return ret
|
||||||
statusCode= 200,
|
|
||||||
data= e), 200
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user