added new method "exec"

This commit is contained in:
Michael Clemens 2021-11-27 00:32:15 +00:00
parent a0112821f2
commit c3932ce4eb

View File

@ -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