def do_GET(self): #used to test Insteon outlet from web browser x = 0 if (self.path == '/start'): while (x < 50): if insteon.turn_on(): print "Turn On Counter: %i" % x break else: x += 1 self.send_response(200) return elif (self.path == '/stop'): while (x < 50): if insteon.turn_off(): print "Turn Off Counter: %i" % x break else: x += 1 self.send_response(200) return #find a file and return its contents string = self.path stripped_string = string.lstrip('/') list = stripped_string.partition('/') action = list[0] print "Action: " + action file_num = (list[2]) print "File Num: " + (str)(file_num) if (action == 'learn'): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() #!!! CHANGE THE FILE PATH FOR DIFFERENT MACHINES/USERS!!! f = open( 'C:\Users\Sean\workspace\NPNG\health_info' + (str)(file_num) + '.html', 'r') info = f.read() self.wfile.write(info) else: self.send_response(400) return
def do_GET(self): #used to test Insteon outlet from web browser x = 0 if(self.path == '/start'): while(x < 50): if insteon.turn_on(): print "Turn On Counter: %i" % x break else: x += 1 self.send_response(200) return elif(self.path == '/stop'): while(x < 50): if insteon.turn_off(): print "Turn Off Counter: %i" % x break else: x += 1 self.send_response(200) return #find a file and return its contents string = self.path stripped_string = string.lstrip('/') list = stripped_string.partition('/') action = list[0] print "Action: " + action file_num = (list[2]) print "File Num: " + (str)(file_num) if(action == 'learn'): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() #!!! CHANGE THE FILE PATH FOR DIFFERENT MACHINES/USERS!!! f = open('C:\Users\Sean\workspace\NPNG\health_info'+(str)(file_num)+'.html', 'r') info = f.read() self.wfile.write(info) else: self.send_response(400) return
def do_POST(self): self.cnt = self.cnt + 1 print self.cnt string = self.path stripped_string = string.lstrip('/') list = stripped_string.partition('/') action = list[0] print "Action: " + action tv_time = (int)(list[2]) print "TV time: " + (str)(tv_time) if (action == 'start'): started = 0 x = 0 while (x < 50): if insteon.turn_on(): print "Turn On Counter: %i" % x started = 1 break else: x += 1 if (started == 1): self.send_response(200, '200') self.start_time = time.clock() print "Start time: %i" % self.start_time for thread in threading.enumerate(): if thread.getName() == 'TimerThread': print "Thread already running" return self.p = TimerThread(self.start_time, tv_time) self.p.start() else: self.send_response(400, '400') elif (action == 'stop'): foundThread = False for thread in threading.enumerate(): if thread.getName() == 'TimerThread': stopped1 = 0 x = 0 while (x < 50): if insteon.turn_off(): print "Turn Off Counter: %i" % x stopped1 = 1 break else: x += 1 if (stopped1 == 1): foundThread = True time_used = time.clock() - thread.start_time print "Time used: %i" % time_used #user_time = 10.0 #this is for temporary testing time_left = tv_time - time_used if (time_left < 0): time_left = 0 self.send_response(200, (int)(time_left)) print "Time left: %i" % time_left thread.stop() else: print "Unable to reach automation hardware" self.send_response(400) if foundThread == False: x = 0 while (x < 50): if insteon.turn_off(): print "Turn Off Counter: %i" % x break else: x += 1 print "Thread Not Found, either it previously stopped or has not been started" self.send_response(200, 0) else: print "There was a POST path error." self.send_response(400)
def do_POST(self): self.cnt = self.cnt + 1 print self.cnt string = self.path stripped_string = string.lstrip('/') list = stripped_string.partition('/') action = list[0] print "Action: " + action tv_time = (int)(list[2]) print "TV time: " + (str)(tv_time) if(action == 'start'): started = 0 x = 0 while(x < 50): if insteon.turn_on(): print "Turn On Counter: %i" % x started = 1 break else: x += 1 if(started == 1): self.send_response(200, '200') self.start_time = time.clock() print "Start time: %i" % self.start_time for thread in threading.enumerate(): if thread.getName() == 'TimerThread': print "Thread already running" return self.p = TimerThread(self.start_time, tv_time) self.p.start() else: self.send_response(400, '400') elif(action == 'stop'): foundThread = False for thread in threading.enumerate(): if thread.getName() == 'TimerThread': stopped1 = 0 x = 0 while(x < 50): if insteon.turn_off(): print "Turn Off Counter: %i" % x stopped1 = 1 break else: x += 1 if(stopped1 == 1): foundThread = True time_used = time.clock() - thread.start_time print "Time used: %i" % time_used #user_time = 10.0 #this is for temporary testing time_left = tv_time - time_used if(time_left < 0): time_left = 0 self.send_response(200, (int)(time_left)) print "Time left: %i" % time_left thread.stop() else: print "Unable to reach automation hardware" self.send_response(400) if foundThread == False: x = 0 while(x < 50): if insteon.turn_off(): print "Turn Off Counter: %i" % x break else: x += 1 print "Thread Not Found, either it previously stopped or has not been started" self.send_response(200, 0) else: print "There was a POST path error." self.send_response(400)