The current ESP8266 library project is called 'WeeESP8266'.
The WeeESP8266 Arduino API documentation is located here and the library files can be downloaded here from Github.
The ESP8266 interface uses standard 'AT' (attention) commands. It uses the same type of commands that were used in MODEMs . . . . remember them? Below is a list of the standard commands but be aware that this may change with time.
AT COMMANDS
NOTE: There are must be no any spaces between the " and IP address or port
Commands | Description | Type | Set/Execute | Inquiry | test | Parameters | Examples |
---|---|---|---|---|---|---|---|
AT+RST | restart the module | basic | - | - | - | - | |
AT+CWMODE | wifi mode | wifi | AT+CWMODE=<mode> | AT+CWMODE? | AT+CWMODE=? | 1= Sta, 2= AP, 3=both | |
AT+CWJAP | join the AP | wifi | AT+ CWJAP =<ssid>,< pwd > | AT+ CWJAP? | - | ssid = ssid, pwd = wifi password | |
AT+CWLAP | list the AP | wifi | AT+CWLAP | ||||
AT+CWQAP | quit the AP | wifi | AT+CWQAP | - | AT+CWQAP=? | ||
AT+ CWSAP | set the parameters of AP | wifi | AT+ CWSAP= <ssid>,<pwd>,<chl>, <ecn> | AT+ CWSAP? | ssid, pwd, chl = channel, ecn = encryption | Connect to your router: :AT+CWJAP="YOURSSID","helloworld"; and check if connected: AT+CWJAP? | |
AT+ CIPSTATUS | get the connection status | TCP/IP | AT+ CIPSTATUS | ||||
AT+CIPSTART | set up TCP or UDP connection | TCP/IP | 1)single connection (+CIPMUX=0) AT+CIPSTART= <type>,<addr>,<port>; 2) multiple connection (+CIPMUX=1) AT+CIPSTART= <id><type>,<addr>, <port> | - | AT+CIPSTART=? | id = 0-4, type = TCP/UDP, addr = IP address, port= port | Connect to another TCP server, set multiple connection first: AT+CIPMUX=1; connect: AT+CIPSTART=4,"TCP","X1.X2.X3.X4",9999 |
AT+CIPSEND | send data | TCP/IP | 1)single connection(+CIPMUX=0) AT+CIPSEND=<length>; 2) multiple connection (+CIPMUX=1) AT+CIPSEND= <id>,<length> | AT+CIPSEND=? | send data: AT+CIPSEND=4,15 and then enter the data | ||
AT+CIPCLOSE | close TCP or UDP connection | TCP/IP | AT+CIPCLOSE=<id> or AT+CIPCLOSE | AT+CIPCLOSE=? | |||
AT+CIFSR | Get IP address | TCP/IP | AT+CIFSR | AT+ CIFSR=? | |||
AT+ CIPMUX | set mutiple connection | TCP/IP | AT+ CIPMUX=<mode> | AT+ CIPMUX? | 0 for single connection 1 for mutiple connection | ||
AT+ CIPSERVER | set as server | TCP/IP | AT+ CIPSERVER= <mode>[,<port> ] | mode 0 to close server mode, mode 1 to open; port = port | turn on as a TCP server: AT+CIPSERVER=1,8888, check the self server IP address: AT+CIFSR=? | ||
+IPD | received data |
WeeESP8266 API
bool kick (void) : Verify ESP8266 whether live or not.
bool restart (void) : Restart ESP8266 by "AT+RST".
String getVersion (void) : Get the version of AT Command Set.
bool setOprToStation (void) : Set operation mode to staion.
bool setOprToSoftAP (void) : Set operation mode to softap.
bool setOprToStationSoftAP (void) : Set operation mode to station + softap.
String getAPList (void) : Search available AP list and return it.
bool joinAP (String ssid, String pwd) : Join in AP.
bool leaveAP (void) : Leave AP joined before.
bool setSoftAPParam (String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4) : Set SoftAP parameters.
String getJoinedDeviceIP (void) : Get the IP list of devices connected to SoftAP.
String getIPStatus (void) : Get the current status of connection(UDP and TCP).
String getLocalIP (void) : Get the IP address of ESP8266.
bool enableMUX (void) : Enable IP MUX(multiple connection mode).
bool disableMUX (void) : Disable IP MUX(single connection mode).
bool createTCP (String addr, uint32_t port) : Create TCP connection in single mode.
bool releaseTCP (void) : Release TCP connection in single mode.
bool registerUDP (String addr, uint32_t port) : Register UDP port number in single mode.
bool unregisterUDP (void) : Unregister UDP port number in single mode.
bool createTCP (uint8_t mux_id, String addr, uint32_t port) : Create TCP connection in multiple mode.
bool releaseTCP (uint8_t mux_id) : Release TCP connection in multiple mode.
bool registerUDP (uint8_t mux_id, String addr, uint32_t port) : Register UDP port number in multiple mode.
bool unregisterUDP (uint8_t mux_id) : Unregister UDP port number in multiple mode.
bool setTCPServerTimeout (uint32_t timeout=180) : Set the timeout of TCP Server.
bool startServer (uint32_t port=333) : Start Server(Only in multiple mode).
bool stopServer (void) : Stop Server(Only in multiple mode).
bool startTCPServer (uint32_t port=333) : Start TCP Server(Only in multiple mode).
bool stopTCPServer (void) : Stop TCP Server(Only in multiple mode).
bool send (const uint8_t *buffer, uint32_t len) : Send data based on TCP or UDP builded already in single mode.
bool send (uint8_t mux_id, const uint8_t *buffer, uint32_t len) : Send data based on one of TCP or UDP builded already in multiple mode.
uint32_t recv (uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from TCP or UDP builded already in single mode.
uint32_t recv (uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from one of TCP or UDP builded already in multiple mode.
uint32_t recv (uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from all of TCP or UDP builded already in multiple mode.
Wiring connections to Arduino
MEGA
Serial 1 can be used. Create an object (named wifi) of class ESP8266 in your code like this:
#include "ESP8266.h"
ESP8266 wifi(Serial1);
The connection should be like these:
The connection should be like these:
ESP8266_TX -> RX1(D19)
ESP8266_RX -> TX1(D18)
ESP8266_CH_PD -> 3.3V
ESP8266_VCC -> 3.3V
ESP8266_GND -> GND
UNO
Software Serial can be used. Create an object (named wifi) of class ESP8266 in your code like this:
#include "ESP8266.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2); /* RX:D3, TX:D2 */
ESP8266 wifi(mySerial);
The connection should be like these:
The connection should be like these:
ESP8266_TX -> RX(D3)
ESP8266_RX -> TX(D2)
ESP8266_CH_PD -> 3.3V
ESP8266_VCC -> 3.3V
ESP8266_GND -> GND