Exemplo n.º 1
0
NUM_PACKETS = "10"

#  Functions
def cleanup(signal, frame) :
    sys.exit(0)

def PktRcvd() :
    db = sql.connect('localhost','thermostat','password','thermostat')
    therm.set_value_in_db(db, therm.LAST_OCCUPIED_ID, str(datetime.datetime.now())[:19])
    db.close()

#  Main Program 
signal.signal(signal.SIGINT, cleanup)

db = sql.connect('localhost','thermostat','password','thermostat')
ip_addresses = therm.get_value_from_id(db, therm.IP_ADDRESSES)
db.close()

if ip_addresses == "" :
    print("{0}: Radar Error: couldn't get IDs from database, trying again next time...".format(datetime.datetime.now()))
    sys.exit(0)

while True :
    for address in ip_addresses.split():
        FNULL = open(os.devnull, 'w')
        pkt = subprocess.call(["arping", "-i", "eth0", "-c", NUM_PACKETS, address], stdout=FNULL, stderr=FNULL)
        FNULL.close()
    
        if pkt == 0 : PktRcvd()

    time.sleep(10)	
Exemplo n.º 2
0
	db.close()
	sys.exit(0)

# Database Connection
db = sql.connect('localhost','thermostat','password','thermostat')

therm.setup_io()
signal.signal(signal.SIGINT, cleanup)
while True:

	# Make Sure DB connection is still alive
	if not db.open :
		db = sql.connect('localhost','thermostat','password','thermostat')

	# Get variables from sensors/input
	occupied = therm.check_occupancy(db)
	indoor_temp = therm.get_temp(db)
	if (indoor_temp == -1) : break
	mode = therm.get_value_from_id(db, therm.MODE_ID)
	fan_on = therm.fan_status(db)
	override = therm.override_status(db)
	setpoint = therm.get_setpoint(db,mode,occupied,override)

	# Update output based on current state
	therm.update_pins(db, mode, fan_on, setpoint, indoor_temp)
	time.sleep(5)	
# end while

io.cleanup();
db.close();