* AM2321的取温度间隔得大于2s,否则,i2c会不工作了 * SimpleTimer有个bug,会导致两次快速的读温度,现在读温度函数里加了保护 * Blynk有个bug,会导致无法把数据传到服务器 * 现在可以正常工作了

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

ESP8266 Class Reference

ESP8266 Class Reference

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

#include <ESP8266_Lib.h>

Public Member Functions

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 deepSleep (uint32_t time)
 Start function of deep sleep.
bool setEcho (uint8_t mode)
 Switch the echo function.
bool restore (void)
 Restore factory.
bool setUart (uint32_t baudrate, uint8_t pattern)
 Set up a serial port configuration.
bool setOprToStation (uint8_t pattern1=DEFAULT_PATTERN, uint8_t pattern2=DEFAULT_PATTERN)
 Set operation mode to station.
String getWifiModeList (void)
 Get the model values list.
bool setOprToSoftAP (uint8_t pattern1=DEFAULT_PATTERN, uint8_t pattern2=DEFAULT_PATTERN)
 Set operation mode to softap.
bool setOprToStationSoftAP (uint8_t pattern1=DEFAULT_PATTERN, uint8_t pattern2=DEFAULT_PATTERN)
 Set operation mode to station + softap.
uint8_t getOprMode (uint8_t pattern1=DEFAULT_PATTERN)
 Get the operation mode.
String getAPList (void)
 Search available AP list and return it.
String getNowConecAp (uint8_t pattern=DEFAULT_PATTERN)
 Search and returns the current connect AP.
bool joinAP (String ssid, String pwd, uint8_t pattern=DEFAULT_PATTERN)
 Join in AP.
bool leaveAP (void)
 Leave AP joined before.
bool setSoftAPParam (String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4, uint8_t pattern=DEFAULT_PATTERN)
 Set SoftAP parameters.
String getSoftAPParam (uint8_t pattern=DEFAULT_PATTERN)
 get SoftAP parameters.
String getJoinedDeviceIP (void)
 Get the IP list of devices connected to SoftAP.
String getDHCP (uint8_t pattern=DEFAULT_PATTERN)
 Get the current state of DHCP.
bool setDHCP (uint8_t mode, uint8_t en, uint8_t pattern=DEFAULT_PATTERN)
 Set the state of DHCP.
bool setAutoConnect (uint8_t en)
 make boot automatically connected.
String getStationMac (uint8_t pattern=DEFAULT_PATTERN)
 Get the station's MAC address.
bool setStationMac (String mac, uint8_t pattern=DEFAULT_PATTERN)
 Set the station's MAC address.
String getStationIp (uint8_t pattern=DEFAULT_PATTERN)
 Get the station's IP.
bool setStationIp (String ip, String gateway, String netmask, uint8_t pattern=DEFAULT_PATTERN)
 Set the station's IP.
String getAPIp (uint8_t pattern=DEFAULT_PATTERN)
 Get the AP's IP.
bool setAPIp (String ip, uint8_t pattern=DEFAULT_PATTERN)
 Set the AP IP.
bool startSmartConfig (uint8_t type)
 start smartconfig.
bool stopSmartConfig (void)
 stop smartconfig.
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 startTCPServer (uint32_t port=333)
 Start TCP Server(Only in multiple mode).
bool stopTCPServer (void)
 Stop TCP Server(Only in multiple mode).
bool setCIPMODE (uint8_t mode)
 Set the module transfer mode.
bool startServer (uint32_t port=333)
 Start Server(Only in multiple mode).
bool stopServer (void)
 Stop Server(Only in multiple mode).
bool saveTransLink (uint8_t mode, String ip, uint32_t port)
 Save the passthrough links.
bool setPing (String ip)
 PING COMMAND.
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.
bool sendFromFlash (const uint8_t *buffer, uint32_t len)
 Send data based on TCP or UDP builded already in single mode.
bool sendFromFlash (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.

Detailed Description

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

Definition at line 60 of file ESP8266_Lib.h.


Member Function Documentation

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

Definition at line 327 of file ESP8266.cpp.

bool 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 351 of file ESP8266.cpp.

bool deepSleep ( uint32_t  time )

Start function of deep sleep.

Parameters:
time- the sleep time.
Return values:
true- success.
false- failure.
Note:
the feature requires hardware support.

Definition at line 95 of file ESP8266.cpp.

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

Definition at line 321 of file ESP8266.cpp.

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

Definition at line 315 of file ESP8266.cpp.

String getAPIp ( uint8_t  pattern = DEFAULT_PATTERN )

Get the AP's IP.

Parameters:
pattern-1 send "AT+CIPAP_DEF?" -2 send "AT+CIPAP_CUR?" -3 send "AT+CIPAP?".
Returns:
ap's ip.
Note:
This method should not be called when station mode.

Definition at line 272 of file ESP8266.cpp.

String 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 182 of file ESP8266.cpp.

String getDHCP ( uint8_t  pattern = DEFAULT_PATTERN )

Get the current state of DHCP.

Parameters:
pattern-1 send "AT+CWDHCP_DEF?" -2 send "AT+CWDHCP_CUR?" -3 send "AT+CWDHCP?".
Returns:
the state of DHCP.

Definition at line 224 of file ESP8266.cpp.

String getIPStatus ( void   )

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

Returns:
the status.

Definition at line 299 of file ESP8266.cpp.

String 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 216 of file ESP8266.cpp.

String getLocalIP ( void   )

Get the IP address of ESP8266.

Returns:
the IP list.

Definition at line 307 of file ESP8266.cpp.

String getNowConecAp ( uint8_t  pattern = DEFAULT_PATTERN )

Search and returns the current connect AP.

Parameters:
pattern-1, send "AT+CWJAP_DEF?",-2,send "AT+CWJAP_CUR?",-3,send "AT+CWJAP?".
Returns:
the ssid of AP connected now.

Definition at line 174 of file ESP8266.cpp.

uint8_t getOprMode ( uint8_t  pattern1 = DEFAULT_PATTERN )

Get the operation mode.

Parameters:
pattern1-1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
Return values:
0- failure.
1- mode Station.
2- mode AP.
3- mode AP + station.

Definition at line 163 of file ESP8266.cpp.

String getSoftAPParam ( uint8_t  pattern = DEFAULT_PATTERN )

get SoftAP parameters.

Parameters:
pattern-1 send "AT+CWSAP_DEF?" -2 send "AT+CWSAP_CUR?" -3 send "AT+CWSAP?".
Note:
This method should not be called when station mode.

Definition at line 202 of file ESP8266.cpp.

String getStationIp ( uint8_t  pattern = DEFAULT_PATTERN )

Get the station's IP.

Parameters:
pattern-1 send "AT+CIPSTA_DEF?" -2 send "AT+CIPSTA_CUR?" -3 send "AT+CIPSTA?".
Returns:
the station's IP.
Note:
This method should not be called when ap mode.

Definition at line 258 of file ESP8266.cpp.

String getStationMac ( uint8_t  pattern = DEFAULT_PATTERN )

Get the station's MAC address.

Parameters:
pattern-1 send "AT+CIPSTAMAC_DEF?=" -2 send "AT+CIPSTAMAC_CUR?" -3 send "AT+CIPSTAMAC?".
Returns:
mac address.
Note:
This method should not be called when ap mode.

Definition at line 244 of file ESP8266.cpp.

String getVersion ( void   )

Get the version of AT Command Set.

Returns:
the string of version.

Definition at line 69 of file ESP8266.cpp.

String getWifiModeList ( void   )

Get the model values list.

Returns:
the list of model.

Definition at line 119 of file ESP8266.cpp.

bool joinAP ( String  ssid,
String  pwd,
uint8_t  pattern = DEFAULT_PATTERN 
)

Join in AP.

Parameters:
pattern-1 send "AT+CWJAP_DEF=" -2 send "AT+CWJAP_CUR=" -3 send "AT+CWJAP=".
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.

Definition at line 190 of file ESP8266.cpp.

bool 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 41 of file ESP8266.cpp.

bool leaveAP ( void   )

Leave AP joined before.

Return values:
true- success.
false- failure.

Definition at line 196 of file ESP8266.cpp.

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

Definition at line 339 of file ESP8266.cpp.

bool 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 363 of file ESP8266.cpp.

bool 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 357 of file ESP8266.cpp.

bool releaseTCP ( void   )

Release TCP connection in single mode.

Return values:
true- success.
false- failure.

Definition at line 333 of file ESP8266.cpp.

bool restart ( void   )

Restart ESP8266 by "AT+RST".

This method will take 3 seconds or more.

Return values:
true- success.
false- failure.

Definition at line 47 of file ESP8266.cpp.

bool restore ( void   )

Restore factory.

Return values:
true- success.
false- failure.
Note:
The operation can lead to restart the machine.

Definition at line 83 of file ESP8266.cpp.

bool saveTransLink ( uint8_t  mode,
String  ip,
uint32_t  port 
)

Save the passthrough links.

Return values:
true- success.
false- failure.

Definition at line 404 of file ESP8266.cpp.

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

Definition at line 429 of file ESP8266.cpp.

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.

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 447 of file ESP8266.cpp.

bool sendFromFlash ( 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 from flash memeory.
len- the length of data to send.
Return values:
true- success.
false- failure.

Definition at line 441 of file ESP8266.cpp.

bool sendFromFlash ( 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 from flash memeory.
len- the length of data to send.
Return values:
true- success.
false- failure.

Definition at line 435 of file ESP8266.cpp.

bool setAPIp ( String  ip,
uint8_t  pattern = DEFAULT_PATTERN 
)

Set the AP IP.

Parameters:
pattern-1 send "AT+CIPAP_DEF=" -2 send "AT+CIPAP_CUR=" -3 send "AT+CIPAP=".
ip- the ip of AP.
Return values:
true- success.
false- failure.
Note:
This method should not be called when station mode.

Definition at line 280 of file ESP8266.cpp.

bool setAutoConnect ( uint8_t  en )

make boot automatically connected.

Parameters:
en-1 enable -0 disable.
Return values:
true- success.
false- failure.

Definition at line 238 of file ESP8266.cpp.

bool setCIPMODE ( uint8_t  mode )

Set the module transfer mode.

Return values:
true- success.
false- failure.

Definition at line 398 of file ESP8266.cpp.

bool setDHCP ( uint8_t  mode,
uint8_t  en,
uint8_t  pattern = DEFAULT_PATTERN 
)

Set the state of DHCP.

Parameters:
pattern-1 send "AT+CWDHCP_DEF=" -2 send "AT+CWDHCP_CUR=" -3 send "AT+CWDHCP=".
mode- set ap or set station or set ap + station.
en- 0 disable DHCP - 1 enable DHCP.
Return values:
true- success.
false- failure.

Definition at line 232 of file ESP8266.cpp.

bool setEcho ( uint8_t  mode )

Switch the echo function.

Parameters:
mode- 1 start echo -0 stop echo
Return values:
true- success.
false- failure.

Definition at line 77 of file ESP8266.cpp.

bool setOprToSoftAP ( uint8_t  pattern1 = DEFAULT_PATTERN,
uint8_t  pattern2 = DEFAULT_PATTERN 
)

Set operation mode to softap.

Parameters:
pattern1-1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
pattern2-1, send "AT+CWMODE_DEF=",-2,send "AT+CWMODE_CUR=",-3,send "AT+CWMODE=".
Return values:
true- success.
false- failure.

Definition at line 127 of file ESP8266.cpp.

bool setOprToStation ( uint8_t  pattern1 = DEFAULT_PATTERN,
uint8_t  pattern2 = DEFAULT_PATTERN 
)

Set operation mode to station.

Parameters:
pattern1-1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
pattern2-1, send "AT+CWMODE_DEF=",-2,send "AT+CWMODE_CUR=",-3,send "AT+CWMODE=".
Return values:
true- success.
false- failure.

Definition at line 101 of file ESP8266.cpp.

bool setOprToStationSoftAP ( uint8_t  pattern1 = DEFAULT_PATTERN,
uint8_t  pattern2 = DEFAULT_PATTERN 
)

Set operation mode to station + softap.

Parameters:
pattern1-1, send "AT+CWMODE_DEF?",-2,send "AT+CWMODE_CUR?",-3,send "AT+CWMODE?".
pattern2-1, send "AT+CWMODE_DEF=",-2,send "AT+CWMODE_CUR=",-3,send "AT+CWMODE=".
Return values:
true- success.
false- failure.

Definition at line 145 of file ESP8266.cpp.

bool setPing ( String  ip )

PING COMMAND.

Return values:
true- success.
false- failure.

Definition at line 410 of file ESP8266.cpp.

bool setSoftAPParam ( String  ssid,
String  pwd,
uint8_t  chl = 7,
uint8_t  ecn = 4,
uint8_t  pattern = DEFAULT_PATTERN 
)

Set SoftAP parameters.

Parameters:
pattern-1 send "AT+CWSAP_DEF=" -2 send "AT+CWSAP_CUR=" -3 send "AT+CWSAP=".
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).
Return values:
true- success.
false- failure.
Note:
This method should not be called when station mode.

Definition at line 210 of file ESP8266.cpp.

bool setStationIp ( String  ip,
String  gateway,
String  netmask,
uint8_t  pattern = DEFAULT_PATTERN 
)

Set the station's IP.

Parameters:
pattern-1 send "AT+CIPSTA_DEF=" -2 send "AT+CIPSTA_CUR=" -3 send "AT+CIPSTA=".
ip- the ip of station.
gateway-the gateway of station.
netmask-the netmask of station.
Return values:
true- success.
false- failure.
Note:
This method should not be called when ap mode.

Definition at line 266 of file ESP8266.cpp.

bool setStationMac ( String  mac,
uint8_t  pattern = DEFAULT_PATTERN 
)

Set the station's MAC address.

Parameters:
pattern-1 send "AT+CIPSTAMAC_DEF=" -2 send "AT+CIPSTAMAC_CUR=" -3 send "AT+CIPSTAMAC=".
mac- the mac address of station.
Return values:
true- success.
false- failure.

Definition at line 252 of file ESP8266.cpp.

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

Definition at line 375 of file ESP8266.cpp.

bool setUart ( uint32_t  baudrate,
uint8_t  pattern 
)

Set up a serial port configuration.

Parameters:
pattern-1 send "AT+UART=", -2 send "AT+UART_CUR=", -3 send "AT+UART_DEF=".
baudrate- the uart baudrate.
Return values:
true- success.
false- failure.
Note:
Only allows baud rate design, for the other parameters:databits- 8,stopbits -1,parity -0,flow control -0 .

Definition at line 89 of file ESP8266.cpp.

bool 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 417 of file ESP8266.cpp.

bool startSmartConfig ( uint8_t  type )

start smartconfig.

Parameters:
type-1:ESP_TOUCH -2:AirKiss.
Return values:
true- success.
false- failure.

Definition at line 286 of file ESP8266.cpp.

bool 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);

Definition at line 381 of file ESP8266.cpp.

bool stopServer ( void   )

Stop Server(Only in multiple mode).

Return values:
true- success.
false- failure.

Definition at line 423 of file ESP8266.cpp.

bool stopSmartConfig ( void   )

stop smartconfig.

Return values:
true- success.
false- failure.

Definition at line 292 of file ESP8266.cpp.

bool stopTCPServer ( void   )

Stop TCP Server(Only in multiple mode).

Return values:
true- success.
false- failure.

Definition at line 390 of file ESP8266.cpp.

bool 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 369 of file ESP8266.cpp.

bool unregisterUDP ( void   )

Unregister UDP port number in single mode.

Return values:
true- success.
false- failure.

Definition at line 345 of file ESP8266.cpp.