def doRead(): global gotInput, theInput while True: if gotInput: time.sleep(0.5) continue # go back to while try: theInput = "" except Exception: # KeyboardInterrupt: allDead = True print("\n\nDeregister " + DAN.profile['d_name'] + " !!!\n", flush=True) DAN.deregister() sys.stdout = sys.__stdout__ print(" Thread say Bye bye ---------------", flush=True) sys.exit() # break # raise # ? gotInput = True
def doRead( ): global gotInput, theInput, allDead while True: if gotInput: time.sleep(0.1) continue # go back to while try: theInput = input("Give me data: ") except Exception: ## KeyboardInterrupt: allDead = True print("\n\nDeregister " + DAN.profile['d_name'] + " !!!\n", flush=True) DAN.deregister() sys.stdout = sys.__stdout__ print(" Thread say Bye bye ---------------", flush=True) sys.exit( ) ## break # raise # ? gotInput=True if theInput !='quit' and theInput != "exit": print("Will send " + theInput, end=" , ")
def doRead(): global gotInput, theInput, allDead while True: while gotInput: # 老闆還沒把資料拿走 time.sleep(0.1) # 小睡 下把 CPU 暫時讓給別人 continue # go back to while try: # 準備讀取資料, 注意程式會卡在這等 User 輸入, 所以要用 Thread theInput = int(input("Give me data: ")) print('send your input: {}'.format(theInput)) except Exception: ## KeyboardInterrupt: allDead = True print("\n\nDeregister " + DAN.profile['d_name'] + " !!!\n", flush=True) DAN.deregister() sys.stdout = sys.__stdout__ print(" Thread say Bye bye ---------------", flush=True) sys.exit() ## break # raise # ? gotInput = True # notify my master that we have data if allDead: break
def doRead( ): global gotInput, theInput, allDead while True: while gotInput: # 老闆還沒把資料拿走 time.sleep(0.1) # 小睡 下把 CPU 暫時讓給別人 continue # go back to while try: # 準備讀取資料, 注意程式會卡在這等 User 輸入, 所以要用 Thread theInput = input("Give me data: ") except Exception: ## KeyboardInterrupt: allDead = True print("\n\nDeregister " + DAN.profile['d_name'] + " !!!\n", flush=True) DAN.deregister() sys.stdout = sys.__stdout__ print(" Thread say Bye bye ---------------", flush=True) sys.exit( ); ## break # raise # ? if theInput =='quit' or theInput == "exit": # these are NOT data allDead = True else: print("Will send " + theInput, end=" , ") gotInput=True # notify my master that we have data if allDead: break; # 離開 while True 這 Loop
def doRead(): global gotInput, theInput while True: if gotInput: time.sleep(0.5) continue # go back to while try: r = req.get(_url) if r.ok: soup = Soup(r.text, 'html.parser') wind = soup.find('span', {'data-testid': 'Wind'}) wind_deg = 180 try: wind_deg = (int( re.search(r'transform:rotate\(([0-9]+)deg\)', wind.find('svg')['style']).group(1)) + 180) % 360 except: pass wind_speed = float( re.search(r'([0-9]+\.?[0-9]*)', wind.text).group(1)) visibility = float( re.search( r'([0-9]+\.?[0-9]*)', soup.find('span', { 'data-testid': 'VisibilityValue' }).text).group(1)) theInput = [wind_deg, wind_speed, visibility] else: theInput = [] except Exception as e: # KeyboardInterrupt: print(e) allDead = True print("\n\nDeregister " + DAN.profile['d_name'] + " !!!\n", flush=True) DAN.deregister() sys.stdout = sys.__stdout__ sys.exit() # break # raise # ? gotInput = True
def doRead( ): global gotInput, theInput, allDead while True: if gotInput: time.sleep(0.1) continue # go back to while try: theInput = input("Give me data: ") except Exception: ## KeyboardInterrupt: allDead = True print("\n\nDeregister " + DAN.profile['d_name'] + " !!!\n", flush=True) DAN.deregister() sys.stdout = sys.__stdout__ print(" Thread say Bye bye ---------------", flush=True) sys.exit( ); ## break # raise # ? gotInput=True ans = re.split(" ,|, |,| ", theInput) ## please try to input: color 55, 168, 33 44 55 print("Original ans=", ans) ans = [ x for x in ans if x] # remove empty string print("new ans=", ans) parse(ans); if cmd[0] == "Q" or cmd[0] == "E": break; if cmd[0] == "S": showData( ); continue; if cmd[0] == "L": print("cmd=", cmd, "; Luminance=", Luminance) elif cmd[0] == "C": print("cmd=", cmd, ",R=", r, ",G=", g, ",B=", b, ",LUM=", Luminance) else: print("Illegal command. Only C / L two commands allowed.") print("Please Re-Enter your ", end=""); if theInput !='quit' and theInput != "exit": print("Will send " + theInput, end=" , ")
def doRead(): r1 = random.randint(10000, 20000) r2 = random.randint(30000, 50000) answer = r1 + r2 global gotInput, theInput, allDead while True: if gotInput: time.sleep(0.1) continue # go back to while try: print("answer the question: ", r1, " + ", r2, "= ?\n") theInput = input("Give me the answer: ") except Exception: ## KeyboardInterrupt: allDead = True print("\n\nDeregister " + DAN.profile['d_name'] + " !!!\n", flush=True) DAN.deregister() sys.stdout = sys.__stdout__ print(" Thread say Bye bye ---------------", flush=True) sys.exit() ## break # raise # ? gotInput = True if theInput != 'quit' and theInput != "exit" and int( theInput) == answer: print("Congraduate!!!! Will send " + theInput, end=" , ") theInput = 0 elif (int(theInput) < answer): print("the answer is bigger\n") theInput = 100 continue elif (int(theInput) > answer): print("the answer is smaller\n") theInput = 100
if gotInput: if theInput =='quit' or theInput=="exit": break # sys.exit( ); #value2=random.uniform(1, 10) try: value2=float( theInput ) except: value2=0 gotInput=False # so that you can input again if(allDead): break DAN.push ('Dummy_Sensor', value2, value2) except Exception as e: print(e) if str(e).find('mac_addr not found:') != -1: print('Reg_addr is not found. Try to re-register...') DAN.device_registration_with_retry(ServerURL, Reg_addr) else: print('Connection failed due to unknow reasons.') time.sleep(1) try: time.sleep(0.2) except KeyboardInterrupt: break time.sleep(0.5) try: DAN.deregister() except Exception as e: print("===") print("Bye ! --------------", flush=True) sys.exit( )
print(value1[0]) #Push data to a device feature called "Dummy_Sensor" #value2=random.uniform(1, 10) ## original Dummy_Device example if gotInput: # we have data in theInput if (allDead): break gotInput = False # so that you can input again DAN.push('Dummy_Sensor', theInput, theInput) # 試這: DAN.push('Dummy_Sensor', theInput) #DAN.push('Color-I', theInput[0], theInput[1], theInput[2]) except Exception as e: print(e) if str(e).find('mac_addr not found:') != -1: print('Reg_addr is not found. Try to re-register...') DAN.device_registration_with_retry(ServerURL, Reg_addr) else: print('Connection failed due to unknow reasons.') time.sleep(1) try: time.sleep(0.2) except KeyboardInterrupt: break time.sleep(0.25) try: DAN.deregister() # 試著解除註冊 except Exception as e: print("===") print("Bye ! --------------", flush=True) sys.exit()
def on_exit(): DAN.deregister() killport(WEB_PORT) save_config(config_name)
change_L = 0 change_P = 0 change_Sh = 0 change_Su = 0 change_T = 0 change_Y = 0 cnt = 1 flag_L_p = 0 flag_P_p = 0 flag_Sh_p = 0 flag_Su_p = 0 flag_T_p = 0 flag_Y_p = 0 ''' DAN.deregister() exit() ''' time.sleep(10) while True: try: w_L = parse_weather_Luodong.parse_weather() w_P = parse_weather_Pinglin.parse_weather() #w_Sh=parse_weather_Shiding.parse_weather() #error w_Sh = '60' w_Su = parse_weather_Suao.parse_weather() w_T = parse_weather_Toucheng.parse_weather() w_Y = parse_weather_Yilan.parse_weather() #w_Y='70'