API
For Arduino developers
Public Member Functions | List of all members
ESP8266 Class Reference

Provide an easy-to-use way to manipulate ESP8266. More...

#include <ESP8266.h>

Public Member Functions

bool kick (void)
 Verify ESP8266 whether live or not. More...
 
bool restart (void)
 Restart ESP8266 by "AT+RST". More...
 
String getVersion (void)
 Get the version of AT Command Set. More...
 
bool setOprToStation (void)
 Set operation mode to staion. More...
 
bool setOprToSoftAP (void)
 Set operation mode to softap. More...
 
bool setOprToStationSoftAP (void)
 Set operation mode to station + softap. More...
 
String getAPList (void)
 Search available AP list and return it. More...
 
bool joinAP (String ssid, String pwd)
 Join in AP. More...
 
bool leaveAP (void)
 Leave AP joined before. More...
 
bool setSoftAPParam (String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4)
 Set SoftAP parameters. More...
 
String getJoinedDeviceIP (void)
 Get the IP list of devices connected to SoftAP. More...
 
String getIPStatus (void)
 Get the current status of connection(UDP and TCP). More...
 
String getLocalIP (void)
 Get the IP address of ESP8266. More...
 
bool enableMUX (void)
 Enable IP MUX(multiple connection mode). More...
 
bool disableMUX (void)
 Disable IP MUX(single connection mode). More...
 
bool createTCP (String addr, uint32_t port)
 Create TCP connection in single mode. More...
 
bool releaseTCP (void)
 Release TCP connection in single mode. More...
 
bool registerUDP (String addr, uint32_t port)
 Register UDP port number in single mode. More...
 
bool unregisterUDP (void)
 Unregister UDP port number in single mode. More...
 
bool createTCP (uint8_t mux_id, String addr, uint32_t port)
 Create TCP connection in multiple mode. More...
 
bool releaseTCP (uint8_t mux_id)
 Release TCP connection in multiple mode. More...
 
bool registerUDP (uint8_t mux_id, String addr, uint32_t port)
 Register UDP port number in multiple mode. More...
 
bool unregisterUDP (uint8_t mux_id)
 Unregister UDP port number in multiple mode. More...
 
bool setTCPServerTimeout (uint32_t timeout=180)
 Set the timeout of TCP Server. More...
 
bool startTCPServer (uint32_t port=333)
 Start TCP Server(Only in multiple mode). More...
 
bool stopTCPServer (void)
 Stop TCP Server(Only in multiple mode). More...
 
bool startServer (uint32_t port=333)
 Start Server(Only in multiple mode). More...
 
bool stopServer (void)
 Stop Server(Only in multiple mode). More...
 
bool send (const uint8_t *buffer, uint32_t len)
 Send data based on TCP or UDP builded already in single mode. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Detailed Description

Provide an easy-to-use way to manipulate ESP8266.

Examples:
ConnectWiFi.ino, HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 38 of file ESP8266.h.

Member Function Documentation

bool ESP8266::createTCP ( String  addr,
uint32_t  port 
)

Create TCP connection in single mode.

Parameters
addr- the IP or domain name of the target host.
port- the port number of the target host.
Return values
true- success.
false- failure.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, and TCPClientSingleUNO.ino.

Definition at line 191 of file ESP8266.cpp.

bool ESP8266::createTCP ( uint8_t  mux_id,
String  addr,
uint32_t  port 
)

Create TCP connection in multiple mode.

Parameters
mux_id- the identifier of this TCP(available value: 0 - 4).
addr- the IP or domain name of the target host.
port- the port number of the target host.
Return values
true- success.
false- failure.

Definition at line 211 of file ESP8266.cpp.

bool ESP8266::disableMUX ( void  )

Disable IP MUX(single connection mode).

In single connection mode, only one TCP or UDP communication can be builded.

Return values
true- success.
false- failure.
Examples:
HTTPGET.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, and UDPClientSingle.ino.

Definition at line 186 of file ESP8266.cpp.

bool ESP8266::enableMUX ( void  )

Enable IP MUX(multiple connection mode).

In multiple connection mode, a couple of TCP and UDP communication can be builded. They can be distinguished by the identifier of TCP or UDP named mux_id.

Return values
true- success.
false- failure.
Examples:
TCPClientMultiple.ino, TCPServer.ino, and UDPClientMultiple.ino.

Definition at line 181 of file ESP8266.cpp.

String ESP8266::getAPList ( void  )

Search available AP list and return it.

Returns
the list of available APs.
Note
This method will occupy a lot of memeory(hundreds of Bytes to a couple of KBytes). Do not call this method unless you must and ensure that your board has enough memery left.

Definition at line 138 of file ESP8266.cpp.

String ESP8266::getIPStatus ( void  )

Get the current status of connection(UDP and TCP).

Returns
the status.
Examples:
TCPServer.ino.

Definition at line 167 of file ESP8266.cpp.

String ESP8266::getJoinedDeviceIP ( void  )

Get the IP list of devices connected to SoftAP.

Returns
the list of IP.
Note
This method should not be called when station mode.

Definition at line 160 of file ESP8266.cpp.

String ESP8266::getLocalIP ( void  )
String ESP8266::getVersion ( void  )

Get the version of AT Command Set.

Returns
the string of version.
Examples:
ConnectWiFi.ino, HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 80 of file ESP8266.cpp.

bool ESP8266::joinAP ( String  ssid,
String  pwd 
)

Join in AP.

Parameters
ssid- SSID of AP to join in.
pwd- Password of AP to join in.
Return values
true- success.
false- failure.
Note
This method will take a couple of seconds.
Examples:
ConnectWiFi.ino, HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 145 of file ESP8266.cpp.

bool ESP8266::kick ( void  )

Verify ESP8266 whether live or not.

Actually, this method will send command "AT" to ESP8266 and waiting for "OK".

Return values
true- alive.
false- dead.

Definition at line 58 of file ESP8266.cpp.

bool ESP8266::leaveAP ( void  )

Leave AP joined before.

Return values
true- success.
false- failure.

Definition at line 150 of file ESP8266.cpp.

uint32_t ESP8266::recv ( uint8_t *  buffer,
uint32_t  buffer_size,
uint32_t  timeout = 1000 
)

Receive data from TCP or UDP builded already in single mode.

Parameters
buffer- the buffer for storing data.
buffer_size- the length of the buffer.
timeout- the time waiting data.
Returns
the length of data received actually.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 271 of file ESP8266.cpp.

uint32_t ESP8266::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.

Parameters
mux_id- the identifier of this TCP(available value: 0 - 4).
buffer- the buffer for storing data.
buffer_size- the length of the buffer.
timeout- the time waiting data.
Returns
the length of data received actually.

Definition at line 276 of file ESP8266.cpp.

uint32_t ESP8266::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.

After return, coming_mux_id store the id of TCP or UDP from which data coming. User should read the value of coming_mux_id and decide what next to do.

Parameters
coming_mux_id- the identifier of TCP or UDP.
buffer- the buffer for storing data.
buffer_size- the length of the buffer.
timeout- the time waiting data.
Returns
the length of data received actually.

Definition at line 287 of file ESP8266.cpp.

bool ESP8266::registerUDP ( String  addr,
uint32_t  port 
)

Register UDP port number in single mode.

Parameters
addr- the IP or domain name of the target host.
port- the port number of the target host.
Return values
true- success.
false- failure.
Examples:
UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 201 of file ESP8266.cpp.

bool ESP8266::registerUDP ( uint8_t  mux_id,
String  addr,
uint32_t  port 
)

Register UDP port number in multiple mode.

Parameters
mux_id- the identifier of this TCP(available value: 0 - 4).
addr- the IP or domain name of the target host.
port- the port number of the target host.
Return values
true- success.
false- failure.

Definition at line 221 of file ESP8266.cpp.

bool ESP8266::releaseTCP ( void  )

Release TCP connection in single mode.

Return values
true- success.
false- failure.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, and TCPServer.ino.

Definition at line 196 of file ESP8266.cpp.

bool ESP8266::releaseTCP ( uint8_t  mux_id)

Release TCP connection in multiple mode.

Parameters
mux_id- the identifier of this TCP(available value: 0 - 4).
Return values
true- success.
false- failure.

Definition at line 216 of file ESP8266.cpp.

bool ESP8266::restart ( void  )

Restart ESP8266 by "AT+RST".

This method will take 3 seconds or more.

Return values
true- success.
false- failure.

Definition at line 63 of file ESP8266.cpp.

bool ESP8266::send ( const uint8_t *  buffer,
uint32_t  len 
)

Send data based on TCP or UDP builded already in single mode.

Parameters
buffer- the buffer of data to send.
len- the length of data to send.
Return values
true- success.
false- failure.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 261 of file ESP8266.cpp.

bool ESP8266::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.

Parameters
mux_id- the identifier of this TCP(available value: 0 - 4).
buffer- the buffer of data to send.
len- the length of data to send.
Return values
true- success.
false- failure.

Definition at line 266 of file ESP8266.cpp.

bool ESP8266::setOprToSoftAP ( void  )

Set operation mode to softap.

Return values
true- success.
false- failure.

Definition at line 104 of file ESP8266.cpp.

bool ESP8266::setOprToStation ( void  )

Set operation mode to staion.

Return values
true- success.
false- failure.
Examples:
ConnectWiFi.ino.

Definition at line 87 of file ESP8266.cpp.

bool ESP8266::setOprToStationSoftAP ( void  )

Set operation mode to station + softap.

Return values
true- success.
false- failure.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 121 of file ESP8266.cpp.

bool ESP8266::setSoftAPParam ( String  ssid,
String  pwd,
uint8_t  chl = 7,
uint8_t  ecn = 4 
)

Set SoftAP parameters.

Parameters
ssid- SSID of SoftAP.
pwd- PASSWORD of SoftAP.
chl- the channel (1 - 13, default: 7).
ecn- the way of encrypstion (0 - OPEN, 1 - WEP, 2 - WPA_PSK, 3 - WPA2_PSK, 4 - WPA_WPA2_PSK, default: 4).
Note
This method should not be called when station mode.

Definition at line 155 of file ESP8266.cpp.

bool ESP8266::setTCPServerTimeout ( uint32_t  timeout = 180)

Set the timeout of TCP Server.

Parameters
timeout- the duration for timeout by second(0 ~ 28800, default:180).
Return values
true- success.
false- failure.
Examples:
TCPServer.ino.

Definition at line 231 of file ESP8266.cpp.

bool ESP8266::startServer ( uint32_t  port = 333)

Start Server(Only in multiple mode).

Parameters
port- the port number to listen(default: 333).
Return values
true- success.
false- failure.
See also
String getIPStatus(void);
uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t len, uint32_t timeout);

Definition at line 251 of file ESP8266.cpp.

bool ESP8266::startTCPServer ( uint32_t  port = 333)

Start TCP Server(Only in multiple mode).

After started, user should call method: getIPStatus to know the status of TCP connections. The methods of receiving data can be called for user's any purpose. After communication, release the TCP connection is needed by calling method: releaseTCP with mux_id.

Parameters
port- the port number to listen(default: 333).
Return values
true- success.
false- failure.
See also
String getIPStatus(void);
uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t len, uint32_t timeout);
bool releaseTCP(uint8_t mux_id);
Examples:
TCPServer.ino.

Definition at line 236 of file ESP8266.cpp.

bool ESP8266::stopServer ( void  )

Stop Server(Only in multiple mode).

Return values
true- success.
false- failure.

Definition at line 256 of file ESP8266.cpp.

bool ESP8266::stopTCPServer ( void  )

Stop TCP Server(Only in multiple mode).

Return values
true- success.
false- failure.

Definition at line 244 of file ESP8266.cpp.

bool ESP8266::unregisterUDP ( void  )

Unregister UDP port number in single mode.

Return values
true- success.
false- failure.
Examples:
UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 206 of file ESP8266.cpp.

bool ESP8266::unregisterUDP ( uint8_t  mux_id)

Unregister UDP port number in multiple mode.

Parameters
mux_id- the identifier of this TCP(available value: 0 - 4).
Return values
true- success.
false- failure.

Definition at line 226 of file ESP8266.cpp.


The documentation for this class was generated from the following files: