Ejemplo n.º 1
0
    def init(self, configFile):

        # Track the file used to configure the current instance
        self.configFilePath = configFile

        # Set up handler for process termination
        signal.signal(signal.SIGTERM, onHomePiKilled)
        signal.signal(signal.SIGINT, onHomePiKilled)

        # Create a lock object for synchronization.
        self.threadLock = threading.Lock()

        # Feedback -  Performing cleanup.
        piglow.red(self.feedbackGlow)
        piglow.show()

        print 'Closing all existing GATT Connections... '
        self.closeAllGattConnections()
        print 'Done'

        # Feedback - Performing Config Initialization.
        piglow.red(0)
        piglow.orange(self.feedbackGlow)
        piglow.show()

        print 'Loading Home Devices... '
        regDevices = self.loadDevicesJSON(configFile)
        print 'Done Loading Home Device!'

        # Feedback - Connecting to registered devices.
        piglow.orange(0)
        piglow.yellow(self.feedbackGlow)
        piglow.show()

        print '\nAttempting connection to devices...'
        self.connectToRegisteredDevices(regDevices)
        print '\nConnection attempt done!'

        # Note: Seemed like a good idea but slows
        # down interaction with the HomePi while it is
        # trying to connect to the unavailable devices.
        # Removing for now until a better solution comes
        # to mind.
        #print '\nSpawning Device Checker Thread...'
        #self.statusChecker = HomePiDeviceStatusCheckerThread(self, 15)
        #self.statusChecker.setDaemon(True)
        #self.statusChecker.start()

        # Feedback - Ready and waiting for connections.
        piglow.red(0)
        piglow.orange(0)
        piglow.yellow(0)

        piglow.blue(self.feedbackGlow)
        piglow.show()

        # Listening to devices...
        self.listenForClients()
Ejemplo n.º 2
0
	def init(self, configFile):
	 
		# Set up handler for process termination
		signal.signal(signal.SIGTERM, onHomePiKilled)
		signal.signal(signal.SIGINT, onHomePiKilled)
	
		# Create a lock object for synchronization.
		self.threadLock = threading.Lock()

		# Feedback -  Performing cleanup.
		piglow.red(self.feedbackGlow)
		piglow.show()

		print 'Closing all existing GATT Connections... '
		self.closeAllGattConnections()	
		print 'Done'
		
		# Feedback - Performing Config Initialization.
		piglow.red(0)
		piglow.orange(self.feedbackGlow)
		piglow.show()

		print 'Loading Home Devices... '
		regDevices = self.loadDevicesJSON(configFile)
		print 'Done Loading Home Device!'

		# Feedback - Connecting to registered devices.
		piglow.orange(0)
		piglow.yellow(self.feedbackGlow)
		piglow.show()

		print '\nAttempting connection to devices...'
		self.connectToRegisteredDevices(regDevices)
		print '\nConnection attempt done!'
		
		# Note: Seemed like a good idea but slows 
		# down interaction with the HomePi while it is 
		# trying to connect to the unavailable devices.
		# Removing for now until a better solution comes
		# to mind.
		#print '\nSpawning Device Checker Thread...'
		#self.statusChecker = HomePiDeviceStatusCheckerThread(self, 15)
		#self.statusChecker.setDaemon(True)
		#self.statusChecker.start()
		
		# Feedback - Ready and waiting for connections.
		piglow.red(0)
		piglow.orange(0)
		piglow.yellow(0)

		piglow.blue(self.feedbackGlow)
		piglow.show()

		# Listening to devices...	
		self.listenForClients()
Ejemplo n.º 3
0
def flash_yellow():

    # Turn off all, turn on yellow
    piglow.clear()
    piglow.yellow(YELLOW)
    piglow.show()
    # Leave on for 0.1 seconds
    time.sleep(0.1)

    # Leave off for 0.1 seconds
    piglow.clear()
    piglow.show()
    time.sleep(0.1)
Ejemplo n.º 4
0
    def getImage(self, keyNum):
        filename = self.tmpLocation + str(keyNum) + ".png"
        if self.piGlowEnable:
            piglow.all(0)
            piglow.yellow(255)
        if (os.path.isfile(filename)):
            if (datetime.fromtimestamp(os.path.getctime(filename)).date() <
                    datetime.today().date()):
                print "DELETE: " + str(keyNum) + ", [File older than today]"
                os.remove(filename)
            else:
                print "CACHED: " + str(keyNum) + " [Returning cached file]"
                return filename

        if not self.URL:
            print 'ERROR: Unable to locate file, and URL fetching not configured'
            return False

        if (self.URL and "<CARDNUM>" not in self.URL):
            print 'ERROR: <CARDNUM> placeholder not found in URL config'
            return False

        try:
            print "GET: " + str(keyNum) + " [Downloading new file]"
            url = self.URL.replace('<CARDNUM>', str(keyNum))
            uh = urllib2.urlopen(url)
        except:
            print "NOTFOUND: " + str(keyNum) + " [Server responded non-200]"
            return False
        CHUNK = 16 * 1024
        with open(filename, 'wb') as f:
            while True:
                chunk = uh.read(CHUNK)
                if not chunk: break
                f.write(chunk)
            f.close()
        print "WROTE: " + filename
        return filename
Ejemplo n.º 5
0
	def getImage(self, keyNum):
		filename = self.tmpLocation + str(keyNum) + ".png"
		if self.piGlowEnable:
			piglow.all(0)
			piglow.yellow(255)
		if (os.path.isfile(filename)):
			if (datetime.fromtimestamp(os.path.getctime(filename)).date() < datetime.today().date()):
				print "DELETE: "+str(keyNum)+", [File older than today]"
				os.remove(filename)
			else:
				print "CACHED: "+str(keyNum)+" [Returning cached file]"
				return filename
			
		if not self.URL:
			print 'ERROR: Unable to locate file, and URL fetching not configured'
			return False	
		
		if (self.URL and "<CARDNUM>" not in self.URL):
			print 'ERROR: <CARDNUM> placeholder not found in URL config'
			return False
		
		try:
			print "GET: "+str(keyNum)+" [Downloading new file]"
			url = self.URL.replace('<CARDNUM>', str(keyNum))
			uh = urllib2.urlopen(url)
		except:
			print "NOTFOUND: "+str(keyNum)+" [Server responded non-200]"
			return False
		CHUNK = 16 * 1024
		with open(filename, 'wb') as f:
			while True:
				chunk = uh.read(CHUNK)
				if not chunk: break
				f.write(chunk) 
			f.close()
		print "WROTE: "+filename
		return filename
Ejemplo n.º 6
0
	def __init__(self):
		self.configFileLocation = os.getenv('CONFFILE', self.configFileLocation)
		self.config = ConfigParser.ConfigParser()
		#Try to load config file
		
		if self.configFileLocation not in self.config.read(self.configFileLocation):
			self.configFileLocation = None
			
		#Try to set rfid input path from config file.
		try:
			self.rfidPath = self.config.get('Parkomatic', 'rfid_input_path')
		except: 
			pass
		
		#Try to set destination URL from config file.
		try:
			self.URL = self.config.get('Parkomatic', 'url')
		except:
			pass
		
		#Try to set tmp path from config file.
		try:
			self.tmpLocation = self.config.get('Parkomatic', 'tmp_path')
		except:
			pass
		
		try:
			piglow_val = self.config.get('Parkomatic', 'piglow')
			if piglow_val == "enable":
				self.piGlowEnable = True
		except:
			 pass
		
		#Try to create the tmp location if it doesn't exist
		if not os.path.exists(self.tmpLocation):
			os.makedirs(self.tmpLocation)
		
		#Make a connection to the CUPS server
		try:
			self.conn = cups.Connection()
		except:
			print "ERROR: CUPs not available"
			#Sleep for 5 seconds as repeatedly attemping to connect to CUPs seems to make it hard for cups to start initially.
			time.sleep(5)
			sys.exit(1)
			
		printers = self.conn.getPrinters()
		if len(printers) == 0:
			print "ERROR: No printers available"
			time.sleep(5)
			sys.exit(1)
		#Get the first printer in the list
		self.printer = printers.keys()[0]
		
		#Create the RFID input device
		self.rfidDevice = InputDevice(self.rfidPath)
		print "STARTED: Waiting for input."
		if self.piGlowEnable:
			piglow.auto_update = True;
			piglow.all(0)
			piglow.red(255)
			time.sleep(0.1)
			piglow.red(0)
			piglow.green(255)
			time.sleep(0.1)
			piglow.green(0)
			piglow.yellow(255)
			time.sleep(0.1)
			piglow.white(255)
			piglow.yellow(0)
			time.sleep(0.1)
			piglow.white(0)
Ejemplo n.º 7
0
sunrise = daily.data[0].sunriseTime
sunset = daily.data[0].sunsetTime

hourly = forecast.hourly()
for i in range(0, 8):
  hourlyData = hourly.data[i]
  print(i, hourlyData.icon)


  if hourlyData.icon == "wind":
   #while True:
    for x in range(100):
        piglow.leg_bar(0, x / 100.0)
        #piglow.leg_bar(1, x / 100.0)
        #piglow.leg_bar(2, x / 100.0)
        piglow.yellow(200)
        piglow.show()
        time.sleep(0.01)
    for x in reversed(range(100)):
        piglow.leg_bar(0, x / 100.0)
        #piglow.leg_bar(1, x / 100.0)
        #piglow.leg_bar(2, x / 100.0)
        piglow.yellow(200)
        piglow.show()
        time.sleep(0.01)

  elif hourlyData.icon == "rain":
    	 for x in range(100):
        piglow.leg_bar(0, x / 100.0)
        #piglow.leg_bar(1, x / 100.0)
        #piglow.leg_bar(2, x / 100.0)
Ejemplo n.º 8
0
    def __init__(self):
        self.configFileLocation = os.getenv('CONFFILE',
                                            self.configFileLocation)
        self.config = ConfigParser.ConfigParser()
        #Try to load config file

        if self.configFileLocation not in self.config.read(
                self.configFileLocation):
            self.configFileLocation = None

        #Try to set rfid input path from config file.
        try:
            self.rfidPath = self.config.get('Parkomatic', 'rfid_input_path')
        except:
            pass

        #Try to set destination URL from config file.
        try:
            self.URL = self.config.get('Parkomatic', 'url')
        except:
            pass

        #Try to set tmp path from config file.
        try:
            self.tmpLocation = self.config.get('Parkomatic', 'tmp_path')
        except:
            pass

        try:
            piglow_val = self.config.get('Parkomatic', 'piglow')
            if piglow_val == "enable":
                self.piGlowEnable = True
        except:
            pass

        #Try to create the tmp location if it doesn't exist
        if not os.path.exists(self.tmpLocation):
            os.makedirs(self.tmpLocation)

        #Make a connection to the CUPS server
        try:
            self.conn = cups.Connection()
        except:
            print "ERROR: CUPs not available"
            #Sleep for 5 seconds as repeatedly attemping to connect to CUPs seems to make it hard for cups to start initially.
            time.sleep(5)
            sys.exit(1)

        printers = self.conn.getPrinters()
        if len(printers) == 0:
            print "ERROR: No printers available"
            time.sleep(5)
            sys.exit(1)
        #Get the first printer in the list
        self.printer = printers.keys()[0]

        #Create the RFID input device
        self.rfidDevice = InputDevice(self.rfidPath)
        print "STARTED: Waiting for input."
        if self.piGlowEnable:
            piglow.auto_update = True
            piglow.all(0)
            piglow.red(255)
            time.sleep(0.1)
            piglow.red(0)
            piglow.green(255)
            time.sleep(0.1)
            piglow.green(0)
            piglow.yellow(255)
            time.sleep(0.1)
            piglow.white(255)
            piglow.yellow(0)
            time.sleep(0.1)
            piglow.white(0)