From 3481ade44953d57641fff593d016a403f8214635 Mon Sep 17 00:00:00 2001 From: Koen De Voegt Date: Thu, 17 Mar 2011 00:05:38 +0100 Subject: [PATCH] the cgi files --- cgi-bin | 1 - cgi-bin/all | 45 +++++++++++++++++++++++++++++++++++++++++++++ cgi-bin/relay | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) delete mode 120000 cgi-bin create mode 100755 cgi-bin/all create mode 100755 cgi-bin/relay diff --git a/cgi-bin b/cgi-bin deleted file mode 120000 index 8869951..0000000 --- a/cgi-bin +++ /dev/null @@ -1 +0,0 @@ -/usr/lib/cgi-bin \ No newline at end of file diff --git a/cgi-bin/all b/cgi-bin/all new file mode 100755 index 0000000..6342163 --- /dev/null +++ b/cgi-bin/all @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import cgi +import serial +import time +import sys +import getpass + +serialPort = "/dev/ttyACM0" + +print "Content-type: text/html" +print "" + +command = "" + +try: + fs = cgi.FieldStorage() + command = fs["value"].value +except: + try: + command = sys.argv[1] + except: + print "Error!!!", sys.exc_info()[0] + +ser = serial.Serial(serialPort, 2400) + +ser.open() +for i in range(0, 4): + command = "%" + str(i) + "#" + command + ser.write(command) + + time.sleep(0.4) + + while ser.inWaiting() > 0: + ser.read() + +time.sleep(1) + +while ser.inWaiting() > 0: + ser.read() + +ser.close() + +print '' + diff --git a/cgi-bin/relay b/cgi-bin/relay new file mode 100755 index 0000000..2e0f528 --- /dev/null +++ b/cgi-bin/relay @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +import cgi +import serial +import time +import sys +import getpass + +serialPort = "/dev/ttyACM0" + +print "Content-type: text/html" +print "" + +command = "" + +try: + fs = cgi.FieldStorage() + command = "%" + fs["relay"].value + "#" + fs["value"].value +except: + try: + command = "%" + sys.argv[1] + "#" + sys.argv[2] + except: + print "Error!!!", sys.exc_info()[0] + +ser = serial.Serial(serialPort, 2400) + +ser.open() + +ser.write(command) + +time.sleep(0.3) + +while ser.inWaiting() > 0: + ser.read() + +ser.close() + +print '' +