From 927f7df669875974185a4013a5b1c40a44d3d966 Mon Sep 17 00:00:00 2001 From: Steve28 Date: Sun, 29 Apr 2018 09:51:06 -0700 Subject: [PATCH] modified to work with Home Assistant --- mca66_server.py | 17 ++++++++++------- mca66_server.sh | 10 +++++----- 2 files changed, 15 insertions(+), 12 deletions(-) mode change 100644 => 100755 mca66_server.py diff --git a/mca66_server.py b/mca66_server.py old mode 100644 new mode 100755 index d71cfa5..6d654db --- a/mca66_server.py +++ b/mca66_server.py @@ -6,16 +6,14 @@ # Open the serial port to communicate with the MCA-66 # Exit if it fails. -# Deafults -logfile = open('/tmp/mca66_server.log','w',0) +# Defults +logfile = open('/var/log/mca66_server/server.log','w',0) sys.stdout = logfile sys.stderr = logfile - - - audio = mca66.MCA66('/dev/ttyUSB0') if audio.open() is False: + print("False!!") sys.exit() # define list of commands we handle @@ -35,10 +33,12 @@ def GET(self): class controller: def GET(self): + print("Received GET") # we're going to return JSON web.header('Content-Type', 'application/json') # Grab the arguements from the URL user_data = web.input() + print("user_data:",user_data) #print user_data, commands # do some input validation if 'command' in user_data: @@ -46,7 +46,7 @@ def GET(self): if command in get_commands: print("Processing...",command) zone = int(user_data.zone) if 'zone' in user_data else None - + # Process the commnads if command == "status": if zone: @@ -68,6 +68,9 @@ def POST(self): # we're going to return JSON web.header('Content-Type', 'application/json') + print("Received POST") + print("user_data:",user_data) + print("data:", web.data()) if 'command' in user_data: command = user_data.command.lower() if command in post_commands: @@ -121,4 +124,4 @@ def POST(self): if __name__ == "__main__": app = web.application(urls, globals()) - app.run() \ No newline at end of file + app.run() diff --git a/mca66_server.sh b/mca66_server.sh index d265c10..7c8a68c 100644 --- a/mca66_server.sh +++ b/mca66_server.sh @@ -6,17 +6,17 @@ # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 -# Short-Description: Put a short description of the service here -# Description: Put a long description of the service here +# Short-Description: MCA-66 Server +# Description: MCA-66 Server ### END INIT INFO # Change the next 3 lines to suit where you install your script and what you want to call it -DIR=/usr/local/bin/myservice +DIR=/usr/local/bin/mca66_server DAEMON=$DIR/mca66_server.py DAEMON_NAME=mca66_server # Add any command line options for your daemon here -DAEMON_OPTS="-l" +DAEMON_OPTS="" # This next line determines what user the script runs as. # Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python. @@ -29,7 +29,7 @@ PIDFILE=/var/run/$DAEMON_NAME.pid do_start () { log_daemon_msg "Starting system $DAEMON_NAME daemon" - start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS + start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --chdir $DIR --startas $DAEMON -- $DAEMON_OPTS log_end_msg $? } do_stop () {