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
ESP8266Interface Class Reference
ESP8266Interface class Implementation of the NetworkStack for the ESP8266. More...
#include <ESP8266Interface.h>
Inherits NetworkStack, and WiFiInterface.
Public Types | |
enum | scan_mode { SCANMODE_ACTIVE, SCANMODE_PASSIVE } |
Scan mode. More... | |
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, PinName rts=NC, PinName cts=NC, PinName rst=NC, PinName pwr=NC) | |
ESP8266Interface lifetime. | |
virtual | ~ESP8266Interface () |
ESP8266Interface default destructor. | |
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 nsapi_error_t | get_ip_address (SocketAddress *address) |
Get the internally stored IP address. | |
virtual const char * | get_mac_address () |
Get the internally stored MAC address. | |
virtual nsapi_error_t | get_gateway (SocketAddress *address) |
Get the local gateway. | |
virtual nsapi_error_t | get_netmask (SocketAddress *address) |
Get the local network mask. | |
virtual char * | get_interface_name (char *interface_name) |
Get the network interface name. | |
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 int | scan (WiFiAccessPoint *res, unsigned count, scan_mode mode=SCANMODE_PASSIVE, unsigned t_max=0, unsigned t_min=0) |
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 | get_ipv6_link_local_address (SocketAddress *address) |
Get the IPv6 link local address. | |
virtual nsapi_error_t | get_ip_address_if (SocketAddress *address, const char *interface_name) |
Get the local IP address on interface name. | |
virtual nsapi_error_t | gethostbyname (const char *host, SocketAddress *address, nsapi_version_t version=NSAPI_UNSPEC, const char *interface_name=NULL) |
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, const char *interface_name=NULL) |
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, const char *interface_name=NULL) |
Add a domain name server to list of servers to query. | |
virtual nsapi_error_t | get_dns_server (int index, SocketAddress *address, const char *interface_name=NULL) |
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 void | set_default_parameters () |
Set default parameters on a Wi-Fi interface. | |
virtual void | set_as_default () |
Set network interface as default one. | |
virtual nsapi_error_t | get_ipv6_link_local_address (SocketAddress *address) |
Get the IPv6 link local address. | |
virtual nsapi_error_t | set_network (const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &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, const char *interface_name=NULL) |
Translate a hostname to an IP address with specific version using network interface name. | |
virtual nsapi_value_or_error_t | gethostbyname_async (const char *host, hostbyname_cb_t callback, nsapi_version_t version=NSAPI_UNSPEC, const char *interface_name=NULL) |
Translate a hostname to an IP address (asynchronous) using network interface name. | |
virtual nsapi_error_t | gethostbyname_async_cancel (int id) |
Cancel asynchronous hostname translation. | |
virtual nsapi_error_t | add_dns_server (const SocketAddress &address, const char *interface_name) |
Add a domain name server to list of servers to query. | |
void | add_event_listener (mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb) |
Add event listener for interface. | |
void | remove_event_listener (mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb) |
Remove event listener from interface. | |
virtual EthInterface * | ethInterface () |
Return pointer to an EthInterface. | |
virtual MeshInterface * | meshInterface () |
Return pointer to a MeshInterface. | |
virtual EMACInterface * | emacInterface () |
Return pointer to an EMACInterface. | |
virtual CellularInterface * | cellularInterface () |
Return pointer to a CellularInterface. | |
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 | set_blocking (bool blocking) |
Set blocking status of connect() which by default should be blocking. | |
nsapi_error_t | set_country_code (bool track_ap, const char *country_code, int len, int channel_start, int channels) |
Set country code. | |
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 | InternetDatagramSocket |
class | TCPSocket |
class | TCPServer |
class | InternetSocket |
class | UDPSocket |
class | TCPSocket |
class | TCPServer |
class | SocketAddress |
Detailed Description
ESP8266Interface class Implementation of the NetworkStack for the ESP8266.
Definition at line 68 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
Reimplemented from DNS.
Definition at line 114 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.
Reimplemented from DNS.
Definition at line 253 of file NetworkInterface.h.
Member Enumeration Documentation
enum scan_mode |
Scan mode.
Definition at line 187 of file ESP8266Interface.h.
Constructor & Destructor Documentation
ESP8266Interface | ( | ) |
ESP8266Interface default constructor Will use values defined in mbed_lib.json.
Definition at line 61 of file ESP8266Interface.cpp.
ESP8266Interface | ( | PinName | tx, |
PinName | rx, | ||
bool | debug = false , |
||
PinName | rts = NC , |
||
PinName | cts = NC , |
||
PinName | rst = NC , |
||
PinName | pwr = NC |
||
) |
ESP8266Interface lifetime.
- Parameters:
-
tx TX pin rx RX pin debug Enable debugging
Definition at line 103 of file ESP8266Interface.cpp.
~ESP8266Interface | ( | ) | [virtual] |
ESP8266Interface default destructor.
Definition at line 143 of file ESP8266Interface.cpp.
Member Function Documentation
nsapi_error_t add_dns_server | ( | const SocketAddress & | address, |
const char * | interface_name = NULL |
||
) | [virtual, inherited] |
Add a domain name server to list of servers to query.
- Parameters:
-
address Destination for the host address interface_name Network interface name
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
Implements DNS.
Definition at line 116 of file NetworkStack.cpp.
nsapi_error_t add_dns_server | ( | const SocketAddress & | address, |
const char * | interface_name | ||
) | [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.
Implements DNS.
Definition at line 109 of file NetworkInterface.cpp.
void add_event_listener | ( | mbed::Callback< void(nsapi_event_t, intptr_t)> | status_cb ) | [inherited] |
Add event listener for interface.
This API allows multiple callback to be registered for a single interface. When first called, internal list of event handlers are created and registered to interface through attach() API.
Application may only use attach() or add_event_listener() interface. Mixing usage of both leads to undefined behavior.
- Parameters:
-
status_cb The callback for status changes.
Definition at line 144 of file NetworkInterface.cpp.
virtual 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.
virtual CellularInterface* cellularInterface | ( | ) | [virtual, inherited] |
Return pointer to a CellularInterface.
- Returns:
- Pointer to requested interface type or NULL if this class doesn't implement the interface.
Reimplemented in CellularInterface.
Definition at line 387 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.
If interface is configured blocking it will timeout after up to ESP8266_INTERFACE_CONNECT_TIMEOUT_MS + ESP8266_CONNECT_TIMEOUT ms.
- 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
Implements WiFiInterface.
Definition at line 220 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 WiFiInterface.
Definition at line 298 of file ESP8266Interface.cpp.
int disconnect | ( | void | ) | [virtual] |
Stop the interface.
- Returns:
- 0 on success, negative on failure
Implements WiFiInterface.
Definition at line 454 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 379 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 355 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 1057 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 it. Default behavior is to get the target's default interface, if any.
- Returns:
- pointer to interface, if any.
Reimplemented from NetworkInterface.
Definition at line 1064 of file ESP8266Interface.cpp.
nsapi_error_t get_dns_server | ( | int | index, |
SocketAddress * | address, | ||
const char * | interface_name = NULL |
||
) | [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 interface_name Network interface name
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure
Definition at line 121 of file NetworkStack.cpp.
nsapi_error_t get_gateway | ( | SocketAddress * | address ) | [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 557 of file ESP8266Interface.cpp.
char * get_interface_name | ( | char * | interface_name ) | [virtual] |
Get the network interface name.
- Returns:
- Null-terminated representation of the network interface name or null if interface not exists
Reimplemented from NetworkInterface.
Definition at line 599 of file ESP8266Interface.cpp.
nsapi_error_t get_ip_address | ( | SocketAddress * | address ) | [virtual] |
Get the internally stored IP address.
- Returns:
- IP address of the interface or null if not yet connected
Reimplemented from NetworkStack.
Definition at line 524 of file ESP8266Interface.cpp.
nsapi_error_t get_ip_address_if | ( | SocketAddress * | address, |
const char * | interface_name | ||
) | [virtual, inherited] |
Get the local IP address on interface name.
- Parameters:
-
address SocketAddress representation of the link local IPv6 address interface_name Network interface_name
- Return values:
-
NSAPI_ERROR_OK on success NSAPI_ERROR_UNSUPPORTED if this feature is not supported NSAPI_ERROR_PARAMETER if the provided pointer is invalid NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack
Definition at line 42 of file NetworkStack.cpp.
nsapi_error_t get_ipv6_link_local_address | ( | SocketAddress * | address ) | [virtual, inherited] |
Get the IPv6 link local address.
- Parameters:
-
address SocketAddress representation of the link local IPv6 address
- Return values:
-
NSAPI_ERROR_OK on success NSAPI_ERROR_UNSUPPORTED if this feature is not supported NSAPI_ERROR_PARAMETER if the provided pointer is invalid
Definition at line 37 of file NetworkStack.cpp.
nsapi_error_t get_ipv6_link_local_address | ( | SocketAddress * | address ) | [virtual, inherited] |
Get the IPv6 link local address.
- Parameters:
-
address SocketAddress representation of the link local IPv6 address
- Return values:
-
NSAPI_ERROR_OK on success NSAPI_ERROR_UNSUPPORTED if this feature is not supported NSAPI_ERROR_PARAMETER if the provided pointer is invalid
Reimplemented in EMACInterface.
Definition at line 45 of file NetworkInterface.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 544 of file ESP8266Interface.cpp.
nsapi_error_t get_netmask | ( | SocketAddress * | address ) | [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 578 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)
Implements WiFiInterface.
Definition at line 605 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 373 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 it. The default implementation returns NULL.
- Returns:
- pointer to interface, if any.
Reimplemented from NetworkInterface.
Definition at line 54 of file NetworkInterfaceDefaults.cpp.
nsapi_error_t gethostbyname | ( | const char * | host, |
SocketAddress * | address, | ||
nsapi_version_t | version = NSAPI_UNSPEC , |
||
const char * | interface_name = NULL |
||
) | [virtual, inherited] |
Translate a hostname to an IP address with specific version using network interface name.
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). interface_name Network interface name
- Return values:
-
NSAPI_ERROR_OK on success int Negative error code on failure. See NetworkStack::gethostbyname
Implements DNS.
Definition at line 94 of file NetworkInterface.cpp.
nsapi_error_t gethostbyname | ( | const char * | host, |
SocketAddress * | address, | ||
nsapi_version_t | version = NSAPI_UNSPEC , |
||
const char * | interface_name = NULL |
||
) | [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) interface_name Network interface_name
- Return values:
-
NSAPI_ERROR_OK on success NSAPI_ERROR_PARAMETER if invalid (null) name is provided NSAPI_ERROR_DNS_FAILURE if DNS resolution fails int other negative errors, see nsapi_dns_query
Implements DNS.
Definition at line 52 of file NetworkStack.cpp.
nsapi_value_or_error_t gethostbyname_async | ( | const char * | host, |
hostbyname_cb_t | callback, | ||
nsapi_version_t | version = NSAPI_UNSPEC , |
||
const char * | interface_name = NULL |
||
) | [virtual, inherited] |
Translate a hostname to an IP address (asynchronous) using network interface name.
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). interface_name Network interface name
- 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.
Implements DNS.
Definition at line 99 of file NetworkInterface.cpp.
nsapi_value_or_error_t gethostbyname_async | ( | const char * | host, |
hostbyname_cb_t | callback, | ||
nsapi_version_t | version = NSAPI_UNSPEC , |
||
const char * | interface_name = NULL |
||
) | [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) interface_name Network interface_name
- 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
Implements DNS.
Definition at line 79 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.
Implements DNS.
Definition at line 104 of file NetworkInterface.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
Implements DNS.
Definition at line 111 of file NetworkStack.cpp.
nsapi_error_t getsockopt | ( | nsapi_socket_t | handle, |
int | level, | ||
int | optname, | ||
void * | optval, | ||
unsigned * | optlen | ||
) | [virtual] |
Get stack-specific socket options.
The getstackopt allow an application to retrieve stack-specific hints from the underlying stack. For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and optval is unmodified.
- Parameters:
-
handle Socket handle. level Stack-specific protocol level. optname Stack-specific option identifier. optval Destination for option value. optlen Length of the option value.
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure.
Reimplemented from NetworkStack.
Definition at line 998 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 371 of file NetworkInterface.h.
virtual OnboardNetworkStack* onboardNetworkStack | ( | ) | [virtual, inherited] |
Dynamic downcast to a OnboardNetworkStack.
Definition at line 203 of file NetworkStack.h.
void remove_event_listener | ( | mbed::Callback< void(nsapi_event_t, intptr_t)> | status_cb ) | [inherited] |
Remove event listener from interface.
Remove previously added callback from the handler list.
- Parameters:
-
status_cb The callback to unregister.
Definition at line 154 of file NetworkInterface.cpp.
int scan | ( | WiFiAccessPoint * | res, |
unsigned | count, | ||
scan_mode | mode = SCANMODE_PASSIVE , |
||
unsigned | t_max = 0 , |
||
unsigned | t_min = 0 |
||
) | [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 t_max Scan time for each channel - 0-1500ms. If 0 - uses default value t_min Minimum for each channel in active mode - 0-1500ms. If 0 - uses default value. Omit in passive mode
- Returns:
- Number of entries in , or if count was 0 number of available networks, negative on error see nsapi_error
Definition at line 625 of file ESP8266Interface.cpp.
virtual nsapi_size_or_error_t scan | ( | WiFiAccessPoint * | res, |
nsapi_size_t | count | ||
) | [pure virtual, inherited] |
Scan for available networks.
- Note:
- This is a blocking function.
If the count
is 0, the function only returns the number of available networks. If the count
is greater than 0 and the res
is not NULL, the array of discovered APs is populated with discovered networks up to the value of the 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).
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
- Returns:
- Number of entries in , or if count was 0 number of available networks, negative on error see nsapi_error
Definition at line 620 of file ESP8266Interface.cpp.
void set_as_default | ( | ) | [virtual, inherited] |
Set network interface as default one.
Reimplemented in EMACInterface, L3IPInterface, and PPPInterface.
Definition at line 25 of file NetworkInterface.cpp.
nsapi_error_t set_blocking | ( | bool | blocking ) | [protected, virtual] |
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 from NetworkInterface.
Definition at line 1148 of file ESP8266Interface.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
Implements WiFiInterface.
Definition at line 401 of file ESP8266Interface.cpp.
nsapi_error_t set_country_code | ( | bool | track_ap, |
const char * | country_code, | ||
int | len, | ||
int | channel_start, | ||
int | channels | ||
) | [protected] |
Set country code.
- Parameters:
-
track_ap if TRUE, use country code used by the AP ESP is connected to, otherwise uses country_code always country_code ISO 3166-1 coded, 2 character alphanumeric country code assumed len Length of the country code channel_start The channel number to start at channel Number of channels
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure.
Definition at line 1155 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
Implements WiFiInterface.
Definition at line 354 of file ESP8266Interface.cpp.
void set_default_parameters | ( | ) | [virtual, inherited] |
Set default parameters on a Wi-Fi interface.
A Wi-Fi interface instantiated directly or using WiFiInterface::get_default_instance() is initially unconfigured. This call can be used to set the default parameters that would have been set if the interface had been requested using NetworkInterface::get_default_instance() (see nsapi JSON configuration).
Reimplemented from NetworkInterface.
Definition at line 74 of file NetworkInterfaceDefaults.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.
- Return values:
-
NSAPI_ERROR_OK on success. NSAPI_ERROR_UNSUPPORTED if operation is not supported.
Reimplemented in EMACInterface, and L3IPInterface.
Definition at line 85 of file NetworkInterface.cpp.
nsapi_error_t set_network | ( | const SocketAddress & | ip_address, |
const SocketAddress & | netmask, | ||
const SocketAddress & | 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 SocketAddress object containing the local IP address netmask SocketAddress object containing the local network mask gateway SocketAddress object containing the local gateway
- Return values:
-
NSAPI_ERROR_OK on success NSAPI_ERROR_UNSUPPORTED if this function is unsupported
Reimplemented in EMACInterface.
Definition at line 80 of file NetworkInterface.cpp.
nsapi_error_t setsockopt | ( | nsapi_socket_t | handle, |
int | level, | ||
int | optname, | ||
const void * | optval, | ||
unsigned | optlen | ||
) | [virtual] |
Set stack-specific socket options.
The setsockopt allow an application to pass stack-specific hints to the underlying stack. For unsupported options, NSAPI_ERROR_UNSUPPORTED is returned and the socket is unmodified.
- Parameters:
-
handle Socket handle. level Stack-specific protocol level. optname Stack-specific option identifier. optval Option value. optlen Length of the option value.
- Returns:
- NSAPI_ERROR_OK on success, negative error code on failure.
Reimplemented from NetworkStack.
Definition at line 965 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
Implemented in AT_CellularStack.
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 845 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 958 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
Implemented in AT_CellularStack.
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.
Implemented in AT_CellularStack.
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 793 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
Implemented in AT_CellularStack.
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 769 of file ESP8266Interface.cpp.
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 825 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
Implemented in AT_CellularStack.
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 820 of file ESP8266Interface.cpp.
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
Implemented in AT_CellularStack.
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
Implemented in AT_CellularStack.
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 739 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 887 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
Implemented in AT_CellularStack.
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
Implemented in AT_CellularStack.
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 942 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
Implemented in AT_CellularStack.
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 850 of file ESP8266Interface.cpp.
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
Implemented in AT_CellularStack.
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 912 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.
Reimplemented from NetworkInterface.
Definition at line 109 of file WiFiInterface.h.
Generated on Tue Jul 12 2022 13:55:30 by
