我已将 ESP8266 Wifi 转串口模块连接到串口转 USB 连接器。
我可以使用以下 Python 脚本和设置连接到 ESP8266:
import serial
def echoCommand(cmd,expected_return,halt_on_fail,tOut = timeoutPeriod) :
ser.write(cmd + '\r\n')
if(echo_local_command):
print('Sent --> '+cmd)
if not echoFind(expected_return,tOut) and (halt_on_fail):
print(cmd+" failed")
sys.exit()
def echoFind(expected_return,tOut):
timeoutTime = datetime.datetime.now() + datetime.timedelta(0,tOut)
while datetime.datetime.now() < timeoutTime:
while ser.inWaiting():
ret = ser.readline().rstrip()
print ret
time.sleep(0.1)
if expected_return in ret:
return True
return False
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=5)
echoCommand('AT+RST', 'ready', True)
上面的工作就像一个魅力,但由于某种原因,我不能在 minicom、GTKTerm、Putty 等终端中做同样的事情。(运行 Ubuntu。任何建议的终端会显示 CR 和 LF?)
我使用了相同的波特率和设置,但没有运气。我尝试切换硬件和软件流控制,并检查了要添加的 CR 和 LF。
任何想法为什么这不起作用?
我注意到,如果我打开 minicom 然后运行 Python 脚本,ESP8266 的输出会显示在 minicom 中,指示和发送问题。(脚本失败导致 minicom 拦截传入的消息)