ESP8266 Basic - ElectroDragon
ESP8266 Basic - ElectroDragon
From ElectroDragon
Share
Contents
1 Module Pin Description ESP-01
2 Module wiring
3 Setup Check list
4 Use Guide of AT Commands
5 Arduino Control Demo Code
6 Note
Working Flash
Pin Description
Mode Mode
VCC, power supply, better use a standalone, and share
GND* ground with uart port
TXD,
uart interface
RXD**
RST Restart on low TTL
CH_PD 1 1 Chip select, constant High TTL for both mode
GPIO 15 0 0 Low TTL for both mode on boot , N/A for ESP-01
GPIO0 1 (optionally) 0 Switch Wroking/Flash Mode
GPIO 2 -
(cancelled on latest) constants on to show the power
Red LEDs
status
Blue
blink when data come through
LEDs
Module wiring
Pin definition ESP-01 use with CH340 battery with esp12
USB-TTL
Use power source that can provide sufficient current, better not using power from USB-TTL
module
Module will automatically disconnect "unlink" TCP/UDP when no data go through
Wifi password length must be more than 8 bytes
Use Guide of AT Commands
At
Header text Header text
Commands
restart the module, received some
Reset AT+RST
strange data, and "ready"
change the working mode to 3,
Set Work AP+STA, only use the most
AT+CWMODE=3
Mode AP+STA versatile mode 3, AT+RST may be
necessary when this is done
Join Network AT+CWLAP search available wifi spot
join my mercury router spot, e.g.
AT+CWJAP=TP-
LINK_4226,1234567890,
Join Network AT+CWJAP=you ssid, password
password length must be correct,
remove all the empty space in the
command
check if connected successfully,
Join Network AT+CWJAP? or use AT+CWJAP=?, or use
AT+CIFSR to find your ip address
check current version, output
AT+GMR AT version:0.30.0.0(Jul 3
2015 19:35:49) / SDK
Cloud Update AT+GMR version:1.2.0 / Ai-Thinker
Technology Co.,Ltd. /
Build:1.2.0.A Aug 7 2015 17:21:44
/ OK
get reply +CIPUPDATE:1,
Cloud Update AT+CIUPDATE +CIPUPDATE:2, +CIPUPDATE:3,
+CIPUPDATE:4, OK
TCP Client AT+CIPMUX=1 turn on multiple connection
connect to remote TCP server
TCP Client AT+CIPSTART=4,"TCP","192,168.1.104",9999
192.168.1.104 (the PC)
optionally enter into data
TCP Client AT+CIPMODE=1
transmission mode
send data via channel 4, 5 bytes
length (see socket test result
TCP Client AT+CIPSEND=4,5 below, only "elect" received), link
will be "unlink" when no data go
through
setup TCP server, on port 9999, 1
TCP Server AT+CIPSERVER=1,9999
means enable
TCP Server AT+CIFSR check module IP address
Test, PC as a TCP client connect to module using socket test, send data
Socket test running result, In the sockettest, do not tick the "secure" in TCP client, it causes
unstable
CIPSTART CIPSEND send data Receive data
"Electrodragon"
change the SSID and password in code for your wifi router
#include <SoftwareSerial.h>
#define SSID "xxxxxxxx"
#define PASS "xxxxxxxx"
#define DST_IP "220.181.111.85" //baidu.com
SoftwareSerial dbgSerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
Serial.setTimeout(5000);
dbgSerial.begin(9600); //can't be faster than 19200 for softserial
dbgSerial.println("ESP8266 Demo");
//test if the module is ready
Serial.println("AT+RST");
delay(1000);
if (Serial.find("ready"))
{
dbgSerial.println("Module is ready");
}
else
{
dbgSerial.println("Module have no response.");
while (1);
}
delay(1000);
//connect to the wifi
boolean connected = false;
for (int i = 0; i < 5; i++)
{
if (connectWiFi())
{
connected = true;
break;
}
}
if (!connected) {
while (1);
}
delay(5000);
//print the ip addr
/*Serial.println("AT+CIFSR");
dbgSerial.println("ip address:");
while (Serial.available())
dbgSerial.write(Serial.read());*/
//set the single connection mode
Serial.println("AT+CIPMUX=0");
}
void loop()
{
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_IP;
cmd += "\",80";
Serial.println(cmd);
dbgSerial.println(cmd);
if (Serial.find("Error")) return;
cmd = "GET / HTTP/1.0\r\n\r\n";
Serial.print("AT+CIPSEND=");
Serial.println(cmd.length());
if (Serial.find(">"))
{
dbgSerial.print(">");
} else
{
Serial.println("AT+CIPCLOSE");
dbgSerial.println("connect timeout");
delay(1000);
return;
}
Serial.print(cmd);
delay(2000);
//Serial.find("+IPD");
while (Serial.available())
{
char c = Serial.read();
dbgSerial.write(c);
if (c == '\r') dbgSerial.print('\n');
}
dbgSerial.println("====");
delay(1000);
}
boolean connectWiFi()
{
Serial.println("AT+CWMODE=1");
String cmd = "AT+CWJAP=\"";
cmd += SSID;
cmd += "\",\"";
cmd += PASS;
cmd += "\"";
dbgSerial.println(cmd);
Serial.println(cmd);
delay(2000);
if (Serial.find("OK"))
{
dbgSerial.println("OK, Connected to WiFi.");
return true;
} else
{
dbgSerial.println("Can not connect to the WiFi.");
return false;
}
}
Note
Avoid to use GPIO4 (D2) and GPIO5 (D1) in nodemcu, it seems switched: GPIO5 =D2 and
GPIO4=D1
Retrieved from "http://www.electrodragon.com/w/index.php?title=ESP8266_Basic&oldid=12515"
Category: ESP8266