Mistake on this page?
Report an issue in GitHub or email us

6LoWPAN 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:

  • 6LoWPAN_ND, loosely following the Zigbee-IP specification.
  • Thread, following the specification from Thread Group.

Nanostack is the networking stack that provides both of these protocols. For more information on the stack internals, please refer to the 6LoWPAN mesh technology section. Application developers use Nanostack through the Mbed Mesh API.

The application can use the LoWPANNDInterface or ThreadInterface object for connecting 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 configure the mesh interface by providing values in mbed_app.json, as the mesh configuration section documents.

Usage

  1. Create a network interface and driver objects.
  2. Initialize the interface with given PHY driver.
  3. Connect to network.

Supported mesh networking modes

Currently, 6LoWPAN-ND (neighbor discovery) and Thread bootstrap modes are supported.

Network connection states

After the initialization, the network state is MESH_DISCONNECTED. After a successful connection, the state changes to MESH_CONNECTED and when disconnected from the network the state is changed back to MESH_DISCONNECTED.

In case of connection errors, the state is changed to some of the connection error states. In an error state, there is no need to make a disconnect request and the application is allowed to attempt connecting again.

Getting started

See the example application mbed-os-example-mesh-minimal for usage.

Mesh class reference

Public Member Functions
virtual MeshInterfacemeshInterface ()
 Public Member Functions inherited from NetworkInterface
virtual const char * get_mac_address ()
virtual const char * get_ip_address ()
virtual const char * get_netmask ()
virtual const char * get_gateway ()
virtual nsapi_error_t set_network (const char *ip_address, const char *netmask, const char *gateway)
virtual nsapi_error_t set_dhcp (bool dhcp)
virtual nsapi_error_t connect ()=0
virtual nsapi_error_t disconnect ()=0
virtual nsapi_error_t gethostbyname (const char *host, SocketAddress *address, nsapi_version_t version=NSAPI_UNSPEC)
virtual nsapi_value_or_error_t gethostbyname_async (const char *host, hostbyname_cb_t callback, nsapi_version_t version=NSAPI_UNSPEC)
virtual nsapi_error_t gethostbyname_async_cancel (int id)
virtual nsapi_error_t add_dns_server (const SocketAddress &address)
virtual void attach (mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb)
virtual nsapi_connection_status_t get_connection_status () const
virtual nsapi_error_t set_blocking (bool blocking)
virtual EthInterfaceethInterface ()
virtual WiFiInterfacewifiInterface ()
virtual CellularBasecellularBase ()
virtual EMACInterfaceemacInterface ()
Static Public Member Functions
static MeshInterfaceget_default_instance ()
 Static Public Member Functions inherited from NetworkInterface
static NetworkInterfaceget_default_instance ()
Static Protected Member Functions
static MeshInterfaceget_target_default_instance ()
 Static Protected Member Functions inherited from NetworkInterface
static NetworkInterfaceget_target_default_instance ()
Additional Inherited Members
 Public Types inherited from NetworkInterface
typedef mbed::Callback< void(nsapi_error_t result, SocketAddress *address)> hostbyname_cb_t
 Public Types inherited from DNS
typedef mbed::Callback< void(nsapi_error_t result, SocketAddress *address)> hostbyname_cb_t
 Protected Member Functions inherited from NetworkInterface
virtual NetworkStackget_stack ()=0

Mesh example

The application below demonstrates a simple light control application, where devices can control the LED status of all devices in the network. You can build the application for the unsecure 6LoWPAN-ND or Thread network.

/*
 * Copyright (c) 2016 ARM Limited. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "mbed.h"
#include "rtos.h"
#include "NanostackInterface.h"
#include "mbed-trace/mbed_trace.h"
#include "mesh_nvm.h"

#if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
#include "mesh_led_control_example.h"
#endif

void trace_printer(const char* str) {
    printf("%s\n", str);
}

MeshInterface *mesh;

static Mutex SerialOutMutex;

void thread_eui64_trace()
{
#define LOWPAN 1
#define THREAD 2
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == THREAD && (MBED_VERSION >= MBED_ENCODE_VERSION(5,10,0))
   uint8_t eui64[8] = {0};
   static_cast<ThreadInterface*>(mesh)->device_eui64_get(eui64);
   printf("Device EUI64 address = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", eui64[0], eui64[1], eui64[2], eui64[3], eui64[4], eui64[5], eui64[6], eui64[7]);
#endif
}

void serial_out_mutex_wait()
{
    SerialOutMutex.lock();
}

void serial_out_mutex_release()
{
    SerialOutMutex.unlock();
}

int main()
{
    mbed_trace_init();
    mbed_trace_print_function_set(trace_printer);
    mbed_trace_mutex_wait_function_set( serial_out_mutex_wait );
    mbed_trace_mutex_release_function_set( serial_out_mutex_release );

    printf("Start mesh-minimal application\n");

#define STR(s) #s
    printf("Build: %s %s\nMesh type: %s\n", __DATE__, __TIME__, STR(MBED_CONF_NSAPI_DEFAULT_MESH_TYPE));
#ifdef MBED_MAJOR_VERSION
    printf("Mbed OS version: %d.%d.%d\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
#endif

#if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
    if (MBED_CONF_APP_BUTTON != NC && MBED_CONF_APP_LED != NC) {
        start_blinking();
    } else {
        printf("pins not configured. Skipping the LED control.\n");
    }
#endif
    mesh = MeshInterface::get_default_instance();
    if (!mesh) {
        printf("Error! MeshInterface not found!\n");
        return -1;
    }

    thread_eui64_trace();
    mesh_nvm_initialize();
    printf("Connecting...\n");
    int error = mesh->connect();
    if (error) {
        printf("Connection failed! %d\n", error);
        return error;
    }

    while (NULL == mesh->get_ip_address())
        ThisThread::sleep_for(500);

    printf("Connected. IP = %s\n", mesh->get_ip_address());

#if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
    // Network found, start socket example
    if (MBED_CONF_APP_BUTTON != NC && MBED_CONF_APP_LED != NC) {
        cancel_blinking();
        start_mesh_led_control_example((NetworkInterface *)mesh);
    }
#endif
}

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.