This application is the simplest one to utilize our mesh networking stack. It just joins your device to the unsecure 6LoWPAN-ND network. The canonical source for this example lives at https://github.com/ARMmbed/mbed-os-example-mesh-minimal

Example mesh application for Mbed OS

With this application, you can use our mesh networking stack. This application joins your device to the unsecure 6LoWPAN-ND network.

Setup

Building with Mbed CLI

If you'd like to use Mbed CLI to build this offline, then you should refer to the Mbed CLI documentation. The instructions here relate to using the Mbed Online Compiler

  1. Click `Import this application` button.
  2. Change the channel settings: See the file `mbed_app.json` for an example of defining an IEEE 802.15.4 channel to use.
  3. Compile the application

A binary is generated at the end of the build process.

Connect the RF shield to the board

By default, we are using the Atmel AT86RF233, which you can purchase. Place the shield on top of your board, and power it on.

Program the target

Drag and drop the binary to the target to program the application.

Update the firmware of the border router.

You can read the instructions on updating the firmware of your board working as 6LoWPAN border router here.

Please remember to connect the Ethernet cable between the border router and your router. Then, power up the board.

Testing

As soon as both the border router and the target are up and running, you can verify the correct behavior. Open a serial console, and see the IP address obtained by the device.

Note: This application uses a baud rate of 115200.

Quote:

connected. IP = 2001:db8:a0b:12f0::1

You can use this IP address to ping from your PC and verify that the connection is working correctly.

Changing the radio driver (optional)

To run a 6LoWPAN-ND network, you need a working RF driver for Nanostack. This example uses the Atmel AT86RF233 by default.

To change the RF driver:

  1. Uninstall the Atmel RF driver.
  2. Install the new driver. (For example, for the FRDM-CR20A radio shield based on the MCR20A device.)
  3. Recompile your application.
Committer:
mbed_official
Date:
Mon Aug 19 14:00:33 2019 +0100
Revision:
128:e7faff9c9fd9
Parent:
116:b2f0131722a0
Merge branch 'mbed-os-5.13'

* mbed-os-5.13:
Updating mbed-os to mbed-os-5.13.3 (#275)
Update mesh_minimal_startup.py
Updating mbed-os to mbed-os-5.13.2 (#274)

.
Commit copied from https://github.com/ARMmbed/mbed-os-example-mesh-minimal

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 52:27692043e962 1 /*
mbed_official 52:27692043e962 2 * Copyright (c) 2016 ARM Limited. All rights reserved.
mbed_official 52:27692043e962 3 * SPDX-License-Identifier: Apache-2.0
mbed_official 52:27692043e962 4 * Licensed under the Apache License, Version 2.0 (the License); you may
mbed_official 52:27692043e962 5 * not use this file except in compliance with the License.
mbed_official 52:27692043e962 6 * You may obtain a copy of the License at
mbed_official 52:27692043e962 7 *
mbed_official 52:27692043e962 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 52:27692043e962 9 *
mbed_official 52:27692043e962 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 52:27692043e962 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
mbed_official 52:27692043e962 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 52:27692043e962 13 * See the License for the specific language governing permissions and
mbed_official 52:27692043e962 14 * limitations under the License.
mbed_official 52:27692043e962 15 */
Seppo Takalo 0:bde1843b9885 16 #include "mbed.h"
Seppo Takalo 0:bde1843b9885 17 #include "rtos.h"
Seppo Takalo 0:bde1843b9885 18 #include "NanostackInterface.h"
mbed_official 52:27692043e962 19 #include "mbed-trace/mbed_trace.h"
mbed_official 72:a7c594402382 20 #include "mesh_nvm.h"
mbed_official 52:27692043e962 21
mbed_official 52:27692043e962 22 #if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
mbed_official 52:27692043e962 23 #include "mesh_led_control_example.h"
mbed_official 52:27692043e962 24 #endif
mbed_official 52:27692043e962 25
mbed_official 52:27692043e962 26 void trace_printer(const char* str) {
mbed_official 52:27692043e962 27 printf("%s\n", str);
mbed_official 52:27692043e962 28 }
Seppo Takalo 0:bde1843b9885 29
mbed_official 105:0b691b27144a 30 MeshInterface *mesh;
mbed_official 16:22f072355a2c 31
mbed_official 52:27692043e962 32 static Mutex SerialOutMutex;
mbed_official 52:27692043e962 33
mbed_official 97:6dee44085a18 34 void thread_eui64_trace()
mbed_official 97:6dee44085a18 35 {
mbed_official 105:0b691b27144a 36 #define LOWPAN 1
mbed_official 105:0b691b27144a 37 #define THREAD 2
mbed_official 105:0b691b27144a 38 #if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == THREAD && (MBED_VERSION >= MBED_ENCODE_VERSION(5,10,0))
mbed_official 97:6dee44085a18 39 uint8_t eui64[8] = {0};
mbed_official 105:0b691b27144a 40 static_cast<ThreadInterface*>(mesh)->device_eui64_get(eui64);
mbed_official 97:6dee44085a18 41 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]);
mbed_official 97:6dee44085a18 42 #endif
mbed_official 97:6dee44085a18 43 }
mbed_official 97:6dee44085a18 44
mbed_official 52:27692043e962 45 void serial_out_mutex_wait()
mbed_official 52:27692043e962 46 {
mbed_official 52:27692043e962 47 SerialOutMutex.lock();
mbed_official 52:27692043e962 48 }
mbed_official 52:27692043e962 49
mbed_official 52:27692043e962 50 void serial_out_mutex_release()
mbed_official 52:27692043e962 51 {
mbed_official 52:27692043e962 52 SerialOutMutex.unlock();
mbed_official 52:27692043e962 53 }
mbed_official 52:27692043e962 54
Seppo Takalo 0:bde1843b9885 55 int main()
Seppo Takalo 0:bde1843b9885 56 {
mbed_official 52:27692043e962 57 mbed_trace_init();
mbed_official 52:27692043e962 58 mbed_trace_print_function_set(trace_printer);
mbed_official 52:27692043e962 59 mbed_trace_mutex_wait_function_set( serial_out_mutex_wait );
mbed_official 52:27692043e962 60 mbed_trace_mutex_release_function_set( serial_out_mutex_release );
mbed_official 105:0b691b27144a 61
mbed_official 52:27692043e962 62 printf("Start mesh-minimal application\n");
mbed_official 105:0b691b27144a 63
mbed_official 105:0b691b27144a 64 #define STR(s) #s
mbed_official 105:0b691b27144a 65 printf("Build: %s %s\nMesh type: %s\n", __DATE__, __TIME__, STR(MBED_CONF_NSAPI_DEFAULT_MESH_TYPE));
mbed_official 97:6dee44085a18 66 #ifdef MBED_MAJOR_VERSION
mbed_official 97:6dee44085a18 67 printf("Mbed OS version: %d.%d.%d\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
mbed_official 97:6dee44085a18 68 #endif
mbed_official 4:567d72fb3d84 69
mbed_official 52:27692043e962 70 #if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
mbed_official 52:27692043e962 71 if (MBED_CONF_APP_BUTTON != NC && MBED_CONF_APP_LED != NC) {
mbed_official 52:27692043e962 72 start_blinking();
mbed_official 52:27692043e962 73 } else {
mbed_official 52:27692043e962 74 printf("pins not configured. Skipping the LED control.\n");
mbed_official 52:27692043e962 75 }
mbed_official 4:567d72fb3d84 76 #endif
mbed_official 105:0b691b27144a 77 mesh = MeshInterface::get_default_instance();
mbed_official 105:0b691b27144a 78 if (!mesh) {
mbed_official 105:0b691b27144a 79 printf("Error! MeshInterface not found!\n");
mbed_official 105:0b691b27144a 80 return -1;
mbed_official 105:0b691b27144a 81 }
mbed_official 105:0b691b27144a 82
mbed_official 97:6dee44085a18 83 thread_eui64_trace();
mbed_official 72:a7c594402382 84 mesh_nvm_initialize();
mbed_official 97:6dee44085a18 85 printf("Connecting...\n");
mbed_official 105:0b691b27144a 86 int error = mesh->connect();
mbed_official 52:27692043e962 87 if (error) {
mbed_official 52:27692043e962 88 printf("Connection failed! %d\n", error);
mbed_official 52:27692043e962 89 return error;
Seppo Takalo 0:bde1843b9885 90 }
Seppo Takalo 0:bde1843b9885 91
mbed_official 105:0b691b27144a 92 while (NULL == mesh->get_ip_address())
mbed_official 116:b2f0131722a0 93 ThisThread::sleep_for(500);
mbed_official 17:ee2610e1cb78 94
mbed_official 105:0b691b27144a 95 printf("Connected. IP = %s\n", mesh->get_ip_address());
mbed_official 52:27692043e962 96
mbed_official 52:27692043e962 97 #if MBED_CONF_APP_ENABLE_LED_CONTROL_EXAMPLE
mbed_official 52:27692043e962 98 // Network found, start socket example
mbed_official 52:27692043e962 99 if (MBED_CONF_APP_BUTTON != NC && MBED_CONF_APP_LED != NC) {
mbed_official 52:27692043e962 100 cancel_blinking();
mbed_official 105:0b691b27144a 101 start_mesh_led_control_example((NetworkInterface *)mesh);
mbed_official 52:27692043e962 102 }
mbed_official 52:27692043e962 103 #endif
mbed_official 1:24cff46332de 104 }