示例#1
0
	def __init__(self):
		iot.device.__init__(self)
		self.name = 'terminal'
		self.category = 'user'
		
		#Set up logging
		iot.setup_log(self.name, time.localtime())
		
		#Register with the gateway
		self.register()
		
		#Start the client thread to handle user input
		client_thread=Thread(target=self.start_client(), name='User Client Thread')
		client_thread.daemon = True
		client_thread.start()
		
		'''
		#Initialize and start daemon thread for serving as the clock synchronization leader
		leader_thread=Thread(target=d.lead, name='User Leader Thread')
		leader_thread.daemon = True
		leader_thread.start()
		'''
		
		#Start the user server
		self.serve()
示例#2
0
    def __init__(self):
        iot.device.__init__(self)
        self.name = 'bulb'
        self.state = 0
        self.category = 'device'
        self.last_on = time.time()
        self.shutoff_interval = 300

        #Set up logging
        iot.setup_log(self.name, time.localtime())
        #Register with the gateway
        self.register()
        '''
		#Initialize and start daemon thread for serving as the clock synchronization leader
		leader_thread=Thread(target=self.lead, name='Bulb Leader Thread')
		leader_thread.daemon = True
		leader_thread.start()
		'''

        #Initialize and start daemon thread to auotmatically shut off the bulb after a certain time interval
        shutoff_thread = Thread(target=self.auto_shutoff,
                                name='Bulb Auto-Shutoff Thread')
        shutoff_thread.daemon = True
        shutoff_thread.start()

        #Start listening for requests
        self.serve()
示例#3
0
    def __init__(self):
        iot.device.__init__(self)
        self.name = 'door'
        self.category = 'device'
        self.state = 0
        self.sensing_interval = 5

        #Set up logging
        iot.setup_log(self.name, time.localtime())

        #Register with the gateway
        self.register()
        '''
		#Initialize and start daemon thread for serving as the clock synchronization leader
		leader_thread=Thread(target=self.lead, name='Door Leader Thread')
		leader_thread.daemon = True
		leader_thread.start()
		'''

        #Initialize and start daemon thread for the client to push state changes to the server
        client_thread = Thread(target=self.start_client,
                               name='Door Client Thread')
        client_thread.daemon = True
        client_thread.start()

        #Start the door server
        self.serve()
示例#4
0
	def __init__(self):
		iot.device.__init__(self)
		self.name = 'bulb'
		self.state = 0
		self.category = 'device'
		self.last_on = time.time()
		self.shutoff_interval = 300
		
		#Set up logging
		iot.setup_log(self.name, time.localtime())
		#Register with the gateway
		self.register()
		
		'''
		#Initialize and start daemon thread for serving as the clock synchronization leader
		leader_thread=Thread(target=self.lead, name='Bulb Leader Thread')
		leader_thread.daemon = True
		leader_thread.start()
		'''
		
		#Initialize and start daemon thread to auotmatically shut off the bulb after a certain time interval
		shutoff_thread=Thread(target=self.auto_shutoff, name='Bulb Auto-Shutoff Thread')
		shutoff_thread.daemon=True
		shutoff_thread.start()
		
		#Start listening for requests
		self.serve()
示例#5
0
 def setup(self):
     #Set up logging and initialize database files
     t = time.localtime()
     iot.setup_log(self.name, time.localtime())
     logging.info('Initializing')
     timestamp = (str(t[0]) + '_' + str(t[1]) + '-' + str(t[2]) + '_' +
                  str(t[3]) + '-' + str(t[4]) + '-' + str(t[5]))
     self.history_file = ('db/' + str(timestamp) + '_history')
     h = shelve.open(self.history_file)
     h.close()
     self.state_file = ('db/' + str(timestamp) + '_state')
     s = shelve.open(self.state_file)
     s.close()
示例#6
0
def main():
    #Set up logging
    iot.setup_log('display')
    #Create a new instance of the user object
    d = display()
    #Register with the gateway
    d.register()

    #Initialize and start daemon thread for serving as the clock synchronization leader
    leader_thread = Thread(target=d.lead, name='Display Leader Thread')
    leader_thread.daemon = True
    leader_thread.start()

    #Start the display server
    d.serve()
示例#7
0
def main():
	#Set up logging
	iot.setup_log('display')
	#Create a new instance of the user object
	d=display()
	#Register with the gateway
	d.register()
	
	#Initialize and start daemon thread for serving as the clock synchronization leader
	leader_thread=Thread(target=d.lead, name='Display Leader Thread')
	leader_thread.daemon = True
	leader_thread.start()
	
	#Start the display server
	d.serve()
示例#8
0
def main():
	#Create the log file and set up its format
	iot.setup_log('presence')
	#Create a new instance of the presence sensor device object
	d=presence()
	#Register with the gateway
	d.register()
	
	#Initialize and start daemon thread for serving as the clock synchronization leader
	leader_thread=Thread(target=d.lead, name='Presence Leader Thread')
	leader_thread.daemon = True
	leader_thread.start()
	
	#Start the presence server
	d.start_client()
示例#9
0
def main():

    # Set up logging
    iot.setup_log("backend")
    # Create a new instance of the backend object
    d = backend()
    # Register with the gateway
    d.register()

    # Initialize and start daemon thread for serving as the clock synchronization leader
    leader_thread = Thread(target=d.lead, name="Backend Leader Thread")
    leader_thread.daemon = True
    leader_thread.start()

    # Start the backend server
    d.serve()
示例#10
0
def main():
	
	#Set up logging
	iot.setup_log('motion')	
	#Create a new instance of the motion sensor object
	d = motion()
	#Register with the gateway
	d.register()
	
	#Initialize and start daemon thread for serving as the clock synchronization leader
	leader_thread=Thread(target=d.lead, name='Motion Leader Thread')
	leader_thread.daemon = True
	leader_thread.start()
	
	#Start the motion sensing client
	d.start_client()
示例#11
0
def main():

    #Set up logging
    iot.setup_log('motion')
    #Create a new instance of the motion sensor object
    d = motion()
    #Register with the gateway
    d.register()

    #Initialize and start daemon thread for serving as the clock synchronization leader
    leader_thread = Thread(target=d.lead, name='Motion Leader Thread')
    leader_thread.daemon = True
    leader_thread.start()

    #Start the motion sensing client
    d.start_client()
示例#12
0
def main():
	
	#Set up logging
	iot.setup_log('temp')
	#Create a new instance of the temperature sensor object
	d = temp()
	#Register with the gateway
	d.register()
	
	#Initialize and start daemon thread for serving as the clock synchronization leader
	leader_thread=Thread(target=d.lead, name='Temperature Leader Thread')
	leader_thread.daemon = True
	leader_thread.start()
	
	#Start the server
	d.serve()
示例#13
0
    def __init__(self):
        iot.device.__init__(self)
        self.name = 'temperature'
        self.category = 'sensor'

        #Set up logging
        iot.setup_log(self.name, time.localtime())

        #Register with the gateway
        self.register()
        '''
		#Initialize and start daemon thread for serving as the clock synchronization leader
		leader_thread=Thread(target=self.lead, name='Temperature Leader Thread')
		leader_thread.daemon = True
		leader_thread.start()
		'''

        #Start the server
        self.serve()
示例#14
0
def main():
    #Set up logging
    iot.setup_log('door')
    #Create a new instance of the door object
    d = door()
    #Register with the gateway
    d.register()

    #Initialize and start daemon thread for serving as the clock synchronization leader
    leader_thread = Thread(target=d.lead, name='Door Leader Thread')
    leader_thread.daemon = True
    leader_thread.start()

    #Initialize and start daemon thread for the client to push state changes to the server
    client_thread = Thread(target=d.start_client, name='Door Client Thread')
    client_thread.daemon = True
    client_thread.start()

    #Start the door server
    d.serve()
示例#15
0
	def __init__(self):
		iot.device.__init__(self)
		self.name = 'temperature'
		self.category = 'sensor'
		
		#Set up logging
		iot.setup_log(self.name, time.localtime())
		
		#Register with the gateway
		self.register()
		
		'''
		#Initialize and start daemon thread for serving as the clock synchronization leader
		leader_thread=Thread(target=self.lead, name='Temperature Leader Thread')
		leader_thread.daemon = True
		leader_thread.start()
		'''
		
		#Start the server
		self.serve()
示例#16
0
def main():
	#Set up logging
	iot.setup_log('door')
	#Create a new instance of the door object
	d=door()
	#Register with the gateway
	d.register()
	
	#Initialize and start daemon thread for serving as the clock synchronization leader
	leader_thread=Thread(target=d.lead, name='Door Leader Thread')
	leader_thread.daemon = True
	leader_thread.start()
	
	#Initialize and start daemon thread for the client to push state changes to the server
	client_thread=Thread(target=d.start_client, name='Door Client Thread')
	client_thread.daemon = True
	client_thread.start()
	
	#Start the door server
	d.serve()
示例#17
0
def main():
	#Set up logging
	iot.setup_log('user')
	#Create a new instance of the user object
	d=user()
	#Register with the gateway
	d.register()
	
	#Start the client thread to handle user input
	client_thread=Thread(target=d.start_client(), name='User Client Thread')
	client_thread.daemon = True
	client_thread.start()
	
	#Initialize and start daemon thread for serving as the clock synchronization leader
	leader_thread=Thread(target=d.lead, name='User Leader Thread')
	leader_thread.daemon = True
	leader_thread.start()
	
	#Start the user server
	d.serve()
示例#18
0
def main():
    #Set up logging
    iot.setup_log('bulb')
    #Create a new instance of the bulb object
    d = bulb()
    #Register with the gateway
    d.register()

    #Initialize and start daemon thread for serving as the clock synchronization leader
    leader_thread = Thread(target=d.lead, name='Bulb Leader Thread')
    leader_thread.daemon = True
    leader_thread.start()

    #Initialize and start daemon thread to auotmatically shut off the bulb after a certain time interval
    shutoff_thread = Thread(target=d.auto_shutoff,
                            name='Bulb Auto-Shutoff Thread')
    shutoff_thread.daemon = True
    shutoff_thread.start()

    #Start the bulb server
    d.serve()
示例#19
0
	def __init__(self):
		iot.device.__init__(self)
		self.name = 'motion'
		self.category = 'sensor'
		self.sensing_interval = 5
		
		#Set up logging
		iot.setup_log(self.name, time.localtime())	
		#Create a new instance of the motion sensor object
		
		self.register()
		
		'''
		#Initialize and start daemon thread for serving as the clock synchronization leader
		leader_thread=Thread(target=self.lead, name='Motion Leader Thread')
		leader_thread.daemon = True
		leader_thread.start()
		'''
		
		#Start the motion sensing client
		self.start_client()
示例#20
0
	def __init__(self):
		iot.device.__init__(self)
		self.name = 'presence'
		self.category = 'sensor'
		self.state = 0
		self.sensing_interval = 5
		
		#Create the log file and set up its format
		iot.setup_log(self.name, time.localtime())
		
		#Register with the gateway
		self.register()
		
		'''
		#Initialize and start daemon thread for serving as the clock synchronization leader
		leader_thread=Thread(target=self.lead, name='Presence Leader Thread')
		leader_thread.daemon = True
		leader_thread.start()
		'''
		
		#Start the presence server
		self.start_client()
示例#21
0
def main():
	#Set up logging
	iot.setup_log('gateway')
	#Create a new instance of the gateway object
	d = gateway()
	
	#Write address to gateway_ip file
	ip_file=open('gateway_ip.txt', 'w')
	ip_file.write('http://' + str(d.ip) + ':' + str(d.port))
	ip_file.close()
	
	#Initialize and start daemon thread for serving as the clock synchronization leader
	leader_thread=Thread(target=d.lead, name='Gateway Leader Thread')
	leader_thread.daemon = True
	leader_thread.start()

	#Initialize and start daemon threads for checking temperature and automatically shutting off the bulb
	temp_thread=Thread(target=d.monitor_temperature, name='Gateway Temperature Thread')
	temp_thread.daemon = True
	temp_thread.start()
	
	#Start the main server
	d.serve()
示例#22
0
	def __init__(self):
		iot.device.__init__(self)
		self.name = 'gateway'
		self.category = 'gateway'
		
		#Set up logging
		start_time=time.localtime()
		iot.setup_log(self.name, start_time)
		
		self.port = 9000
		self.door_state = 0
		self.motion_mode = 'HOME'
		self.temperature_interval = 10
		
		self.cache_capacity = 100
		self.cache = collections.OrderedDict()
		
		self.backend_ip = False
		self.backend_port = False
		
		self.register()
		self.request_db()
		
		'''
		#Initialize and start daemon thread for serving as the clock synchronization leader
		leader_thread=Thread(target=d.lead, name='Bulb Leader Thread')
		leader_thread.daemon = True
		leader_thread.start()
		'''
		
		#Initialize and start daemon threads for checking temperature and automatically shutting off the bulb
		#temp_thread=Thread(target=self.monitor_temperature, name='Gateway Temperature Thread')
		#temp_thread.daemon = True
		#temp_thread.start()
		
		self.serve()
示例#23
0
def main():
    #Set up logging
    iot.setup_log('gateway')
    #Create a new instance of the gateway object
    d = gateway()

    #Write address to gateway_ip file
    ip_file = open('gateway_ip.txt', 'w')
    ip_file.write('http://' + str(d.ip) + ':' + str(d.port))
    ip_file.close()

    #Initialize and start daemon thread for serving as the clock synchronization leader
    leader_thread = Thread(target=d.lead, name='Gateway Leader Thread')
    leader_thread.daemon = True
    leader_thread.start()

    #Initialize and start daemon threads for checking temperature and automatically shutting off the bulb
    temp_thread = Thread(target=d.monitor_temperature,
                         name='Gateway Temperature Thread')
    temp_thread.daemon = True
    temp_thread.start()

    #Start the main server
    d.serve()