from hfwifi import* from machine import UART, Pin import time import _thread def HFM_Listener(event, data): global hfm print(f"RECV Event:{event}") # if event=="RECV": #不能使用,否则可能发生重复循环 # hfm.doSend(data) # print(data.decode()) hfm=HFWifi() hfm.setListener(HFM_Listener) s=hfm.AT_CMD(b"HFAT+VER\n") print(s) #hfm.doConnectWifi("GUAN","123456789") time.sleep(1) #hfm.doTcpConnect("192.168.0.102", 12345) apScanedList= hfm.AT_WSCAN() for apScaned in apScanedList: print(apScaned.toString()) while True: cmd=input(">>(输入Quit结束运行;SEND: 交互;AT+命令cmd)") if cmd!=None and len(cmd)>3: if cmd=="Quit": break elif cmd.startswith("SEND:"): #如果以"SEND:"开头,表示在串口窗进行交互(非CMD) s=cmd[5:] hfm.doSend(bytes(s, "utf-8")) else: cmd="HF"+cmd+"\n" print("send:"+cmd) bcmd= bytes(cmd, "utf-8") rpl=hfm.AT_CMD(bcmd) print(rpl) time.sleep(1) else: time.sleep(0.5)