API
For Arduino developers
|
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... | |
Provide an easy-to-use way to manipulate ESP8266.
bool ESP8266::createTCP | ( | String | addr, |
uint32_t | port | ||
) |
Create TCP connection in single mode.
addr | - the IP or domain name of the target host. |
port | - the port number of the target host. |
true | - success. |
false | - failure. |
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.
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. |
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.
true | - success. |
false | - failure. |
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.
true | - success. |
false | - failure. |
Definition at line 181 of file ESP8266.cpp.
String ESP8266::getAPList | ( | void | ) |
Search available AP list and return it.
Definition at line 138 of file ESP8266.cpp.
String ESP8266::getIPStatus | ( | void | ) |
Get the current status of connection(UDP and TCP).
Definition at line 167 of file ESP8266.cpp.
String ESP8266::getJoinedDeviceIP | ( | void | ) |
Get the IP list of devices connected to SoftAP.
Definition at line 160 of file ESP8266.cpp.
String ESP8266::getLocalIP | ( | void | ) |
Get the IP address of ESP8266.
Definition at line 174 of file ESP8266.cpp.
String ESP8266::getVersion | ( | void | ) |
Get the version of AT Command Set.
Definition at line 80 of file ESP8266.cpp.
bool ESP8266::joinAP | ( | String | ssid, |
String | pwd | ||
) |
Join in AP.
ssid | - SSID of AP to join in. |
pwd | - Password of AP to join in. |
true | - success. |
false | - failure. |
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".
true | - alive. |
false | - dead. |
Definition at line 58 of file ESP8266.cpp.
bool ESP8266::leaveAP | ( | void | ) |
Leave AP joined before.
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.
buffer | - the buffer for storing data. |
buffer_size | - the length of the buffer. |
timeout | - the time waiting data. |
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.
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. |
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.
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. |
Definition at line 287 of file ESP8266.cpp.
bool ESP8266::registerUDP | ( | String | addr, |
uint32_t | port | ||
) |
Register UDP port number in single mode.
addr | - the IP or domain name of the target host. |
port | - the port number of the target host. |
true | - success. |
false | - failure. |
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.
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. |
true | - success. |
false | - failure. |
Definition at line 221 of file ESP8266.cpp.
bool ESP8266::releaseTCP | ( | void | ) |
Release TCP connection in single mode.
true | - success. |
false | - failure. |
Definition at line 196 of file ESP8266.cpp.
bool ESP8266::releaseTCP | ( | uint8_t | mux_id | ) |
Release TCP connection in multiple mode.
mux_id | - the identifier of this TCP(available value: 0 - 4). |
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.
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.
buffer | - the buffer of data to send. |
len | - the length of data to send. |
true | - success. |
false | - failure. |
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.
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. |
true | - success. |
false | - failure. |
Definition at line 266 of file ESP8266.cpp.
bool ESP8266::setOprToSoftAP | ( | void | ) |
Set operation mode to softap.
true | - success. |
false | - failure. |
Definition at line 104 of file ESP8266.cpp.
bool ESP8266::setOprToStation | ( | void | ) |
Set operation mode to staion.
true | - success. |
false | - failure. |
Definition at line 87 of file ESP8266.cpp.
bool ESP8266::setOprToStationSoftAP | ( | void | ) |
Set operation mode to station + softap.
true | - success. |
false | - failure. |
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.
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). |
Definition at line 155 of file ESP8266.cpp.
bool ESP8266::setTCPServerTimeout | ( | uint32_t | timeout = 180 | ) |
Set the timeout of TCP Server.
timeout | - the duration for timeout by second(0 ~ 28800, default:180). |
true | - success. |
false | - failure. |
Definition at line 231 of file ESP8266.cpp.
bool ESP8266::startServer | ( | uint32_t | port = 333 | ) |
Start Server(Only in multiple mode).
port | - the port number to listen(default: 333). |
true | - success. |
false | - failure. |
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.
port | - the port number to listen(default: 333). |
true | - success. |
false | - failure. |
Definition at line 236 of file ESP8266.cpp.
bool ESP8266::stopServer | ( | void | ) |
Stop Server(Only in multiple mode).
true | - success. |
false | - failure. |
Definition at line 256 of file ESP8266.cpp.
bool ESP8266::stopTCPServer | ( | void | ) |
Stop TCP Server(Only in multiple mode).
true | - success. |
false | - failure. |
Definition at line 244 of file ESP8266.cpp.
bool ESP8266::unregisterUDP | ( | void | ) |
Unregister UDP port number in single mode.
true | - success. |
false | - failure. |
Definition at line 206 of file ESP8266.cpp.
bool ESP8266::unregisterUDP | ( | uint8_t | mux_id | ) |
Unregister UDP port number in multiple mode.
mux_id | - the identifier of this TCP(available value: 0 - 4). |
true | - success. |
false | - failure. |
Definition at line 226 of file ESP8266.cpp.