Mesh
MeshInterface class hierarchy
The Arm Mbed Mesh API allows the application to use the IPv6 mesh network topologies through the Nanostack networking stack.
Mbed OS provides two types of IPv6-based mesh networks:
-
Wi-SUN, following the specification from the Wi-SUN alliance.
-
6LoWPAN-ND, loosely following the Zigbee-IP specification.
The application can use the LoWPANNDInterface
or WisunInterface
object to connect to the mesh network. When successfully connected, the application can use the Mbed C++ socket APIs to create a socket to start communication with a remote peer. You can use the Network status API to monitor changes in the network status.
You can configure the mesh interface by providing values in mbed_app.json
, as the mesh configuration section documents.
Mesh class reference
Public Types | |
typedef mbed::Callback< void(nsapi_value_or_error_t result, SocketAddress *address)> | hostbyname_cb_t |
Hostname translation callback (for use with gethostbyname_async()). More... |
Public Member Functions | |
MeshInterface * | meshInterface () final |
Return pointer to a MeshInterface. More... | |
virtual void | set_as_default () |
Set network interface as default one. More... | |
virtual const char * | get_mac_address () |
Get the local MAC address. More... | |
virtual nsapi_error_t | get_ip_address (SocketAddress *address) |
Get the local IP address. More... | |
virtual nsapi_error_t | get_ipv6_link_local_address (SocketAddress *address) |
Get the IPv6 link local address. More... | |
virtual nsapi_error_t | get_netmask (SocketAddress *address) |
Get the local network mask. More... | |
virtual nsapi_error_t | get_gateway (SocketAddress *address) |
Get the local gateway. More... | |
virtual char * | get_interface_name (char *interface_name) |
Get the network interface name. More... | |
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. More... | |
virtual nsapi_error_t | set_dhcp (bool dhcp) |
Enable or disable DHCP on connecting the network. More... | |
virtual nsapi_error_t | connect ()=0 |
Connect to a network. More... | |
virtual nsapi_error_t | disconnect ()=0 |
Disconnect from the network. More... | |
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. More... | |
virtual nsapi_value_or_error_t | getaddrinfo (const char *hostname, SocketAddress *hints, SocketAddress **res, const char *interface_name=NULL) |
Translate a hostname to the multiple IP addresses with specific version using network interface name. More... | |
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. More... | |
virtual nsapi_value_or_error_t | getaddrinfo_async (const char *hostname, SocketAddress *hints, hostbyname_cb_t callback, const char *interface_name=NULL) |
Translate a hostname to the multiple IP addresses (asynchronous) using network interface name. More... | |
virtual nsapi_error_t | gethostbyname_async_cancel (int id) |
Cancel asynchronous hostname translation. More... | |
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. More... | |
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. More... | |
virtual void | attach (mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb) |
Register callback for status reporting. More... | |
void | add_event_listener (mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb) |
Add event listener for interface. More... | |
virtual nsapi_connection_status_t | get_connection_status () const |
Get the connection status. More... | |
virtual nsapi_error_t | set_blocking (bool blocking) |
Set asynchronous operation of connect() and disconnect() calls. More... | |
virtual EthInterface * | ethInterface () |
Return pointer to an EthInterface. More... | |
virtual WiFiInterface * | wifiInterface () |
Return pointer to a WiFiInterface. More... | |
virtual EMACInterface * | emacInterface () |
Return pointer to an EMACInterface. More... | |
virtual CellularInterface * | cellularInterface () |
Return pointer to a CellularInterface. More... | |
virtual void | set_default_parameters () |
defined(DOXYGEN_ONLY) More... |
Static Public Member Functions | |
static MeshInterface * | get_default_instance () |
Get the default Mesh interface. More... |
Mesh example
The following code snippet illustrates how you can use the MeshInterface API:
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
int main(void)
{
MeshInterface *mesh = MeshInterface::get_default_instance();
int status = mesh->connect();
if (status) {
printf("Connection failed! error %d\n", status);
return status;
}
printf("Connected!\n");
UDPSocket sock;
status = sock.open(mesh);
if (status) {
printf("Failed to open socket, error %d\n", status);
}
// Now the interface is connected, and I can communicate with Sockets
}
Related content
- Mesh tutorial to start using mesh technology.
- Light control tutorial, in which devices can control the LED status of all devices in the network.
- Mesh configuration.
- Networking connectivity architecture reference material.