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.
ESP8266Interface Class Reference
ESP8266Interface class Implementation of the NetworkStack for the ESP8266. More...
#include <ESP8266Interface.h>
Inherits NetworkStack, and WiFiInterface.
Public Types | |
| typedef mbed::Callback< void(nsapi_error_t result, SocketAddress *address) | hostbyname_cb_t ) |
| Hostname translation callback (asynchronous) | |
| typedef mbed::Callback< void(nsapi_error_t result, SocketAddress *address) | hostbyname_cb_t ) |
| Hostname translation callback (for use with gethostbyname_async()). | |
Public Member Functions | |
| ESP8266Interface () | |
| ESP8266Interface default constructor Will use values defined in mbed_lib.json. | |
| ESP8266Interface (PinName tx, PinName rx, bool debug=false) | |
| ESP8266Interface lifetime. | |
| virtual int | connect () |
| Start the interface. | |
| virtual int | connect (const char *ssid, const char *pass, nsapi_security_t security=NSAPI_SECURITY_NONE, uint8_t channel=0) |
| Start the interface. | |
| virtual int | set_credentials (const char *ssid, const char *pass, nsapi_security_t security=NSAPI_SECURITY_NONE) |
| Set the WiFi network credentials. | |
| virtual int | set_channel (uint8_t channel) |
| Set the WiFi network channel - NOT SUPPORTED. | |
| virtual int | disconnect () |
| Stop the interface. | |
| virtual const char * | get_ip_address () |
| Get the internally stored IP address. | |
| virtual const char * | get_mac_address () |
| Get the internally stored MAC address. | |
| virtual const char * | get_gateway () |
| Get the local gateway. | |
| virtual const char * | get_netmask () |
| Get the local network mask. | |
| virtual int8_t | get_rssi () |
| Gets the current radio signal strength for active connection. | |
| virtual int | scan (WiFiAccessPoint *res, unsigned count) |
| Scan for available networks. | |
| virtual nsapi_error_t | setsockopt (nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen) |
| virtual nsapi_error_t | getsockopt (nsapi_socket_t handle, int level, int optname, void *optval, unsigned *optlen) |
| virtual void | attach (mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb) |
| Register callback for status reporting. | |
| virtual nsapi_connection_status_t | get_connection_status () const |
| Get the connection status. | |
| virtual nsapi_error_t | gethostbyname (const char *host, SocketAddress *address, nsapi_version_t version=NSAPI_UNSPEC) |
| Translates a hostname to an IP address with specific version. | |
| virtual nsapi_value_or_error_t | gethostbyname_async (const char *host, hostbyname_cb_t callback, nsapi_version_t version=NSAPI_UNSPEC) |
| Translates a hostname to an IP address (asynchronous) | |
| virtual nsapi_error_t | gethostbyname_async_cancel (int id) |
| Cancels asynchronous hostname translation. | |
| virtual nsapi_error_t | add_dns_server (const SocketAddress &address) |
| Add a domain name server to list of servers to query. | |
| virtual nsapi_error_t | get_dns_server (int index, SocketAddress *address) |
| Get a domain name server from a list of servers to query. | |
| virtual OnboardNetworkStack * | onboardNetworkStack () |
| Dynamic downcast to a OnboardNetworkStack. | |
| virtual nsapi_size_or_error_t | scan (WiFiAccessPoint *res, nsapi_size_t count)=0 |
| Scan for available networks. | |
| virtual WiFiInterface * | wifiInterface () |
| virtual nsapi_error_t | set_network (const char *ip_address, const char *netmask, const char *gateway) |
| Configure this network interface to use a static IP address. | |
| virtual nsapi_error_t | set_dhcp (bool dhcp) |
| Enable or disable DHCP on connecting the network. | |
| virtual nsapi_error_t | gethostbyname (const char *host, SocketAddress *address, nsapi_version_t version=NSAPI_UNSPEC) |
| Translate a hostname to an IP address with specific version. | |
| virtual nsapi_value_or_error_t | gethostbyname_async (const char *host, hostbyname_cb_t callback, nsapi_version_t version=NSAPI_UNSPEC) |
| Translate a hostname to an IP address (asynchronous). | |
| virtual nsapi_error_t | gethostbyname_async_cancel (int id) |
| Cancel asynchronous hostname translation. | |
| virtual nsapi_error_t | add_dns_server (const SocketAddress &address) |
| Add a domain name server to list of servers to query. | |
| virtual nsapi_error_t | set_blocking (bool blocking) |
| Set blocking status of connect() which by default should be blocking. | |
| virtual EthInterface * | ethInterface () |
| Return pointer to an EthInterface. | |
| virtual MeshInterface * | meshInterface () |
| Return pointer to a MeshInterface. | |
| virtual CellularBase * | cellularBase () |
| Return pointer to a CellularBase. | |
| virtual EMACInterface * | emacInterface () |
| Return pointer to an EMACInterface. | |
Static Public Member Functions | |
| static WiFiInterface * | get_default_instance () |
| Get the default Wi-Fi interface. | |
Protected Member Functions | |
| virtual int | socket_open (void **handle, nsapi_protocol_t proto) |
| Open a socket. | |
| virtual int | socket_close (void *handle) |
| Close the socket. | |
| virtual int | socket_bind (void *handle, const SocketAddress &address) |
| Bind a server socket to a specific port. | |
| virtual int | socket_listen (void *handle, int backlog) |
| Start listening for incoming connections. | |
| virtual int | socket_connect (void *handle, const SocketAddress &address) |
| Connects this TCP socket to the server. | |
| virtual int | socket_accept (void *handle, void **socket, SocketAddress *address) |
| Accept a new connection. | |
| virtual int | socket_send (void *handle, const void *data, unsigned size) |
| Send data to the remote host. | |
| virtual int | socket_recv (void *handle, void *data, unsigned size) |
| Receive data from the remote host. | |
| virtual int | socket_sendto (void *handle, const SocketAddress &address, const void *data, unsigned size) |
| Send a packet to a remote endpoint. | |
| virtual int | socket_recvfrom (void *handle, SocketAddress *address, void *buffer, unsigned size) |
| Receive a packet from a remote endpoint. | |
| virtual void | socket_attach (void *handle, void(*callback)(void *), void *data) |
| Register a callback on state change of the socket. | |
| virtual NetworkStack * | get_stack () |
| Provide access to the NetworkStack object. | |
| virtual nsapi_error_t | socket_open (nsapi_socket_t *handle, nsapi_protocol_t proto)=0 |
| Opens a socket. | |
| virtual nsapi_error_t | socket_close (nsapi_socket_t handle)=0 |
| Close the socket. | |
| virtual nsapi_error_t | socket_bind (nsapi_socket_t handle, const SocketAddress &address)=0 |
| Bind a specific address to a socket. | |
| virtual nsapi_error_t | socket_listen (nsapi_socket_t handle, int backlog)=0 |
| Listen for connections on a TCP socket. | |
| virtual nsapi_error_t | socket_connect (nsapi_socket_t handle, const SocketAddress &address)=0 |
| Connects TCP socket to a remote host. | |
| virtual nsapi_error_t | socket_accept (nsapi_socket_t server, nsapi_socket_t *handle, SocketAddress *address=0)=0 |
| Accepts a connection on a TCP socket. | |
| virtual nsapi_size_or_error_t | socket_send (nsapi_socket_t handle, const void *data, nsapi_size_t size)=0 |
| Send data over a TCP socket. | |
| virtual nsapi_size_or_error_t | socket_recv (nsapi_socket_t handle, void *data, nsapi_size_t size)=0 |
| Receive data over a TCP socket. | |
| virtual nsapi_size_or_error_t | socket_sendto (nsapi_socket_t handle, const SocketAddress &address, const void *data, nsapi_size_t size)=0 |
| Send a packet over a UDP socket. | |
| virtual nsapi_size_or_error_t | socket_recvfrom (nsapi_socket_t handle, SocketAddress *address, void *buffer, nsapi_size_t size)=0 |
| Receive a packet over a UDP socket. | |
| virtual void | socket_attach (nsapi_socket_t handle, void(*callback)(void *), void *data)=0 |
| Register a callback on state change of the socket. | |
Static Protected Member Functions | |
| static WiFiInterface * | get_target_default_instance () |
| Get the target's default Wi-Fi interface. | |
Friends | |
| class | InternetSocket |
| class | UDPSocket |
| class | TCPSocket |
| class | InternetSocket |
| class | UDPSocket |
| class | TCPSocket |
Detailed Description
ESP8266Interface class Implementation of the NetworkStack for the ESP8266.
Definition at line 29 of file ESP8266Interface.h.
Member Typedef Documentation
typedef mbed::Callback<void (nsapi_error_t result, SocketAddress *address) hostbyname_cb_t) [inherited] |
Hostname translation callback (asynchronous)
Callback will be called after DNS resolution completes or a failure occurs.
Callback should not take more than 10ms to execute, otherwise it might prevent underlying thread processing. A portable user of the callback should not make calls to network operations due to stack size limitations. The callback should not perform expensive operations such as socket recv/send calls or blocking operations.
- Parameters:
-
status NSAPI_ERROR_OK on success, negative error code on failure address On success, destination for the host SocketAddress
Definition at line 78 of file NetworkStack.h.
typedef mbed::Callback<void (nsapi_error_t result, SocketAddress *address) hostbyname_cb_t) [inherited] |
Hostname translation callback (for use with gethostbyname_async()).
Callback will be called after DNS resolution completes or a failure occurs.
- Note:
- Callback should not take more than 10ms to execute, otherwise it might prevent underlying thread processing. A portable user of the callback should not make calls to network operations due to stack size limitations. The callback should not perform expensive operations such as socket recv/send calls or blocking operations.
- Parameters:
-
result NSAPI_ERROR_OK on success, negative error code on failure. address On success, destination for the host SocketAddress.
Definition at line 178 of file NetworkInterface.h.
Constructor & Destructor Documentation
| ESP8266Interface | ( | ) |
ESP8266Interface default constructor Will use values defined in mbed_lib.json.
Definition at line 43 of file ESP8266Interface.cpp.
| ESP8266Interface | ( | PinName | tx, |
| PinName | rx, | ||
| bool | debug = false |
||
| ) |
ESP8266Interface lifetime.
- Parameters:
-
tx TX pin rx RX pin debug Enable debugging
Definition at line 60 of file ESP8266Interface.cpp.
Member Function Documentation
| nsapi_error_t add_dns_server | ( | const SocketAddress & | address ) | [virtual, inherited] |
Add a domain name server to list of servers to query.
- Parameters:
-
address Destination for the host address
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
Definition at line 93 of file NetworkStack.cpp.
| nsapi_error_t add_dns_server | ( | const SocketAddress & | address ) | [virtual, inherited] |
Add a domain name server to list of servers to query.
- Parameters:
-
address Address for the dns host.
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure.
Definition at line 73 of file NetworkInterface.cpp.
| void attach | ( | mbed::Callback< void(nsapi_event_t, intptr_t)> | status_cb ) | [virtual] |
Register callback for status reporting.
The specified status callback function will be called on status changes on the network. The parameters on the callback are the event type and event-type dependent reason parameter.
In ESP8266 the callback will be called when processing OOB-messages via AT-parser. Do NOT call any ESP8266Interface -functions or do extensive processing in the callback.
- Parameters:
-
status_cb The callback for status changes
Reimplemented from NetworkInterface.
Definition at line 569 of file ESP8266Interface.cpp.
| virtual CellularBase* cellularBase | ( | ) | [virtual, inherited] |
Return pointer to a CellularBase.
- Returns:
- Pointer to requested interface type or NULL if this class doesn't implement the interface.
Definition at line 272 of file NetworkInterface.h.
| int connect | ( | const char * | ssid, |
| const char * | pass, | ||
| nsapi_security_t | security = NSAPI_SECURITY_NONE, |
||
| uint8_t | channel = 0 |
||
| ) | [virtual] |
Start the interface.
Attempts to connect to a WiFi network.
- Parameters:
-
ssid Name of the network to connect to pass Security passphrase to connect to the network security Type of encryption for connection (Default: NSAPI_SECURITY_NONE) channel This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED
- Returns:
- 0 on success, or error code on failure
Definition at line 76 of file ESP8266Interface.cpp.
| int connect | ( | ) | [virtual] |
Start the interface.
Attempts to connect to a WiFi network. Requires ssid and passphrase to be set. If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
- Returns:
- 0 on success, negative error code on failure
Implements NetworkInterface.
Definition at line 91 of file ESP8266Interface.cpp.
| int disconnect | ( | void | ) | [virtual] |
Stop the interface.
- Returns:
- 0 on success, negative on failure
Implements NetworkInterface.
Definition at line 181 of file ESP8266Interface.cpp.
| virtual EMACInterface* emacInterface | ( | ) | [virtual, inherited] |
Return pointer to an EMACInterface.
- Returns:
- Pointer to requested interface type or NULL if this class doesn't implement the interface.
Reimplemented in EMACInterface.
Definition at line 280 of file NetworkInterface.h.
| virtual EthInterface* ethInterface | ( | ) | [virtual, inherited] |
Return pointer to an EthInterface.
- Returns:
- Pointer to requested interface type or NULL if this class doesn't implement the interface.
Reimplemented in EthInterface.
Definition at line 248 of file NetworkInterface.h.
| nsapi_connection_status_t get_connection_status | ( | ) | const [virtual] |
Get the connection status.
- Returns:
- The connection status according to ConnectionStatusType
Reimplemented from NetworkInterface.
Definition at line 574 of file ESP8266Interface.cpp.
| MBED_WEAK WiFiInterface * get_default_instance | ( | ) | [static, inherited] |
Get the default Wi-Fi interface.
This is provided as a weak method so applications can override. Default behaviour is to get the target's default interface, if any.
- Returns:
- pointer to interface, if any.
Definition at line 581 of file ESP8266Interface.cpp.
| nsapi_error_t get_dns_server | ( | int | index, |
| SocketAddress * | address | ||
| ) | [virtual, inherited] |
Get a domain name server from a list of servers to query.
Returns a DNS server address for a index. If returns error no more DNS servers to read.
- Parameters:
-
index Index of the DNS server, starts from zero address Destination for the host address
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
Definition at line 98 of file NetworkStack.cpp.
| const char * get_gateway | ( | ) | [virtual] |
Get the local gateway.
- Returns:
- Null-terminated representation of the local gateway or null if no network mask has been recieved
Reimplemented from NetworkInterface.
Definition at line 208 of file ESP8266Interface.cpp.
| const char * get_ip_address | ( | ) | [virtual] |
Get the internally stored IP address.
- Returns:
- IP address of the interface or null if not yet connected
Reimplemented from NetworkInterface.
Definition at line 189 of file ESP8266Interface.cpp.
| const char * get_mac_address | ( | ) | [virtual] |
Get the internally stored MAC address.
- Returns:
- MAC address of the interface
Reimplemented from NetworkInterface.
Definition at line 203 of file ESP8266Interface.cpp.
| const char * get_netmask | ( | ) | [virtual] |
Get the local network mask.
- Returns:
- Null-terminated representation of the local network mask or null if no network mask has been recieved
Reimplemented from NetworkInterface.
Definition at line 213 of file ESP8266Interface.cpp.
| int8_t get_rssi | ( | ) | [virtual] |
Gets the current radio signal strength for active connection.
- Returns:
- Connection strength in dBm (negative value)
Definition at line 218 of file ESP8266Interface.cpp.
| virtual NetworkStack* get_stack | ( | void | ) | [protected, virtual] |
Provide access to the NetworkStack object.
- Returns:
- The underlying NetworkStack object
Implements NetworkInterface.
Definition at line 289 of file ESP8266Interface.h.
| MBED_WEAK WiFiInterface * get_target_default_instance | ( | ) | [static, protected, inherited] |
Get the target's default Wi-Fi interface.
This is provided as a weak method so targets can override. The default implementation returns NULL.
- Returns:
- pointer to interface, if any.
Definition at line 54 of file NetworkInterfaceDefaults.cpp.
| nsapi_error_t gethostbyname | ( | const char * | host, |
| SocketAddress * | address, | ||
| nsapi_version_t | version = NSAPI_UNSPEC |
||
| ) | [virtual, inherited] |
Translate a hostname to an IP address with specific version.
The hostname may be either a domain name or an IP address. If the hostname is an IP address, no network transactions will be performed.
If no stack-specific DNS resolution is provided, the hostname will be resolve using a UDP socket on the stack.
- Parameters:
-
host Hostname to resolve. address Pointer to a SocketAddress to store the result. version IP version of address to resolve, NSAPI_UNSPEC indicates version is chosen by the stack (defaults to NSAPI_UNSPEC).
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure.
Definition at line 58 of file NetworkInterface.cpp.
| nsapi_error_t gethostbyname | ( | const char * | host, |
| SocketAddress * | address, | ||
| nsapi_version_t | version = NSAPI_UNSPEC |
||
| ) | [virtual, inherited] |
Translates a hostname to an IP address with specific version.
The hostname may be either a domain name or an IP address. If the hostname is an IP address, no network transactions will be performed.
If no stack-specific DNS resolution is provided, the hostname will be resolve using a UDP socket on the stack.
- Parameters:
-
host Hostname to resolve address Pointer to a SocketAddress to store the result. version IP version of address to resolve, NSAPI_UNSPEC indicates version is chosen by the stack (defaults to NSAPI_UNSPEC)
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
Definition at line 29 of file NetworkStack.cpp.
| nsapi_value_or_error_t gethostbyname_async | ( | const char * | host, |
| hostbyname_cb_t | callback, | ||
| nsapi_version_t | version = NSAPI_UNSPEC |
||
| ) | [virtual, inherited] |
Translate a hostname to an IP address (asynchronous).
The hostname may be either a domain name or a dotted IP address. If the hostname is an IP address, no network transactions will be performed.
If no stack-specific DNS resolution is provided, the hostname will be resolve using a UDP socket on the stack.
Call is non-blocking. Result of the DNS operation is returned by the callback. If this function returns failure, callback will not be called. In case result is success (IP address was found from DNS cache), callback will be called before function returns.
- Parameters:
-
host Hostname to resolve. callback Callback that is called for result. version IP version of address to resolve, NSAPI_UNSPEC indicates version is chosen by the stack (defaults to NSAPI_UNSPEC).
- Returns:
- 0 on immediate success, negative error code on immediate failure or a positive unique id that represents the hostname translation operation and can be passed to cancel.
Definition at line 63 of file NetworkInterface.cpp.
| nsapi_value_or_error_t gethostbyname_async | ( | const char * | host, |
| hostbyname_cb_t | callback, | ||
| nsapi_version_t | version = NSAPI_UNSPEC |
||
| ) | [virtual, inherited] |
Translates a hostname to an IP address (asynchronous)
The hostname may be either a domain name or an IP address. If the hostname is an IP address, no network transactions will be performed.
If no stack-specific DNS resolution is provided, the hostname will be resolve using a UDP socket on the stack.
Call is non-blocking. Result of the DNS operation is returned by the callback. If this function returns failure, callback will not be called. In case result is success (IP address was found from DNS cache), callback will be called before function returns.
- Parameters:
-
host Hostname to resolve callback Callback that is called for result version IP version of address to resolve, NSAPI_UNSPEC indicates version is chosen by the stack (defaults to NSAPI_UNSPEC)
- Returns:
- 0 on immediate success, negative error code on immediate failure or a positive unique id that represents the hostname translation operation and can be passed to cancel
Definition at line 56 of file NetworkStack.cpp.
| nsapi_error_t gethostbyname_async_cancel | ( | int | id ) | [virtual, inherited] |
Cancels asynchronous hostname translation.
When translation is cancelled, callback will not be called.
- Parameters:
-
id Unique id of the hostname translation operation
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
Definition at line 88 of file NetworkStack.cpp.
| nsapi_error_t gethostbyname_async_cancel | ( | int | id ) | [virtual, inherited] |
Cancel asynchronous hostname translation.
When translation is cancelled, callback will not be called.
- Parameters:
-
id Unique id of the hostname translation operation (returned by gethostbyname_async)
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure.
Definition at line 68 of file NetworkInterface.cpp.
| nsapi_error_t getsockopt | ( | nsapi_socket_t | handle, |
| int | level, | ||
| int | optname, | ||
| void * | optval, | ||
| unsigned * | optlen | ||
| ) | [virtual] |
Definition at line 534 of file ESP8266Interface.cpp.
| virtual MeshInterface* meshInterface | ( | ) | [virtual, inherited] |
Return pointer to a MeshInterface.
- Returns:
- Pointer to requested interface type or NULL if this class doesn't implement the interface.
Reimplemented in MeshInterface.
Definition at line 264 of file NetworkInterface.h.
| virtual OnboardNetworkStack* onboardNetworkStack | ( | ) | [virtual, inherited] |
Dynamic downcast to a OnboardNetworkStack.
Definition at line 164 of file NetworkStack.h.
| int scan | ( | WiFiAccessPoint * | res, |
| unsigned | count | ||
| ) | [virtual] |
Scan for available networks.
This function will block.
- Parameters:
-
ap Pointer to allocated array to store discovered AP count Size of allocated res array, or 0 to only count available AP timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
- Returns:
- Number of entries in , or if count was 0 number of available networks, negative on error see nsapi_error
Definition at line 223 of file ESP8266Interface.cpp.
| virtual nsapi_size_or_error_t scan | ( | WiFiAccessPoint * | res, |
| nsapi_size_t | count | ||
| ) | [pure virtual, inherited] |
Scan for available networks.
This function will block. If the count is 0, function will only return count of available networks, so that user can allocated necessary memory. If the count is grater than 0 and the a res is not NULL it'll be populated with discovered networks up to value of count.
- Parameters:
-
res Pointer to allocated array to store discovered APs. count Size of allocated res array, or 0 to only count available APs.
- Returns:
- Number of entries in res, or if count was 0 number of available networks. Negative on error (
- See also:
- nsapi_types.h for nsapi_error).
| nsapi_error_t set_blocking | ( | bool | blocking ) | [virtual, inherited] |
Set blocking status of connect() which by default should be blocking.
- Parameters:
-
blocking Use true to make connect() blocking.
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure.
Reimplemented in CellularNetwork, AT_CellularNetwork, and EMACInterface.
Definition at line 87 of file NetworkInterface.cpp.
| int set_channel | ( | uint8_t | channel ) | [virtual] |
Set the WiFi network channel - NOT SUPPORTED.
This function is not supported and will return NSAPI_ERROR_UNSUPPORTED
- Parameters:
-
channel Channel on which the connection is to be made, or 0 for any (Default: 0)
- Returns:
- Not supported, returns NSAPI_ERROR_UNSUPPORTED
Definition at line 175 of file ESP8266Interface.cpp.
| int set_credentials | ( | const char * | ssid, |
| const char * | pass, | ||
| nsapi_security_t | security = NSAPI_SECURITY_NONE |
||
| ) | [virtual] |
Set the WiFi network credentials.
- Parameters:
-
ssid Name of the network to connect to pass Security passphrase to connect to the network security Type of encryption for connection (defaults to NSAPI_SECURITY_NONE)
- Returns:
- 0 on success, or error code on failure
Definition at line 136 of file ESP8266Interface.cpp.
| nsapi_error_t set_dhcp | ( | bool | dhcp ) | [virtual, inherited] |
Enable or disable DHCP on connecting the network.
Enabled by default unless a static IP address has been assigned. Requires that the network is disconnected.
- Parameters:
-
dhcp True to enable DHCP.
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure.
Reimplemented in EMACInterface.
Definition at line 48 of file NetworkInterface.cpp.
| nsapi_error_t set_network | ( | const char * | ip_address, |
| const char * | netmask, | ||
| const char * | gateway | ||
| ) | [virtual, inherited] |
Configure this network interface to use a static IP address.
Implicitly disables DHCP, which can be enabled in set_dhcp. Requires that the network is disconnected.
- Parameters:
-
ip_address Null-terminated representation of the local IP address netmask Null-terminated representation of the local network mask gateway Null-terminated representation of the local gateway
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
Reimplemented in EMACInterface.
Definition at line 43 of file NetworkInterface.cpp.
| nsapi_error_t setsockopt | ( | nsapi_socket_t | handle, |
| int | level, | ||
| int | optname, | ||
| const void * | optval, | ||
| unsigned | optlen | ||
| ) | [virtual] |
Definition at line 501 of file ESP8266Interface.cpp.
| virtual nsapi_error_t socket_accept | ( | nsapi_socket_t | server, |
| nsapi_socket_t * | handle, | ||
| SocketAddress * | address = 0 |
||
| ) | [protected, pure virtual, inherited] |
Accepts a connection on a TCP socket.
The server socket must be bound and set to listen for connections. On a new connection, creates a network socket and stores it in the specified handle. The handle must be passed to following calls on the socket.
A stack may have a finite number of sockets, in this case NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
This call is non-blocking. If accept would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
server Socket handle to server to accept from handle Destination for a handle to the newly created socket address Destination for the remote address or NULL
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
| int socket_accept | ( | void * | handle, |
| void ** | socket, | ||
| SocketAddress * | address | ||
| ) | [protected, virtual] |
Accept a new connection.
- Parameters:
-
handle Handle in which to store new socket server Socket handle to server to accept from
- Returns:
- 0 on success, negative on failure
- Note:
- This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT
Definition at line 408 of file ESP8266Interface.cpp.
| void socket_attach | ( | void * | handle, |
| void(*)(void *) | callback, | ||
| void * | data | ||
| ) | [protected, virtual] |
Register a callback on state change of the socket.
- Parameters:
-
handle Socket handle callback Function to call on state change data Argument to pass to callback
- Note:
- Callback may be called in an interrupt context.
Definition at line 494 of file ESP8266Interface.cpp.
| virtual void socket_attach | ( | nsapi_socket_t | handle, |
| void(*)(void *) | callback, | ||
| void * | data | ||
| ) | [protected, pure virtual, inherited] |
Register a callback on state change of the socket.
The specified callback will be called on state changes such as when the socket can recv/send/accept successfully and on when an error occurs. The callback may also be called spuriously without reason.
The callback may be called in an interrupt context and should not perform expensive operations such as recv/send calls.
- Parameters:
-
handle Socket handle callback Function to call on state change data Argument to pass to callback
| int socket_bind | ( | void * | handle, |
| const SocketAddress & | address | ||
| ) | [protected, virtual] |
Bind a server socket to a specific port.
- Parameters:
-
handle Socket handle address Local address to listen for incoming connections on
- Returns:
- 0 on success, negative on failure.
Definition at line 352 of file ESP8266Interface.cpp.
| virtual nsapi_error_t socket_bind | ( | nsapi_socket_t | handle, |
| const SocketAddress & | address | ||
| ) | [protected, pure virtual, inherited] |
Bind a specific address to a socket.
Binding a socket specifies the address and port on which to receive data. If the IP address is zeroed, only the port is bound.
- Parameters:
-
handle Socket handle address Local address to bind
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure.
| int socket_close | ( | void * | handle ) | [protected, virtual] |
Close the socket.
- Parameters:
-
handle Socket handle
- Returns:
- 0 on success, negative on failure
- Note:
- On failure, any memory associated with the socket must still be cleaned up
Definition at line 332 of file ESP8266Interface.cpp.
| virtual nsapi_error_t socket_close | ( | nsapi_socket_t | handle ) | [protected, pure virtual, inherited] |
Close the socket.
Closes any open connection and deallocates any memory associated with the socket.
- Parameters:
-
handle Socket handle
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
| int socket_connect | ( | void * | handle, |
| const SocketAddress & | address | ||
| ) | [protected, virtual] |
Connects this TCP socket to the server.
- Parameters:
-
handle Socket handle address SocketAddress to connect to
- Returns:
- 0 on success, negative on failure
Definition at line 384 of file ESP8266Interface.cpp.
| virtual nsapi_error_t socket_connect | ( | nsapi_socket_t | handle, |
| const SocketAddress & | address | ||
| ) | [protected, pure virtual, inherited] |
Connects TCP socket to a remote host.
Initiates a connection to a remote server specified by the indicated address.
- Parameters:
-
handle Socket handle address The SocketAddress of the remote host
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
| virtual nsapi_error_t socket_listen | ( | nsapi_socket_t | handle, |
| int | backlog | ||
| ) | [protected, pure virtual, inherited] |
Listen for connections on a TCP socket.
Marks the socket as a passive socket that can be used to accept incoming connections.
- Parameters:
-
handle Socket handle backlog Number of pending connections that can be queued simultaneously
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
| int socket_listen | ( | void * | handle, |
| int | backlog | ||
| ) | [protected, virtual] |
Start listening for incoming connections.
- Parameters:
-
handle Socket handle backlog Number of pending connections that can be queued up at any one time [Default: 1]
- Returns:
- 0 on success, negative on failure
Definition at line 379 of file ESP8266Interface.cpp.
| virtual nsapi_error_t socket_open | ( | nsapi_socket_t * | handle, |
| nsapi_protocol_t | proto | ||
| ) | [protected, pure virtual, inherited] |
Opens a socket.
Creates a network socket and stores it in the specified handle. The handle must be passed to following calls on the socket.
A stack may have a finite number of sockets, in this case NSAPI_ERROR_NO_SOCKET is returned if no socket is available.
- Parameters:
-
handle Destination for the handle to a newly created socket proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
| int socket_open | ( | void ** | handle, |
| nsapi_protocol_t | proto | ||
| ) | [protected, virtual] |
Open a socket.
- Parameters:
-
handle Handle in which to store new socket proto Type of socket to open, NSAPI_TCP or NSAPI_UDP
- Returns:
- 0 on success, negative on failure
Definition at line 302 of file ESP8266Interface.cpp.
| int socket_recv | ( | void * | handle, |
| void * | data, | ||
| unsigned | size | ||
| ) | [protected, virtual] |
Receive data from the remote host.
- Parameters:
-
handle Socket handle data The buffer in which to store the data received from the host size The maximum length of the buffer
- Returns:
- Number of received bytes on success, negative on failure
- Note:
- This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT
Definition at line 427 of file ESP8266Interface.cpp.
| virtual nsapi_size_or_error_t socket_recv | ( | nsapi_socket_t | handle, |
| void * | data, | ||
| nsapi_size_t | size | ||
| ) | [protected, pure virtual, inherited] |
Receive data over a TCP socket.
The socket must be connected to a remote host. Returns the number of bytes received into the buffer.
This call is non-blocking. If recv would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
handle Socket handle data Destination buffer for data received from the host size Size of the buffer in bytes
- Returns:
- Number of received bytes on success, negative error code on failure
| virtual nsapi_size_or_error_t socket_recvfrom | ( | nsapi_socket_t | handle, |
| SocketAddress * | address, | ||
| void * | buffer, | ||
| nsapi_size_t | size | ||
| ) | [protected, pure virtual, inherited] |
Receive a packet over a UDP socket.
Receives data and stores the source address in address if address is not NULL. Returns the number of bytes received into the buffer.
This call is non-blocking. If recvfrom would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
handle Socket handle address Destination for the source address or NULL buffer Destination buffer for data received from the host size Size of the buffer in bytes
- Returns:
- Number of received bytes on success, negative error code on failure
| int socket_recvfrom | ( | void * | handle, |
| SocketAddress * | address, | ||
| void * | buffer, | ||
| unsigned | size | ||
| ) | [protected, virtual] |
Receive a packet from a remote endpoint.
- Parameters:
-
handle Socket handle address Destination for the remote SocketAddress or null buffer The buffer for storing the incoming packet data If a packet is too long to fit in the supplied buffer, excess bytes are discarded size The length of the buffer
- Returns:
- The number of received bytes on success, negative on failure
- Note:
- This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT
Definition at line 478 of file ESP8266Interface.cpp.
| int socket_send | ( | void * | handle, |
| const void * | data, | ||
| unsigned | size | ||
| ) | [protected, virtual] |
Send data to the remote host.
- Parameters:
-
handle Socket handle data The buffer to send to the host size The length of the buffer to send
- Returns:
- Number of written bytes on success, negative on failure
- Note:
- This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT
Definition at line 413 of file ESP8266Interface.cpp.
| virtual nsapi_size_or_error_t socket_send | ( | nsapi_socket_t | handle, |
| const void * | data, | ||
| nsapi_size_t | size | ||
| ) | [protected, pure virtual, inherited] |
Send data over a TCP socket.
The socket must be connected to a remote host. Returns the number of bytes sent from the buffer.
This call is non-blocking. If send would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
handle Socket handle data Buffer of data to send to the host size Size of the buffer in bytes
- Returns:
- Number of sent bytes on success, negative error code on failure
| virtual nsapi_size_or_error_t socket_sendto | ( | nsapi_socket_t | handle, |
| const SocketAddress & | address, | ||
| const void * | data, | ||
| nsapi_size_t | size | ||
| ) | [protected, pure virtual, inherited] |
Send a packet over a UDP socket.
Sends data to the specified address. Returns the number of bytes sent from the buffer.
This call is non-blocking. If sendto would block, NSAPI_ERROR_WOULD_BLOCK is returned immediately.
- Parameters:
-
handle Socket handle address The SocketAddress of the remote host data Buffer of data to send to the host size Size of the buffer in bytes
- Returns:
- Number of sent bytes on success, negative error code on failure
| int socket_sendto | ( | void * | handle, |
| const SocketAddress & | address, | ||
| const void * | data, | ||
| unsigned | size | ||
| ) | [protected, virtual] |
Send a packet to a remote endpoint.
- Parameters:
-
handle Socket handle address The remote SocketAddress data The packet to be sent size The length of the packet to be sent
- Returns:
- The number of written bytes on success, negative on failure
- Note:
- This call is not-blocking, if this call would block, must immediately return NSAPI_ERROR_WOULD_WAIT
Definition at line 448 of file ESP8266Interface.cpp.
| virtual WiFiInterface* wifiInterface | ( | ) | [virtual, inherited] |
Return pointer to a WiFiInterface.
- Returns:
- Pointer to requested interface type or NULL if this class doesn't implement the interface.
Definition at line 105 of file WiFiInterface.h.
Generated on Tue Jul 12 2022 20:53:11 by
1.7.2