if type(a) is int : print "Error parsing house input, return value is " + str(a) exit(a) action = [(a,b,c)] else : # Cron Entry Point timespan = int(sys.argv[1]) lightMode = int(sys.argv[2]) action = determineActions(lightMode) startTime = sys.argv[3] if len(sys.argv) > 4: startTZ = sys.argv[4] else: startTZ = None waitForStart(timespan, startTime, startTZ) LOGFILE = 'cm19.log.' + str(os.getpid()) log = CM19aDriver.startLogging(logfile=LOGFILE) print "\nInitializing..." cm19a = CM19aDriver.CM19aDevice(1, log, polling = False) #Initialize device if not cm19a.initialised > 0: print "CM19a Driver: failed to initialize - See log for errors\n" else: for args in action : (House, Unit, Action) = args cm19a.send(House, Unit, Action) print "Return: %s %d %s" % (House, Unit, Action) cm19a.finish()
POLLFREQ = 1 WINDOW_WIDTH = 600 WINDOW_HEIGHT = 300 # Create the root widget for the application root = Tk() root.withdraw() try: if CM19aDriver.VERSION < 3.00: tkMessageBox.showerror("Cm19a Driver","The app requires version 3.00 of the driver or above. You are using version %r." % cm19aDriver.VERSION) except: tkMessageBox.showerror("Cm19a Driver","The app requires version 3.00 of the driver or above. Please download a leter version from www cuddon.net") # Start logging log = CM19aDriver.startLogging() # log is an instance of the logger class # Open the device and configure cm19a = CM19aDriver.CM19aDevice(POLLFREQ, log, polling = True) if not cm19a.initialised > 0: tkMessageBox.showerror("Cm19a Driver","Error initialising the Cm19a device.\n See log for more info.") else: # Set up the root window root.title(string="CM19a driver example front end (v%s) - Driver version: %s" % (VERSION, CM19aDriver.VERSION)) root.resizable(width=None, height=None) # get screen width and height ws = root.winfo_screenwidth() hs = root.winfo_screenheight() # calculate position x, y x = (ws/2) - (WINDOW_WIDTH/2)
startTime = sys.argv[3] if len(sys.argv) > 4: startTZ = sys.argv[4] else: startTZ = None pt.waitForStart(timespan, startTime, startTZ) print print "*************************" print time.strftime("%A %m/%d/%y %H:%M:%S") mypid = os.getpid() #LOGFILE = '/home/chf/Log/cm19aLog.' + str(mypid) LOGFILE = '/home/chf/Log/cm19a.log' log = CM19aDriver.startLogging(progname="Lights.py",logfile=LOGFILE) print "\nInitializing..." cm19a = CM19aDriver.CM19aDevice(1, log, polling = False) #Initialize device if not cm19a.initialised > 0: print "CM19a Driver: failed to initialize - See log for errors\n" log.error ('CM19a Driver: failed to initialize') cm19a.finish() sys.exit(5) else: for args in action : (House, Unit, Action) = args if not House in [ 1, 2, 3 ] : result = cm19a.send(House, Unit, Action) if not result: print 'Command failed: %s%s %s' % (House, Unit, Action)
import os import sys # CM19a module from https://github.com/Cuddon/cm19a import CM19aDriver # *************** CONFIGURATION *************** POLLFREQ = 1 # Polling Frequency - Check for inbound commands every 1 second # pinging Google's anycast DNS server HOST = '8.8.8.8' # FAILURE needs to be determined by what the system ping returns FAILURE = '0 received' # prior failure test #if 'request timed out' in data or 'Unreachable' or "100% packet loss" in data: # Start logging and initialize driver log = CM19aDriver.startLogging() # log is an instance of the logger class cm19a = CM19aDriver.CM19aDevice(POLLFREQ, log, polling=True) def test(): if (os.path.exists('/tmp/teston')): if cm19a.initialised: print "Turning on test..." print time.ctime() result = cm19a.send("C", "1", "on") if result: print "...Success" else: print >> sys.stderr, "Command failed" os.remove('/tmp/teston') if (os.path.exists('/tmp/testoff')):