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
ESP8266Interface class. More...
#include <ESP8266.h>
Public Member Functions | |
| int | get_firmware_version (void) |
| Check firmware version of ESP8266. | |
| 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 * | getIPAddress (void) |
| Get the IP address of ESP8266. | |
| const char * | getMACAddress (void) |
| Get the MAC address of ESP8266. | |
| const char * | getGateway () |
| Get the local gateway. | |
| const char * | getNetmask () |
| Get the local network mask. | |
| int | scan (WiFiAccessPoint *res, unsigned limit) |
| 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. | |
| bool | 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 | setTimeout (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 (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(nsapi_event_t, intptr_t)> status_cb) |
| Attach a function to call whenever network state has changed. | |
| int8_t | get_default_wifi_mode () |
| Read default Wifi mode from flash. | |
| bool | set_default_wifi_mode (const int8_t mode) |
| Write default Wifi mode to flash. | |
| nsapi_connection_status_t | get_connection_status () const |
| Get the connection status. | |
Detailed Description
ESP8266Interface class.
This is an interface to a ESP8266 radio.
Definition at line 41 of file ESP8266.h.
Member Function Documentation
| void attach | ( | mbed::Callback< void(nsapi_event_t, intptr_t)> | 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
Definition at line 558 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 510 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 only if ESP8266 is connected successfully
Definition at line 127 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 112 of file ESP8266.cpp.
| bool disconnect | ( | void | ) |
Disconnect ESP8266 from AP.
- Returns:
- true only if ESP8266 is disconnected successfully
Definition at line 160 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 346 of file ESP8266.cpp.
| nsapi_connection_status_t get_connection_status | ( | ) | const |
Get the connection status.
- Returns:
- The connection status according to ConnectionStatusType
Definition at line 667 of file ESP8266.cpp.
| int8_t get_default_wifi_mode | ( | ) |
Read default Wifi mode from flash.
return Station, SoftAP or SoftAP+Station - 0 on failure
Definition at line 641 of file ESP8266.cpp.
| int get_firmware_version | ( | void | ) |
Check firmware version of ESP8266.
- Returns:
- integer firmware version or -1 if firmware query command gives outdated response
Definition at line 55 of file ESP8266.cpp.
| const char * getGateway | ( | ) |
Get the local gateway.
- Returns:
- Null-terminated representation of the local gateway or null if no network mask has been recieved
Definition at line 199 of file ESP8266.cpp.
| const char * getIPAddress | ( | void | ) |
Get the IP address of ESP8266.
- Returns:
- null-teriminated IP address or null if no IP address is assigned
Definition at line 169 of file ESP8266.cpp.
| const char * getMACAddress | ( | void | ) |
Get the MAC address of ESP8266.
- Returns:
- null-terminated MAC address or null if no MAC address is assigned
Definition at line 185 of file ESP8266.cpp.
| const char * getNetmask | ( | ) |
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 213 of file ESP8266.cpp.
| bool 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:
- true only if socket opened successfully
Definition at line 317 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:
- true only if socket opened successfully
Definition at line 286 of file ESP8266.cpp.
| bool readable | ( | ) |
Checks if data is available.
Definition at line 543 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 406 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 454 of file ESP8266.cpp.
| bool reset | ( | void | ) |
Reset ESP8266.
- Returns:
- true only if ESP8266 resets successfully
Definition at line 92 of file ESP8266.cpp.
| int scan | ( | WiFiAccessPoint * | res, |
| unsigned | limit | ||
| ) |
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
- Returns:
- Number of entries in res, or if count was 0 number of available networks, negative on error see nsapi_error
Definition at line 257 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 355 of file ESP8266.cpp.
| bool set_default_wifi_mode | ( | const int8_t | mode ) |
Write default Wifi mode to flash.
Definition at line 657 of file ESP8266.cpp.
| void setTimeout | ( | uint32_t | timeout_ms = ESP8266_MISC_TIMEOUT ) |
Allows timeout to be changed between commands.
- Parameters:
-
timeout_ms timeout of the connection
Definition at line 538 of file ESP8266.cpp.
| void sigio | ( | T * | obj, |
| M | method | ||
| ) |
| void sigio | ( | 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
Definition at line 553 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 73 of file ESP8266.cpp.
| bool writeable | ( | ) |
Checks if data can be written.
Definition at line 548 of file ESP8266.cpp.
Generated on Tue Aug 9 2022 00:37:33 by
1.7.2