Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ESP8266 Class Reference
Provide methods to manipulate ESP8266 for internet access via WiFi. More...
#include <ESP8266.h>
Public Member Functions | |
| ESP8266 (PinName tx, PinName rx, int baud_rate=9600) | |
| Constructor. | |
| bool | setStationMode (String ssid, String pwd) |
| Set as station mode and join in ssid with pwd. | |
| bool | setSoftAPMode (String sap_ssid, String sap_pwd, int chl=7, ESP8266Encrypstion ecn=ESP8266_ECN_WAP_WAP2_PSK) |
| Set as softap mode and start softap. | |
| bool | setStationSoftAPMode (String ssid, String pwd, String sap_ssid, String sap_pwd, int chl=7, ESP8266Encrypstion ecn=ESP8266_ECN_WAP_WAP2_PSK) |
| Set as softap + station mode and start softap and join in ssid with pwd. | |
| bool | ipConfig (ESP8266CommType type, String addr, int port, ESP8266Mux mux=ESP8266_MUX_SINGLE, int id=0) |
| Start a TCP connection to server or init UDP communication. | |
| bool | confMux (ESP8266Mux mux) |
| Set the connection mode(sigle or multiple) | |
| bool | confServer (int mode, int port) |
| Start or stop the TCP server. | |
| bool | send (String str) |
| Send data in sigle connection mode(mux = 0). | |
| bool | send (int id, String str) |
| Send data in multiple connection mode(mux = 1). | |
| int | recvData (char *buf) |
| Start to receive data from network. | |
| int | getMuxID (void) |
| Get the current id of data received via member method:recvData in multiple connection mode. | |
| bool | reset (void) |
| Reset the module. | |
| String | showMode (void) |
| Get current work mode. | |
| String | showAP (void) |
| Get the list of Access Points available. | |
| String | showJAP (void) |
| Get the SSID of AP joined already. | |
| bool | quitAP (void) |
| Quit the AP joined before. | |
| String | showSAP (void) |
| Get SoftAP Parameters. | |
| String | showStatus (void) |
| Get the status of connection. | |
| String | showMux (void) |
| Get the connection mode(sigle or multiple) | |
| String | showIP (void) |
| Show the current ip address. | |
| bool | newMux (ESP8266CommType type, String addr, int port) |
| Create new tcp or udp connection in sigle connection mode. | |
| bool | newMux (int id, ESP8266CommType type, String addr, int port) |
| Create new tcp or udp connection in multiple connection mode)(id:0-4). | |
| void | closeMux (void) |
| Close tcp or udp in sigle connection mode. | |
| void | closeMux (int id) |
| Close tcp or udp in multiple connection mode. | |
Detailed Description
Provide methods to manipulate ESP8266 for internet access via WiFi.
Definition at line 55 of file ESP8266.h.
Constructor & Destructor Documentation
| ESP8266 | ( | PinName | tx, |
| PinName | rx, | ||
| int | baud_rate = 9600 |
||
| ) |
Constructor.
Need an serial port for communication between MCU and ESP8266.
- Parameters:
-
tx - the TX of serial port. rx - the RX of serial port. baud_rate - the baud rate of communication(default 9600).
Definition at line 4 of file ESP8266.cpp.
Member Function Documentation
| void closeMux | ( | void | ) |
Close tcp or udp in sigle connection mode.
Definition at line 632 of file ESP8266.cpp.
| void closeMux | ( | int | id ) |
Close tcp or udp in multiple connection mode.
- Parameters:
-
id - the id number.
Definition at line 652 of file ESP8266.cpp.
| bool confMux | ( | ESP8266Mux | mux ) |
Set the connection mode(sigle or multiple)
- Parameters:
-
mux - single or multiple.
- Returns:
- true for success, false for failure.
Definition at line 464 of file ESP8266.cpp.
| bool confServer | ( | int | mode, |
| int | port | ||
| ) |
Start or stop the TCP server.
- Parameters:
-
mode - 1 to start, 0 to stop (restart needed). port - the port to listen.
- Returns:
- true for success, false for failure.
Definition at line 709 of file ESP8266.cpp.
| int getMuxID | ( | void | ) |
Get the current id of data received via member method:recvData in multiple connection mode.
- Returns:
- the id of connection which data received from.
Definition at line 10 of file ESP8266.cpp.
| bool ipConfig | ( | ESP8266CommType | type, |
| String | addr, | ||
| int | port, | ||
| ESP8266Mux | mux = ESP8266_MUX_SINGLE, |
||
| int | id = 0 |
||
| ) |
Start a TCP connection to server or init UDP communication.
- Parameters:
-
type - TCP or UDP. addr - ip address or domain name of server to connect. port - the port number of server to connect. mux - single or mulitple connection mode(default: ESP8266_MUX_SINGLE). id - id number when mux is multiple(default: 0).
- Returns:
- true for success, false for failure.
Definition at line 71 of file ESP8266.cpp.
| bool newMux | ( | ESP8266CommType | type, |
| String | addr, | ||
| int | port | ||
| ) |
Create new tcp or udp connection in sigle connection mode.
- Parameters:
-
type - UDP or TCP. addr - the ip or domain name of server. port - the port number.
Definition at line 480 of file ESP8266.cpp.
| bool newMux | ( | int | id, |
| ESP8266CommType | type, | ||
| String | addr, | ||
| int | port | ||
| ) |
Create new tcp or udp connection in multiple connection mode)(id:0-4).
- Parameters:
-
id - the id number. type - UDP or TCP. addr - the ip or domain name of server. port - the port number.
Definition at line 513 of file ESP8266.cpp.
| bool quitAP | ( | void | ) |
Quit the AP joined before.
- Returns:
- true for success, false for failure.
Definition at line 331 of file ESP8266.cpp.
| int recvData | ( | char * | buf ) |
Start to receive data from network.
- Parameters:
-
buf - buffer for storing data from network.
- Returns:
- the size of data received.
Definition at line 89 of file ESP8266.cpp.
| bool reset | ( | void | ) |
Reset the module.
- Returns:
- true for success, false for failure.
Definition at line 14 of file ESP8266.cpp.
| bool send | ( | int | id, |
| String | str | ||
| ) |
Send data in multiple connection mode(mux = 1).
- Parameters:
-
id - id number. str - string to send by id connection.
- Returns:
- true for success, false for failure.
Definition at line 589 of file ESP8266.cpp.
| bool send | ( | String | str ) |
Send data in sigle connection mode(mux = 0).
- Parameters:
-
str - string to send.
- Returns:
- true for success, false for failure.
Definition at line 549 of file ESP8266.cpp.
| bool setSoftAPMode | ( | String | sap_ssid, |
| String | sap_pwd, | ||
| int | chl = 7, |
||
| ESP8266Encrypstion | ecn = ESP8266_ECN_WAP_WAP2_PSK |
||
| ) |
Set as softap mode and start softap.
- Parameters:
-
sap_ssid - SSID of its self softap. sap_pwd - PASSWORD of its self softap. chl - the channel can be 1, 2, 3, ..., 13(default: 7). enc - the method of encrypstion(default: ESP8266_ECN_WAP_WAP2_PSK).
- Returns:
- true if success, false for failure.
Definition at line 48 of file ESP8266.cpp.
| bool setStationMode | ( | String | ssid, |
| String | pwd | ||
| ) |
Set as station mode and join in ssid with pwd.
- Parameters:
-
ssid - SSID of AP to join in. pwd - PASSWORD of AP to join in.
- Returns:
- true if success, false for failure.
Definition at line 39 of file ESP8266.cpp.
| bool setStationSoftAPMode | ( | String | ssid, |
| String | pwd, | ||
| String | sap_ssid, | ||
| String | sap_pwd, | ||
| int | chl = 7, |
||
| ESP8266Encrypstion | ecn = ESP8266_ECN_WAP_WAP2_PSK |
||
| ) |
Set as softap + station mode and start softap and join in ssid with pwd.
- Parameters:
-
ssid - SSID of AP to join in. pwd - PASSWORD of AP to join in. sap_ssid - SSID of its self softap. sap_pwd - PASSWORD of its self softap. chl - the channel can be 1, 2, 3, ..., 13(default: 7). enc - the method of encrypstion(default: ESP8266_ECN_WAP_WAP2_PSK).
- Returns:
- true if success, false for failure.
Definition at line 57 of file ESP8266.cpp.
| String showAP | ( | void | ) |
Get the list of Access Points available.
- Returns:
- the list of SSID.
Definition at line 219 of file ESP8266.cpp.
| String showIP | ( | void | ) |
| String showJAP | ( | void | ) |
Get the SSID of AP joined already.
- Returns:
- the SSID joined.
Definition at line 256 of file ESP8266.cpp.
| String showMode | ( | void | ) |
| String showMux | ( | void | ) |
Get the connection mode(sigle or multiple)
- Returns:
- the mux string.
Definition at line 435 of file ESP8266.cpp.
| String showSAP | ( | void | ) |
Get SoftAP Parameters.
- Returns:
- the parameters of SoftAP.
Definition at line 347 of file ESP8266.cpp.
| String showStatus | ( | void | ) |
Generated on Tue Jul 12 2022 18:59:49 by
1.7.2