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