mirror of
https://codeberg.org/mclemens/hr50-api.git
synced 2024-12-22 11:36:48 -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 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('/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'])
|
@app.route('/', methods=['GET'])
|
||||||
def send_command():
|
def send_command():
|
||||||
|
ret = ""
|
||||||
try:
|
try:
|
||||||
cmd = request.args.get('cmd', default="", type=str)
|
ret = request.args.get('cmd', default="", type=str)
|
||||||
data = send_cmd_via_serial(cmd)
|
send_cmd_via_serial(ret)
|
||||||
return jsonify(isError= False,
|
|
||||||
message= "Success",
|
|
||||||
statusCode= 200,
|
|
||||||
data= data), 200
|
|
||||||
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