Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@toyowata
Last active June 26, 2018 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toyowata/523f9c2c4013d138c568edf76343b71e to your computer and use it in GitHub Desktop.
Save toyowata/523f9c2c4013d138c568edf76343b71e to your computer and use it in GitHub Desktop.
AT command test code for the ESP8266 WiFi module
#! /usr/bin/env python
# codeing: utf-8
import serial
def send_normal_command(cmd):
ser.write(cmd)
rcv_buf = ""
while rcv_buf != "OK\r\n":
rcv_buf = ser.readline()
print rcv_buf
def parse_IPD(buf):
if "+IPD" not in buf:
return
resp = buf.split(',')[2].split(':')
for i in range(0, int(resp[0])):
print i, "{0:0>3d}".format(ord(resp[1][i])), resp[1][i]
print resp
ser = serial.Serial('/dev/tty.usbserial-DA01M7DU', 115200, timeout=2)
send_normal_command("AT\r\n")
send_normal_command("AT+GMR\r\n")
send_normal_command("AT+CWMODE=3\r\n")
send_normal_command("AT+CIPMUX=1\r\n")
send_normal_command("AT+CWDHCP=1,1\r\n")
send_normal_command("AT+CWJAP=\"elecom2g-FF7168\",\"7491896150355\"\r\n")
send_normal_command("AT+CIFSR\r\n")
send_normal_command("AT+CIPSTART=0,\"UDP\",\"8.8.8.8\",53\r\n")
send_normal_command("AT+CIPSEND=0,26\r\n")
# wait for input prompt ">"
rcv_buf = ""
while rcv_buf != ">":
rcv_buf = ser.read()
print rcv_buf
buf = [0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 4, 'm', 'b', 'e', 'd', 3, 'o', 'r', 'g', 0, 0, 1, 0, 1]
ser.write(buf)
rcv_buf = ""
while rcv_buf != "SEND OK\r\n":
rcv_buf = ser.readline()
print rcv_buf
rcv_buf = ""
while "+IPD" not in rcv_buf:
rcv_buf = ser.readline()
print rcv_buf
parse_IPD(rcv_buf)
send_normal_command("AT+CIPCLOSE=0\r\n")
ser.close()
@Deepika655
Copy link

Iam new to arduino programming,can u help me in learning & interfacing with ESP8266 module.
iam unable to receive any response when try send AT command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment