Пример #1
0
def RPiTimer(*args):
	global logger
	
	device_file = args[0]

	#Get RaspberryPi temp
	curRPiTemp = None
	try:
		curRPiTemp = RPi_Temp.read_temp(device_file, 5)
	except Exception, e:
		logger.error('Failed to read Raspberry Pi Temp', exc_info=True)
Пример #2
0
def RPiTimer(*args):

	try:

		print "RPiTimer"

		global logger
		#global RPiDataPoints
		global CHARTTIME
		global tRPiPeriod
	
		device_file = args[0]
		db = args[1]

		#debug
		#print "RPiDataPoints: "
		#print RPiDataPoints
		#debug

		#Get RaspberryPi temp
		curRPiTemp = None
		curRPiPressure = None
		try:
			#print "RPi temp"
			curRPiTemp = RPi_Temp.read_temp(device_file, 5)
			#print "RPi pressure"
			curRPiPressure = RPi_Pressure.read_pressure()
			if (curRPiPressure < 900 or curRPiPressure > 1100): curRPiPressure = None
		except Exception, e:
			logger.error('Failed to read Raspberry Pi', exc_info=True)



		if (curRPiTemp != None and curRPiPressure != None):
			print (strftime("[%H:%M:%S]: ", localtime()) + "Upstair Temp\t" + str(curRPiTemp))
			logger.info(strftime("[%H:%M:%S]: ", localtime()) + "Upstair Temp\t" + str(curRPiTemp))

			try:
				db = MySQLdatabase.Connect(mysql_host, mysql_login, mysql_pw, mysql_db)
				MySQLdatabase.InsertData(db, 'sensordata', '2nd Floor', 'Raspberry Pi', 'Current', 'Temperature', curRPiTemp, 'F')
				MySQLdatabase.InsertData(db, 'sensordata', '2nd Floor', 'Raspberry Pi', 'Current', 'Pressure', curRPiPressure, 'mbar')
				MySQLdatabase.Close(db)

				#RPiDataPoints.append((datetime.now(), curRPiTemp))
				#shorten array to fit chart
				#if (len(RPiDataPoints) > CHARTTIME/tRPiPeriod):
				#	index = len(RPiDataPoints) - CHARTTIME/tRPiPeriod
				#	RPiDataPoints = RPiDataPoints[index:]	
				#data = [DataPoint(datetime.now(), curRPiTemp)]
				#tempo_client.write_key("temp3", data)
			except:
				print (strftime("[%H:%M:%S]: EXCEPTION ", localtime()) + str(sys.exc_info()[0]))
				logger.error(strftime("[%H:%M:%S]: EXCEPTION ", localtime()) + str(sys.exc_info()[0]), exc_info=True)
Пример #3
0
def main():
	
	# Start File Logger
	global logger
	logger = FileLogger.startLogger("/var/log/PostTemperature.log", 1000000, 5)
	logger.info("Starting Logger...")
	
	# Check for internet connection
	#URL = "http://www.google.com"
	#print "Checking for internet connection..."
	#logger.info("Checking for internet connection...")
	#for retry in range(10):
	#	try:
	#		response = requests.get(URL)
	#	except Exception as e:
	#		print "Failed to connect to Internet"
	#		print e
	#		logger.error("Failed to connect to Internet", exc_info=True)
	#		sleep(3)
	#	if response.ok:
	#		break
		

	# Init TempoDB
	global tempo_client
	tempo_client = init_tempo(tempo_key, tempo_secret)

	#Start Plotly Timer
	global tPlotlyPeriod, tPlotly
	tPlotlyPeriod = 60 * 1
	py = plotlyClient.initPlotly(plotly_un, plotly_key)
	if (py and tempo_client):	
		tPlotly = Timer(0, PlotlyTimer, [py, tempo_client])
		tPlotly.start()

	# Start Nest Timer
	global n, tNestPeriod, tNest
	n = nest.Nest(nlogin, npasswd)
	n.login()
	tNestPeriod = 60 * 5
	tNest = Timer(0, NestTimer)
	tNest.start()

	# Start WU Timer
	global tWUPeriod, tWU
	tWUPeriod = 60 * 15
	tWU = Timer(0, WUTimer)
	tWU.start()
	
	# Start Raspberry Pi Temp Timer
	global tRPiPeriod, tRPi
	tRPiPeriod = 60 * 5
	device_file = RPi_Temp.initTemp()
	if (device_file):
		tRPi = Timer(0, RPiTimer, [device_file])
		tRPi.start()

	# Start Arduino Timer
	global tArduinoPeriod, tArduino
	tArduinoPeriod = 60 * 5
	tArduino = Timer(0, ArduinoTimer)
	tArduino.start()
	
	# Setup exit handlers
	signal.signal(signal.SIGTSTP, SIGTSTP_handler)	#Thread stop detected
	signal.signal(signal.SIGINT, SIGINT_handler)	#Ctrl+C detected
	
	# Wait for termination
	signal.pause()
Пример #4
0
def RPiTimer(*args):

    try:

        print "RPiTimer"

        global logger
        #global RPiDataPoints
        global CHARTTIME
        global tRPiPeriod

        device_file = args[0]
        db = args[1]

        #debug
        #print "RPiDataPoints: "
        #print RPiDataPoints
        #debug

        #Get RaspberryPi temp
        curRPiTemp = None
        curRPiPressure = None
        try:
            #print "RPi temp"
            curRPiTemp = RPi_Temp.read_temp(device_file, 5)
            #print "RPi pressure"
            curRPiPressure = RPi_Pressure.read_pressure()
            if (curRPiPressure < 900 or curRPiPressure > 1100):
                curRPiPressure = None
        except Exception, e:
            logger.error('Failed to read Raspberry Pi', exc_info=True)

        if (curRPiTemp != None and curRPiPressure != None):
            print(
                strftime("[%H:%M:%S]: ", localtime()) + "Upstair Temp\t" +
                str(curRPiTemp))
            logger.info(
                strftime("[%H:%M:%S]: ", localtime()) + "Upstair Temp\t" +
                str(curRPiTemp))

            try:
                db = MySQLdatabase.Connect(mysql_host, mysql_login, mysql_pw,
                                           mysql_db)
                MySQLdatabase.InsertData(db, 'sensordata', '2nd Floor',
                                         'Raspberry Pi', 'Current',
                                         'Temperature', curRPiTemp, 'F')
                MySQLdatabase.InsertData(db, 'sensordata', '2nd Floor',
                                         'Raspberry Pi', 'Current', 'Pressure',
                                         curRPiPressure, 'mbar')
                MySQLdatabase.Close(db)

                #RPiDataPoints.append((datetime.now(), curRPiTemp))
                #shorten array to fit chart
                #if (len(RPiDataPoints) > CHARTTIME/tRPiPeriod):
                #	index = len(RPiDataPoints) - CHARTTIME/tRPiPeriod
                #	RPiDataPoints = RPiDataPoints[index:]
                #data = [DataPoint(datetime.now(), curRPiTemp)]
                #tempo_client.write_key("temp3", data)
            except:
                print(
                    strftime("[%H:%M:%S]: EXCEPTION ", localtime()) +
                    str(sys.exc_info()[0]))
                logger.error(strftime("[%H:%M:%S]: EXCEPTION ", localtime()) +
                             str(sys.exc_info()[0]),
                             exc_info=True)
Пример #5
0
def main():

    # Start File Logger
    print "Starting Logger.."
    global logger
    logger = FileLogger.startLogger("/var/log/HomeWeather.log", 1000000, 5)
    logger.info("Starting Logger...")

    # Check for internet connection
    #URL = "http://www.google.com"
    #print "Checking for internet connection..."
    #logger.info("Checking for internet connection...")
    #for retry in range(10):
    #	try:
    #		response = requests.get(URL)
    #	except Exception as e:
    #		print "Failed to connect to Internet"
    #		print e
    #		logger.error("Failed to connect to Internet", exc_info=True)
    #		sleep(3)
    #	if response.ok:
    #		break

    # Init TempoDB
    #global tempo_client
    #tempo_client = init_tempo(tempo_key, tempo_secret)

    # Init MySQLdb
    db = MySQLdatabase.Connect(mysql_host, mysql_login, mysql_pw, mysql_db)
    if (db == None):

        cleanup()
        return

    #Start Plotly Timer
    print "Starting Plotly Timer..."
    global tPlotlyPeriod, tPlotly
    tPlotlyPeriod = 60 * 1
    py = plotlyClient.initPlotly(plotly_un, plotly_key)
    if py:
        tPlotly = Timer(0, PlotlyTimer, [py, db])
        tPlotly.start()
    else:
        cleanup()
        return

    # Start Nest Timer
    print "Starting Nest Timer..."
    global n, tNestPeriod, tNest
    n = nest.Nest(nlogin, npasswd)
    n.login()
    tNestPeriod = 60 * 3
    tNest = Timer(0, NestTimer, [n, db])
    tNest.start()

    # Start WU Timer
    #print "Starting WU Timer..."
    #global tWUPeriod, tWU
    #tWUPeriod = 60 * 15
    #tWU = Timer(0, WUTimer, [db])
    #tWU.start()

    # Start ForecastIO Timer
    print "Starting ForecastIO Timer..."
    global tForecastIOPeriod, tForecastIO
    tForecastIOPeriod = 60 * 3
    tForecastIO = Timer(0, ForecastIOTimer, [db])
    tForecastIO.start()

    # Start Raspberry Pi Temp Timer
    print "Starting Raspberry Pi Timer..."
    global tRPiPeriod, tRPi
    tRPiPeriod = 60 * 3
    device_file = RPi_Temp.initTemp()
    if (device_file):
        tRPi = Timer(0, RPiTimer, [device_file, db])
        tRPi.start()

    # Start Arduino Timer
    print "Starting Arduino Timer..."
    global tArduinoPeriod, tArduino
    tArduinoPeriod = 60 * 3
    tArduino = Timer(0, ArduinoTimer, [db])
    tArduino.start()

    # Setup exit handlers
    signal.signal(signal.SIGTSTP, SIGTSTP_handler)
    signal.signal(signal.SIGINT, SIGINT_handler)

    # Wait for termination
    signal.pause()
Пример #6
0
def main():

	
	# Start File Logger
	print "Starting Logger.."
	global logger
	logger = FileLogger.startLogger("/var/log/HomeWeather.log", 1000000, 5)
	logger.info("Starting Logger...")
	
	# Check for internet connection
	#URL = "http://www.google.com"
	#print "Checking for internet connection..."
	#logger.info("Checking for internet connection...")
	#for retry in range(10):
	#	try:
	#		response = requests.get(URL)
	#	except Exception as e:
	#		print "Failed to connect to Internet"
	#		print e
	#		logger.error("Failed to connect to Internet", exc_info=True)
	#		sleep(3)
	#	if response.ok:
	#		break

	# Init TempoDB
	#global tempo_client
	#tempo_client = init_tempo(tempo_key, tempo_secret)

	# Init MySQLdb
	db = MySQLdatabase.Connect(mysql_host, mysql_login, mysql_pw, mysql_db)
	if (db == None):
		
		cleanup()
		return

	#Start Plotly Timer
	print "Starting Plotly Timer..."
	global tPlotlyPeriod, tPlotly
	tPlotlyPeriod = 60 * 1
	py = plotlyClient.initPlotly(plotly_un, plotly_key)
	if py:	
		tPlotly = Timer(0, PlotlyTimer, [py, db])
		tPlotly.start()
	else:
		cleanup()
		return

	# Start Nest Timer
	print "Starting Nest Timer..."
	global n, tNestPeriod, tNest
	n = nest.Nest(nlogin, npasswd)
	n.login()
	tNestPeriod = 60 * 3
	tNest = Timer(0, NestTimer, [n, db])
	tNest.start()

	# Start WU Timer
	#print "Starting WU Timer..."
	#global tWUPeriod, tWU
	#tWUPeriod = 60 * 15
	#tWU = Timer(0, WUTimer, [db])
	#tWU.start()
	
	# Start ForecastIO Timer
	print "Starting ForecastIO Timer..."
	global tForecastIOPeriod, tForecastIO
	tForecastIOPeriod = 60 * 3
	tForecastIO = Timer(0, ForecastIOTimer, [db])
	tForecastIO.start()

	# Start Raspberry Pi Temp Timer
	print "Starting Raspberry Pi Timer..."
	global tRPiPeriod, tRPi
	tRPiPeriod = 60 * 3
	device_file = RPi_Temp.initTemp()
	if (device_file):
		tRPi = Timer(0, RPiTimer, [device_file, db])
		tRPi.start()

	# Start Arduino Timer
	print "Starting Arduino Timer..."
	global tArduinoPeriod, tArduino
	tArduinoPeriod = 60 * 3
	tArduino = Timer(0, ArduinoTimer, [db])
	tArduino.start()
	
	# Setup exit handlers
	signal.signal(signal.SIGTSTP, SIGTSTP_handler)
	signal.signal(signal.SIGINT, SIGINT_handler)
	
	# Wait for termination
	signal.pause()
Пример #7
0
def initSensors(lock, logger=None):

    # Init MySQLdb
    db = MySQLdatabase.Connect(mysql_host, mysql_login, mysql_pw, mysql_db)
    if (db == None):
        print(
            strftime("[%H:%M:%S]: Error: Cannot connect to MySQL database",
                     localtime()))
        if logger:
            logger.error(strftime(
                "[%H:%M:%S]: Error: Cannot connect to MySQL database",
                localtime()),
                         exc_info=True)
        return False

    # Arduino Temp Sensor
    qIn_Arduino = Queue.Queue()
    qOut_Arduino = Queue.Queue()

    if ArduinoTempEnable:
        arduino_temp = Arduino_Temp.Arduino_Temp(lock, qIn_Arduino,
                                                 qOut_Arduino, logger)

        # Initialize Arduino_Temp module
        if not arduino_temp.init():
            print(
                strftime("[%H:%M:%S]: Error: initializing Arduino_Temp",
                         localtime()))
            if logger:
                logger.error(strftime(
                    "[%H:%M:%S]: Error: initializing Arduino_Temp",
                    localtime()),
                             exc_info=True)
            return False

        #arduino_temp.run()					# run on main thread
        arduino_temp.start()  # start thread

        #sleep(5)

    # ForecastIO Data
    qIn_ForecastIO = Queue.Queue()
    qOut_ForecastIO = Queue.Queue()

    if ForecastIOEnable:
        forecastio = ForecastIO.ForecastIO(lock, qIn_ForecastIO,
                                           qOut_ForecastIO, logger)

        # Initialize ForecastIO module
        if not forecastio.init():
            print(
                strftime("[%H:%M:%S]: Error: initializing ForecastIO",
                         localtime()))
            if logger:
                logger.error(strftime(
                    "[%H:%M:%S]: Error: initializing ForecastIO", localtime()),
                             exc_info=True)
            return False

        #forecastio.run()					# run on main thread
        forecastio.start()  # start thread

        #sleep(5)

    # Nest Sensor Data
    qIn_NestSensor = Queue.Queue()
    qOut_NestSensor = Queue.Queue()

    if NestSensorEnable:
        nestsensor = NestSensor.NestSensor(lock, qIn_NestSensor,
                                           qOut_NestSensor, logger)

        # Initialize NestSensor module
        if not nestsensor.init():
            print(
                strftime("[%H:%M:%S]: Error: initializing NestSensor",
                         localtime()))
            if logger:
                logger.error(strftime(
                    "[%H:%M:%S]: Error: initializing NestSensor", localtime()),
                             exc_info=True)
            return False

        #nestsensor.run()					# run on main thread
        nestsensor.start()  # start thread

        #sleep(5)

    # RPi Pressure Sensor
    qIn_RPiPressure = Queue.Queue()
    qOut_RPiPressure = Queue.Queue()

    if RPiPressEnable:
        rpipressure = RPi_Pressure.RPi_Pressure(lock, qIn_RPiPressure,
                                                qOut_RPiPressure, logger)

        # Initialize RPi Pressure module
        if not rpipressure.init():
            print(
                strftime("[%H:%M:%S]: Error: initializing RPi Pressure",
                         localtime()))
            if logger:
                logger.error(strftime(
                    "[%H:%M:%S]: Error: initializing RPi Pressure",
                    localtime()),
                             exc_info=True)
            return False

        #rpipressure.run()					# run on main thread
        rpipressure.start()  # start thread

        #sleep(5)

    # RPi Temp Sensor
    qIn_RPiTemp = Queue.Queue()
    qOut_RPiTemp = Queue.Queue()

    if RPiTempEnable:
        rpi_temp = RPi_Temp.RPi_Temp(lock, qIn_RPiTemp, qOut_RPiTemp, logger)

        # Initialize RPi_Temp module
        if not rpi_temp.init():
            print(
                strftime("[%H:%M:%S]: Error: initializing RPi Temp",
                         localtime()))
            if logger:
                logger.error(strftime(
                    "[%H:%M:%S]: Error: initializing RPi Temp", localtime()),
                             exc_info=True)
            return False

        #rpi_temp.run()					# run on main thread
        rpi_temp.start()  # start thread

        #sleep(5)

    return True