Skip to content

Added MDNS functions #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 79 additions & 27 deletions ESP8266.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @file ESP8266.cpp
* @brief The implementation of class ESP8266.
* @author Wu Pengfei<[email protected]>
* @brief The implementation of class ESP8266.
* @author Wu Pengfei<[email protected]>
* @date 2015.02
*
*
* @par Copyright:
* Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n
* This program is free software; you can redistribute it and/or
@@ -147,6 +147,10 @@ bool ESP8266::joinAP(String ssid, String pwd)
return sATCWJAP(ssid, pwd);
}

bool ESP8266::setStaticIp(String ip, String gateway, String mask){
return sATCIPSTACUR(ip, gateway, mask);
}

bool ESP8266::enableClientDHCP(uint8_t mode, boolean enabled)
{
return sATCWDHCP(mode, enabled);
@@ -263,6 +267,16 @@ bool ESP8266::stopServer(void)
return stopTCPServer();
}

bool ESP8266::enableMDNS(String hostname, String servername, uint32_t port)
{
return sATCMDNS(true, hostname, servername, port);
}

bool ESP8266::disableMDNS(void)
{
return sATCMDNS(false, "", "", 0);
}

bool ESP8266::send(const uint8_t *buffer, uint32_t len)
{
return sATCIPSENDSingle(buffer, len);
@@ -311,25 +325,25 @@ uint32_t ESP8266::recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_
uint32_t ret;
unsigned long start;
uint32_t i;

if (buffer == NULL) {
return 0;
}

start = millis();
while (millis() - start < timeout) {
if(m_puart->available() > 0) {
a = m_puart->read();
data += a;
}

index_PIPDcomma = data.indexOf("+IPD,");
if (index_PIPDcomma != -1) {
index_colon = data.indexOf(':', index_PIPDcomma + 5);
if (index_colon != -1) {
index_comma = data.indexOf(',', index_PIPDcomma + 5);
/* +IPD,id,len:data */
if (index_comma != -1 && index_comma < index_colon) {
if (index_comma != -1 && index_comma < index_colon) {
id = data.substring(index_PIPDcomma + 5, index_comma).toInt();
if (id < 0 || id > 4) {
return 0;
@@ -349,7 +363,7 @@ uint32_t ESP8266::recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_
}
}
}

if (has_data) {
i = 0;
ret = len > buffer_size ? buffer_size : len;
@@ -362,7 +376,7 @@ uint32_t ESP8266::recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_
if (i == ret) {
rx_empty();
if (data_len) {
*data_len = len;
*data_len = len;
}
if (index_comma != -1 && coming_mux_id) {
*coming_mux_id = id;
@@ -374,7 +388,7 @@ uint32_t ESP8266::recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_
return 0;
}

void ESP8266::rx_empty(void)
void ESP8266::rx_empty(void)
{
while(m_puart->available() > 0) {
m_puart->read();
@@ -394,7 +408,7 @@ String ESP8266::recvString(String target, uint32_t timeout)
}
if (data.indexOf(target) != -1) {
break;
}
}
}
return data;
}
@@ -475,7 +489,7 @@ bool ESP8266::eAT(void)
return recvFind("OK");
}

bool ESP8266::eATRST(void)
bool ESP8266::eATRST(void)
{
rx_empty();
m_puart->println("AT+RST");
@@ -486,10 +500,10 @@ bool ESP8266::eATGMR(String &version)
{
rx_empty();
m_puart->println("AT+GMR");
return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", version);
return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", version);
}

bool ESP8266::qATCWMODE(uint8_t *mode)
bool ESP8266::qATCWMODE(uint8_t *mode)
{
String str_mode;
bool ret;
@@ -498,7 +512,7 @@ bool ESP8266::qATCWMODE(uint8_t *mode)
}
rx_empty();
m_puart->println("AT+CWMODE?");
ret = recvFindAndFilter("OK", "+CWMODE:", "\r\n\r\nOK", str_mode);
ret = recvFindAndFilter("OK", "+CWMODE:", "\r\n\r\nOK", str_mode);
if (ret) {
*mode = (uint8_t)str_mode.toInt();
return true;
@@ -513,7 +527,7 @@ bool ESP8266::sATCWMODE(uint8_t mode)
rx_empty();
m_puart->print("AT+CWMODE=");
m_puart->println(mode);

data = recvString("OK", "no change");
if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
return true;
@@ -530,7 +544,25 @@ bool ESP8266::sATCWJAP(String ssid, String pwd)
m_puart->print("\",\"");
m_puart->print(pwd);
m_puart->println("\"");


data = recvString("OK", "FAIL", 10000);
if (data.indexOf("OK") != -1) {
return true;
}
return false;
}

bool ESP8266::sATCIPSTACUR(String ip, String gateway, String mask)
{
String data;
rx_empty();
m_puart->print("AT+CIPSTA_CUR=\"");
m_puart->print(ip);
m_puart->print("\",\"");
m_puart->print(gateway);
m_puart->print("\",\"");
m_puart->print(mask);
m_puart->println("\"");
data = recvString("OK", "FAIL", 10000);
if (data.indexOf("OK") != -1) {
return true;
@@ -544,15 +576,15 @@ bool ESP8266::sATCWDHCP(uint8_t mode, boolean enabled)
if (enabled) {
strEn = "1";
}


String data;
rx_empty();
m_puart->print("AT+CWDHCP=");
m_puart->print(strEn);
m_puart->print(",");
m_puart->println(mode);

data = recvString("OK", "FAIL", 10000);
if (data.indexOf("OK") != -1) {
return true;
@@ -588,7 +620,7 @@ bool ESP8266::sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn)
m_puart->print(chl);
m_puart->print(",");
m_puart->println(ecn);

data = recvString("OK", "ERROR", 5000);
if (data.indexOf("OK") != -1) {
return true;
@@ -621,7 +653,7 @@ bool ESP8266::sATCIPSTARTSingle(String type, String addr, uint32_t port)
m_puart->print(addr);
m_puart->print("\",");
m_puart->println(port);

data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000);
if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) {
return true;
@@ -640,7 +672,7 @@ bool ESP8266::sATCIPSTARTMultiple(uint8_t mux_id, String type, String addr, uint
m_puart->print(addr);
m_puart->print("\",");
m_puart->println(port);

data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000);
if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) {
return true;
@@ -683,7 +715,7 @@ bool ESP8266::sATCIPCLOSEMulitple(uint8_t mux_id)
rx_empty();
m_puart->print("AT+CIPCLOSE=");
m_puart->println(mux_id);

data = recvString("OK", "link is not", 5000);
if (data.indexOf("OK") != -1 || data.indexOf("link is not") != -1) {
return true;
@@ -708,7 +740,7 @@ bool ESP8266::sATCIPMUX(uint8_t mode)
rx_empty();
m_puart->print("AT+CIPMUX=");
m_puart->println(mode);

data = recvString("OK", "Link is builded");
if (data.indexOf("OK") != -1) {
return true;
@@ -722,7 +754,7 @@ bool ESP8266::sATCIPSERVER(uint8_t mode, uint32_t port)
rx_empty();
m_puart->print("AT+CIPSERVER=1,");
m_puart->println(port);

data = recvString("OK", "no change");
if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
return true;
@@ -741,4 +773,24 @@ bool ESP8266::sATCIPSTO(uint32_t timeout)
m_puart->println(timeout);
return recvFind("OK");
}

bool ESP8266::sATCMDNS(bool enable, String hostname, String servername, uint32_t port)
{
String data;
if (enable) {
rx_empty();
m_puart->print("AT+MDNS=1,\"");
m_puart->print(hostname);
m_puart->print("\",\"");
m_puart->print(servername);
m_puart->print("\",");
m_puart->println(port);
} else {
rx_empty();
m_puart->println("AT+MDNS=0");
}
data = recvString("OK", "ERROR");
if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
return true;
}
return false;
}
407 changes: 219 additions & 188 deletions ESP8266.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @file ESP8266.h
* @brief The definition of class ESP8266.
* @author Wu Pengfei<pengfei.wu@itead.cc>
* @brief The definition of class ESP8266.
* @author Wu Pengfei<pengfei.wu@itead.cc>
* @date 2015.02
*
*
* @par Copyright:
* Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n
* This program is free software; you can redistribute it and/or
@@ -33,272 +33,282 @@


/**
* Provide an easy-to-use way to manipulate ESP8266.
* Provide an easy-to-use way to manipulate ESP8266.
*/
class ESP8266 {
public:

#ifdef ESP8266_USE_SOFTWARE_SERIAL
/*
* Constuctor.
* Constuctor.
*
* @param uart - an reference of SoftwareSerial object.
* @param baud - the buad rate to communicate with ESP8266(default:9600).
* @param uart - an reference of SoftwareSerial object.
* @param baud - the buad rate to communicate with ESP8266(default:9600).
*
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
*/
ESP8266(SoftwareSerial &uart, uint32_t baud = 9600);
#else /* HardwareSerial */
/*
* Constuctor.
* Constuctor.
*
* @param uart - an reference of HardwareSerial object.
* @param baud - the buad rate to communicate with ESP8266(default:9600).
* @param uart - an reference of HardwareSerial object.
* @param baud - the buad rate to communicate with ESP8266(default:9600).
*
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
*/
ESP8266(HardwareSerial &uart, uint32_t baud = 9600);
#endif


/**
* Verify ESP8266 whether live or not.


/**
* Verify ESP8266 whether live or not.
*
* Actually, this method will send command "AT" to ESP8266 and waiting for "OK".
*
* Actually, this method will send command "AT" to ESP8266 and waiting for "OK".
*
* @retval true - alive.
* @retval false - dead.
*/
bool kick(void);

/**
* Restart ESP8266 by "AT+RST".
* Restart ESP8266 by "AT+RST".
*
* This method will take 3 seconds or more.
* This method will take 3 seconds or more.
*
* @retval true - success.
* @retval false - failure.
*/
bool restart(void);

/**
* Get the version of AT Command Set.
*
* @return the string of version.
* Get the version of AT Command Set.
*
* @return the string of version.
*/
String getVersion(void);

/**
* Set operation mode to staion.
*
* Set operation mode to staion.
*
* @retval true - success.
* @retval false - failure.
*/
bool setOprToStation(void);

/**
* Set operation mode to softap.
*
* Set operation mode to softap.
*
* @retval true - success.
* @retval false - failure.
*/
bool setOprToSoftAP(void);

/**
* Set operation mode to station + softap.
*
* Set operation mode to station + softap.
*
* @retval true - success.
* @retval false - failure.
*/
bool setOprToStationSoftAP(void);

/**
* Search available AP list and return it.
*
* @return the list of available APs.
* @note This method will occupy a lot of memeory(hundreds of Bytes to a couple of KBytes).
*
* @return 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.
*/
String getAPList(void);

/**
* Join in AP.
* Join in AP.
*
* @param ssid - SSID of AP to join in.
* @param pwd - Password of AP to join in.
* @param ssid - SSID of AP to join in.
* @param pwd - Password of AP to join in.
* @retval true - success.
* @retval false - failure.
* @note This method will take a couple of seconds.
* @note This method will take a couple of seconds.
*/
bool joinAP(String ssid, String pwd);



/**
* Enable DHCP for client mode.
*Set Static IP address.
*
* @param ip - host ip address.
* @param gateway - gateway address.
* @param mask - network mask
* @retval true - success.
* @retval false - failure.
*/
bool setStaticIp(String ip, String gateway, String mask);

/**
* Enable DHCP for client mode.
*
* @param mode - server mode (0=soft AP, 1=station, 2=both
* @param enabled - true if dhcp should be enabled, otherwise false
*
*
* @note This method will enable DHCP but only for client mode!
*/
bool enableClientDHCP(uint8_t mode, boolean enabled);

/**
* Leave AP joined before.
* Leave AP joined before.
*
* @retval true - success.
* @retval false - failure.
*/
bool leaveAP(void);

/**
* Set SoftAP parameters.
*
* @param ssid - SSID of SoftAP.
* @param pwd - PASSWORD of SoftAP.
* @param chl - the channel (1 - 13, default: 7).
* @param 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.
* Set SoftAP parameters.
*
* @param ssid - SSID of SoftAP.
* @param pwd - PASSWORD of SoftAP.
* @param chl - the channel (1 - 13, default: 7).
* @param 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.
*/
bool setSoftAPParam(String ssid, String pwd, uint8_t chl = 7, uint8_t ecn = 4);

/**
* Get the IP list of devices connected to SoftAP.
*
* Get the IP list of devices connected to SoftAP.
*
* @return the list of IP.
* @note This method should not be called when station mode.
* @note This method should not be called when station mode.
*/
String getJoinedDeviceIP(void);

/**
* Get the current status of connection(UDP and TCP).
*
* @return the status.
* Get the current status of connection(UDP and TCP).
*
* @return the status.
*/
String getIPStatus(void);

/**
* Get the IP address of ESP8266.
* Get the IP address of ESP8266.
*
* @return the IP list.
* @return the IP list.
*/
String getLocalIP(void);

/**
* Enable IP MUX(multiple connection mode).
* 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.
*
* 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.
*
* @retval true - success.
* @retval false - failure.
*/
bool enableMUX(void);

/**
* Disable IP MUX(single connection mode).
* Disable IP MUX(single connection mode).
*
* In single connection mode, only one TCP or UDP communication can be builded.
*
* In single connection mode, only one TCP or UDP communication can be builded.
*
* @retval true - success.
* @retval false - failure.
*/
bool disableMUX(void);


/**
* Create TCP connection in single mode.
*
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* Create TCP connection in single mode.
*
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* @retval true - success.
* @retval false - failure.
*/
bool createTCP(String addr, uint32_t port);

/**
* Release TCP connection in single mode.
*
* Release TCP connection in single mode.
*
* @retval true - success.
* @retval false - failure.
*/
bool releaseTCP(void);

/**
* Register UDP port number in single mode.
*
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
*
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* @retval true - success.
* @retval false - failure.
*/
bool registerUDP(String addr, uint32_t port);

/**
* Unregister UDP port number in single mode.
*
* Unregister UDP port number in single mode.
*
* @retval true - success.
* @retval false - failure.
*/
bool unregisterUDP(void);

/**
* Create TCP connection in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* Create TCP connection in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* @retval true - success.
* @retval false - failure.
*/
bool createTCP(uint8_t mux_id, String addr, uint32_t port);

/**
* Release TCP connection in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* Release TCP connection in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @retval true - success.
* @retval false - failure.
*/
bool releaseTCP(uint8_t mux_id);

/**
* Register UDP port number in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param addr - the IP or domain name of the target host.
* @param port - the port number of the target host.
* @retval true - success.
* @retval false - failure.
*/
bool registerUDP(uint8_t mux_id, String addr, uint32_t port);

/**
* Unregister UDP port number in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* Unregister UDP port number in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @retval true - success.
* @retval false - failure.
*/
bool unregisterUDP(uint8_t mux_id);


/**
* Set the timeout of TCP Server.
*
* @param timeout - the duration for timeout by second(0 ~ 28800, default:180).
* Set the timeout of TCP Server.
*
* @param timeout - the duration for timeout by second(0 ~ 28800, default:180).
* @retval true - success.
* @retval false - failure.
*/
bool setTCPServerTimeout(uint32_t timeout = 180);

/**
* 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.
* 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.
*
* @param port - the port number to listen(default: 333).
* @retval true - success.
@@ -311,16 +321,16 @@ class ESP8266 {
bool startTCPServer(uint32_t port = 333);

/**
* Stop TCP Server(Only in multiple mode).
*
* Stop TCP Server(Only in multiple mode).
*
* @retval true - success.
* @retval false - failure.
*/
bool stopTCPServer(void);

/**
* Start Server(Only in multiple mode).
*
* Start Server(Only in multiple mode).
*
* @param port - the port number to listen(default: 333).
* @retval true - success.
* @retval false - failure.
@@ -331,118 +341,137 @@ class ESP8266 {
bool startServer(uint32_t port = 333);

/**
* Stop Server(Only in multiple mode).
*
* Stop Server(Only in multiple mode).
*
* @retval true - success.
* @retval false - failure.
*/
bool stopServer(void);

/**
* Send data based on TCP or UDP builded already in single mode.
*
* @param buffer - the buffer of data to send.
* @param len - the length of data to send.
Enable MDNS
@param hostname - MDNS host name.
@param servername - MDNS server name.
@param port - MDNS server port.
@retval true - success.
@retval false - failure.
*/
bool enableMDNS(String hostname, String servername, uint32_t port);

/**
Disable MDNS
@retval true - success.
@retval false - failure.
*/
bool disableMDNS(void);

/**
* Send data based on TCP or UDP builded already in single mode.
*
* @param buffer - the buffer of data to send.
* @param len - the length of data to send.
* @retval true - success.
* @retval false - failure.
*/
bool send(const uint8_t *buffer, uint32_t len);

/**
* Send data based on one of TCP or UDP builded already in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param buffer - the buffer of data to send.
* @param len - the length of data to send.
* Send data based on one of TCP or UDP builded already in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param buffer - the buffer of data to send.
* @param len - the length of data to send.
* @retval true - success.
* @retval false - failure.
*/
bool send(uint8_t mux_id, const uint8_t *buffer, uint32_t len);

/**
* Receive data from TCP or UDP builded already in single mode.
* Receive data from TCP or UDP builded already in single mode.
*
* @param buffer - the buffer for storing data.
* @param buffer_size - the length of the buffer.
* @param timeout - the time waiting data.
* @return the length of data received actually.
* @param buffer - the buffer for storing data.
* @param buffer_size - the length of the buffer.
* @param timeout - the time waiting data.
* @return the length of data received actually.
*/
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000);

/**
* Receive data from one of TCP or UDP builded already in multiple mode.
* Receive data from one of TCP or UDP builded already in multiple mode.
*
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param buffer - the buffer for storing data.
* @param buffer_size - the length of the buffer.
* @param timeout - the time waiting data.
* @return the length of data received actually.
* @param mux_id - the identifier of this TCP(available value: 0 - 4).
* @param buffer - the buffer for storing data.
* @param buffer_size - the length of the buffer.
* @param timeout - the time waiting data.
* @return the length of data received actually.
*/
uint32_t recv(uint8_t 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.
* 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.
*
* 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.
*
* @param coming_mux_id - the identifier of TCP or UDP.
* @param buffer - the buffer for storing data.
* @param buffer_size - the length of the buffer.
* @param timeout - the time waiting data.
* @return the length of data received actually.
* @param coming_mux_id - the identifier of TCP or UDP.
* @param buffer - the buffer for storing data.
* @param buffer_size - the length of the buffer.
* @param timeout - the time waiting data.
* @return the length of data received actually.
*/
uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000);

private:

/*
/*
* Empty the buffer or UART RX.
*/
void rx_empty(void);
/*
* Recvive data from uart. Return all received data if target found or timeout.

/*
* Recvive data from uart. Return all received data if target found or timeout.
*/
String recvString(String target, uint32_t timeout = 1000);
/*
* Recvive data from uart. Return all received data if one of target1 and target2 found or timeout.

/*
* Recvive data from uart. Return all received data if one of target1 and target2 found or timeout.
*/
String recvString(String target1, String target2, uint32_t timeout = 1000);
/*
* Recvive data from uart. Return all received data if one of target1, target2 and target3 found or timeout.

/*
* Recvive data from uart. Return all received data if one of target1, target2 and target3 found or timeout.
*/
String recvString(String target1, String target2, String target3, uint32_t timeout = 1000);
/*

/*
* Recvive data from uart and search first target. Return true if target found, false for timeout.
*/
bool recvFind(String target, uint32_t timeout = 1000);
/*
* Recvive data from uart and search first target and cut out the substring between begin and end(excluding begin and end self).

/*
* Recvive data from uart and search first target and cut out the substring between begin and end(excluding begin and end self).
* Return true if target found, false for timeout.
*/
bool recvFindAndFilter(String target, String begin, String end, String &data, uint32_t timeout = 1000);

/*
* Receive a package from uart.
* Receive a package from uart.
*
* @param buffer - the buffer storing data.
* @param buffer - the buffer storing data.
* @param buffer_size - guess what!
* @param data_len - the length of data actually received(maybe more than buffer_size, the remained data will be abandoned).
* @param timeout - the duration waitting data comming.
* @param coming_mux_id - in single connection mode, should be NULL and not NULL in multiple.
* @param coming_mux_id - in single connection mode, should be NULL and not NULL in multiple.
*/
uint32_t recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_len, uint32_t timeout, uint8_t *coming_mux_id);


bool eAT(void);
bool eATRST(void);
bool eATGMR(String &version);

bool qATCWMODE(uint8_t *mode);
bool sATCWMODE(uint8_t mode);
bool sATCWJAP(String ssid, String pwd);
@@ -451,7 +480,9 @@ class ESP8266 {
bool eATCWQAP(void);
bool sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn);
bool eATCWLIF(String &list);


bool sATCIPSTACUR (String ip, String gateway, String mask);

bool eATCIPSTATUS(String &list);
bool sATCIPSTARTSingle(String type, String addr, uint32_t port);
bool sATCIPSTARTMultiple(uint8_t mux_id, String type, String addr, uint32_t port);
@@ -463,12 +494,13 @@ class ESP8266 {
bool sATCIPMUX(uint8_t mode);
bool sATCIPSERVER(uint8_t mode, uint32_t port = 333);
bool sATCIPSTO(uint32_t timeout);

bool sATCMDNS(bool enable, String hostname, String servername, uint32_t port);

/*
* +IPD,len:data
* +IPD,id,len:data
*/

#ifdef ESP8266_USE_SOFTWARE_SERIAL
SoftwareSerial *m_puart; /* The UART to communicate with ESP8266 */
#else
@@ -477,4 +509,3 @@ class ESP8266 {
};

#endif /* #ifndef __ESP8266_H__ */