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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
ESP8266 Class Reference
ESP8266Interface class. More...
#include <ESP8266.h>
Data Structures | |
struct | fw_at_version |
ESP8266 firmware AT version. More... | |
struct | fw_sdk_version |
ESP8266 firmware SDK version. More... | |
Public Types | |
enum | scan_mode { SCANMODE_ACTIVE = 0, SCANMODE_PASSIVE = 1 } |
Scan mode. More... | |
Public Member Functions | |
bool | at_available (void) |
Check AT command interface of ESP8266. | |
bool | echo_off (void) |
Disable echo - required for OOB processing to work. | |
struct fw_sdk_version | sdk_version (void) |
Check sdk version from which firmware is created. | |
struct fw_at_version | at_version (void) |
Check AT instruction set version from which firmware is created. | |
bool | startup (int mode) |
Startup the ESP8266. | |
bool | reset (void) |
Reset ESP8266. | |
bool | dhcp (bool enabled, int mode) |
Enable/Disable DHCP. | |
nsapi_error_t | connect (const char *ap, const char *passPhrase) |
Connect ESP8266 to AP. | |
bool | disconnect (void) |
Disconnect ESP8266 from AP. | |
const char * | ip_addr (void) |
Get the IP address of ESP8266. | |
const char * | mac_addr (void) |
Get the MAC address of ESP8266. | |
const char * | gateway () |
Get the local gateway. | |
const char * | netmask () |
Get the local network mask. | |
int | scan (WiFiAccessPoint *res, unsigned limit, scan_mode mode, unsigned t_max, unsigned t_min) |
Scan for available networks. | |
bool | dns_lookup (const char *name, char *ip) |
Perform a dns query. | |
nsapi_error_t | open_udp (int id, const char *addr, int port, int local_port=0) |
Open a socketed connection. | |
nsapi_error_t | open_tcp (int id, const char *addr, int port, int keepalive=0) |
Open a socketed connection. | |
nsapi_error_t | send (int id, const void *data, uint32_t amount) |
Sends data to an open socket. | |
int32_t | recv_udp (int id, void *data, uint32_t amount, uint32_t timeout=ESP8266_RECV_TIMEOUT) |
Receives datagram from an open UDP socket. | |
int32_t | recv_tcp (int id, void *data, uint32_t amount, uint32_t timeout=ESP8266_RECV_TIMEOUT) |
Receives stream data from an open TCP socket. | |
bool | close (int id) |
Closes a socket. | |
void | set_timeout (uint32_t timeout_ms=ESP8266_MISC_TIMEOUT) |
Allows timeout to be changed between commands. | |
bool | readable () |
Checks if data is available. | |
bool | writeable () |
Checks if data can be written. | |
void | sigio (mbed::Callback< void()> func) |
Attach a function to call whenever sigio happens in the serial. | |
template<typename T , typename M > | |
void | sigio (T *obj, M method) |
Attach a function to call whenever sigio happens in the serial. | |
void | attach (mbed::Callback< void()> status_cb) |
Attach a function to call whenever network state has changed. | |
int8_t | default_wifi_mode () |
Read default Wifi mode from flash. | |
bool | set_default_wifi_mode (const int8_t mode) |
Default Wifi mode written to flash only if changes. | |
bool | set_country_code_policy (bool track_ap, const char *country_code, int channel_start, int channels) |
nsapi_connection_status_t | connection_status () const |
Get the connection status. | |
bool | start_uart_hw_flow_ctrl () |
Start board's and ESP8266's UART flow control. | |
bool | stop_uart_hw_flow_ctrl () |
Stop board's and ESP8266's UART flow control. | |
void | bg_process_oob (uint32_t timeout, bool all) |
For executing OOB processing on background. | |
void | flush () |
Flush the serial port input buffers. | |
int | uart_enable_input (bool lock) |
Enables or disables uart input and deep sleep. |
Detailed Description
ESP8266Interface class.
This is an interface to a ESP8266 radio.
Definition at line 67 of file ESP8266.h.
Member Enumeration Documentation
enum scan_mode |
Member Function Documentation
bool at_available | ( | void | ) |
Check AT command interface of ESP8266.
- Returns:
- true if ready to respond on AT commands
Definition at line 106 of file ESP8266.cpp.
struct ESP8266::fw_at_version at_version | ( | void | ) | [read] |
Check AT instruction set version from which firmware is created.
- Returns:
- fw_at_version which tells major, minor and patch version
Definition at line 155 of file ESP8266.cpp.
void attach | ( | mbed::Callback< void()> | status_cb ) |
Attach a function to call whenever network state has changed.
- Parameters:
-
func A pointer to a void function, or 0 to set as none
void bg_process_oob | ( | uint32_t | timeout, |
bool | all | ||
) |
For executing OOB processing on background.
- Parameters:
-
timeout AT parser receive timeout if TRUE, process all OOBs instead of only one
Definition at line 756 of file ESP8266.cpp.
bool close | ( | int | id ) |
Closes a socket.
- Parameters:
-
id id of socket to close, valid only 0-4
- Returns:
- true only if socket is closed successfully
Definition at line 956 of file ESP8266.cpp.
nsapi_error_t connect | ( | const char * | ap, |
const char * | passPhrase | ||
) |
Connect ESP8266 to AP.
- Parameters:
-
ap the name of the AP passPhrase the password of AP
- Returns:
- NSAPI_ERROR_OK in success, negative error code in failure
Definition at line 329 of file ESP8266.cpp.
nsapi_connection_status_t connection_status | ( | ) | const |
Get the connection status.
- Returns:
- The connection status according to ConnectionStatusType
Definition at line 1261 of file ESP8266.cpp.
int8_t default_wifi_mode | ( | ) |
Read default Wifi mode from flash.
return Station, SoftAP or SoftAP+Station - 0 on failure
Definition at line 1228 of file ESP8266.cpp.
bool dhcp | ( | bool | enabled, |
int | mode | ||
) |
Enable/Disable DHCP.
- Parameters:
-
enabled DHCP enabled when true mode mode of DHCP 0-softAP, 1-station, 2-both
- Returns:
- true only if ESP8266 enables/disables DHCP successfully
Definition at line 297 of file ESP8266.cpp.
bool disconnect | ( | void | ) |
Disconnect ESP8266 from AP.
- Returns:
- true only if ESP8266 is disconnected successfully
Definition at line 359 of file ESP8266.cpp.
bool dns_lookup | ( | const char * | name, |
char * | ip | ||
) |
Perform a dns query.
- Parameters:
-
name Hostname to resolve ip Buffer to store IP address
- Returns:
- 0 true on success, false on failure
Definition at line 606 of file ESP8266.cpp.
bool echo_off | ( | void | ) |
Disable echo - required for OOB processing to work.
- Returns:
- true if echo was successfully disabled
Definition at line 125 of file ESP8266.cpp.
void flush | ( | ) |
Flush the serial port input buffers.
If you do HW reset for ESP module, you should flush the input buffers from existing responses from the device.
Definition at line 1244 of file ESP8266.cpp.
const char * gateway | ( | ) |
Get the local gateway.
- Returns:
- Null-terminated representation of the local gateway or null if no network mask has been recieved
Definition at line 399 of file ESP8266.cpp.
const char * ip_addr | ( | void | ) |
Get the IP address of ESP8266.
- Returns:
- null-teriminated IP address or null if no IP address is assigned
Definition at line 369 of file ESP8266.cpp.
const char * mac_addr | ( | void | ) |
Get the MAC address of ESP8266.
- Returns:
- null-terminated MAC address or null if no MAC address is assigned
Definition at line 385 of file ESP8266.cpp.
const char * netmask | ( | ) |
Get the local network mask.
- Returns:
- Null-terminated representation of the local network mask or null if no network mask has been recieved
Definition at line 413 of file ESP8266.cpp.
nsapi_error_t open_tcp | ( | int | id, |
const char * | addr, | ||
int | port, | ||
int | keepalive = 0 |
||
) |
Open a socketed connection.
- Parameters:
-
type the type of socket to open "UDP" or "TCP" id id to give the new socket, valid 0-4 port port to open connection with addr the IP address of the destination port the port on the destination tcp_keepalive TCP connection's keep alive time, zero means disabled
- Returns:
- NSAPI_ERROR_OK in success, negative error code in failure
Definition at line 555 of file ESP8266.cpp.
nsapi_error_t open_udp | ( | int | id, |
const char * | addr, | ||
int | port, | ||
int | local_port = 0 |
||
) |
Open a socketed connection.
- Parameters:
-
type the type of socket to open "UDP" or "TCP" id id to give the new socket, valid 0-4 port port to open connection with addr the IP address of the destination port the port on the destination local_port UDP socket's local port, zero means any
- Returns:
- NSAPI_ERROR_OK in success, negative error code in failure
Definition at line 504 of file ESP8266.cpp.
bool readable | ( | ) |
Checks if data is available.
Definition at line 989 of file ESP8266.cpp.
int32_t recv_tcp | ( | int | id, |
void * | data, | ||
uint32_t | amount, | ||
uint32_t | timeout = ESP8266_RECV_TIMEOUT |
||
) |
Receives stream data from an open TCP socket.
- Parameters:
-
id id to receive from data placeholder for returned information amount number of bytes to be received
- Returns:
- the number of bytes received
Definition at line 826 of file ESP8266.cpp.
int32_t recv_udp | ( | int | id, |
void * | data, | ||
uint32_t | amount, | ||
uint32_t | timeout = ESP8266_RECV_TIMEOUT |
||
) |
Receives datagram from an open UDP socket.
- Parameters:
-
id id to receive from data placeholder for returned information amount number of bytes to be received
- Returns:
- the number of bytes received
Definition at line 884 of file ESP8266.cpp.
bool reset | ( | void | ) |
Reset ESP8266.
- Returns:
- true only if ESP8266 resets successfully
Definition at line 258 of file ESP8266.cpp.
int scan | ( | WiFiAccessPoint * | res, |
unsigned | limit, | ||
scan_mode | mode, | ||
unsigned | t_max, | ||
unsigned | t_min | ||
) |
Scan for available networks.
- Parameters:
-
ap Pointer to allocated array to store discovered AP limit Size of allocated res array, or 0 to only count available AP t_max Maximum scan time per channel t_min Minimum scan time per channel in active mode, can be omitted in passive mode
- Returns:
- Number of entries in res, or if count was 0 number of available networks, negative on error see nsapi_error
Definition at line 467 of file ESP8266.cpp.
struct ESP8266::fw_sdk_version sdk_version | ( | void | ) | [read] |
Check sdk version from which firmware is created.
- Returns:
- fw_sdk_version which tells major, minor and patch version
Definition at line 135 of file ESP8266.cpp.
nsapi_error_t send | ( | int | id, |
const void * | data, | ||
uint32_t | amount | ||
) |
Sends data to an open socket.
- Parameters:
-
id id of socket to send to data data to be sent amount amount of data to be sent - max 1024
- Returns:
- NSAPI_ERROR_OK in success, negative error code in failure
Definition at line 615 of file ESP8266.cpp.
bool set_country_code_policy | ( | bool | track_ap, |
const char * | country_code, | ||
int | channel_start, | ||
int | channels | ||
) |
- Parameters:
-
track_ap if TRUE, sets the county code to be the same as the AP's that ESP is connected to, if FALSE the code will not change country_code ISO 3166-1 Alpha-2 coded country code channel_start the channel number to start at channels number of channels
Definition at line 1266 of file ESP8266.cpp.
bool set_default_wifi_mode | ( | const int8_t | mode ) |
Default Wifi mode written to flash only if changes.
Definition at line 1251 of file ESP8266.cpp.
void set_timeout | ( | uint32_t | timeout_ms = ESP8266_MISC_TIMEOUT ) |
Allows timeout to be changed between commands.
- Parameters:
-
timeout_ms timeout of the connection
Definition at line 984 of file ESP8266.cpp.
void sigio | ( | T * | obj, |
M | method | ||
) |
void sigio | ( | mbed::Callback< void()> | func ) |
Attach a function to call whenever sigio happens in the serial.
- Parameters:
-
func A pointer to a void function, or 0 to set as none
bool start_uart_hw_flow_ctrl | ( | void | ) |
Start board's and ESP8266's UART flow control.
- Returns:
- true if started
Definition at line 194 of file ESP8266.cpp.
bool startup | ( | int | mode ) |
Startup the ESP8266.
- Parameters:
-
mode mode of WIFI 1-client, 2-host, 3-both
- Returns:
- true only if ESP8266 was setup correctly
Definition at line 239 of file ESP8266.cpp.
bool stop_uart_hw_flow_ctrl | ( | void | ) |
Stop board's and ESP8266's UART flow control.
- Returns:
- true if started
Definition at line 176 of file ESP8266.cpp.
int uart_enable_input | ( | bool | lock ) |
Enables or disables uart input and deep sleep.
- Parameters:
-
lock if TRUE, uart input is enabled and deep sleep is locked if FALSE, uart input is disabled and deep sleep is unlocked
Definition at line 1294 of file ESP8266.cpp.
bool writeable | ( | ) |
Checks if data can be written.
Definition at line 994 of file ESP8266.cpp.
Generated on Tue Jul 12 2022 13:55:30 by
