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 Mar 04 09:00:38 2019 +0000
Revision:
123:7626a5c3e063
Parent:
119:9974bf303a9c
Child:
124:9dc494407c90
Add Wi-SUN configurations for CI (#244)


.
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 26:b28ab71ff595 1 properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
mbed_official 52:27692043e962 2 [$class: 'StringParameterDefinition', name: 'mbed_os_revision', defaultValue: '', description: 'Revision of mbed-os to build. Use format "pull/PR-NUMBER/head" to access mbed-os PR'],
mbed_official 26:b28ab71ff595 3 [$class: 'BooleanParameterDefinition', name: 'smoke_test', defaultValue: false, description: 'Enable to run HW smoke test after building']
mbed_official 26:b28ab71ff595 4 ]]])
mbed_official 26:b28ab71ff595 5
mbed_official 52:27692043e962 6 if (params.mbed_os_revision == '') {
mbed_official 52:27692043e962 7 echo 'Use mbed OS revision from mbed-os.lib'
mbed_official 52:27692043e962 8 } else {
mbed_official 52:27692043e962 9 echo "Use mbed OS revisiong ${params.mbed_os_revision}"
mbed_official 52:27692043e962 10 if (params.mbed_os_revision.matches('pull/\\d+/head')) {
mbed_official 52:27692043e962 11 echo "Revision is a Pull Request"
mbed_official 52:27692043e962 12 }
mbed_official 52:27692043e962 13 }
mbed_official 32:8b28e79d2ed0 14 echo "Run smoke tests: ${params.smoke_test}"
mbed_official 26:b28ab71ff595 15
mbed_official 26:b28ab71ff595 16
mbed_official 26:b28ab71ff595 17 // Map RaaS instances to corresponding test suites
mbed_official 52:27692043e962 18 // Run only selected set of tests.
mbed_official 52:27692043e962 19 // Board: K64F
mbed_official 52:27692043e962 20 // Radios: Atmel & MCR20A
mbed_official 52:27692043e962 21 // configurations: 6LP + Thread
mbed_official 26:b28ab71ff595 22 def raas = [
mbed_official 26:b28ab71ff595 23 "lowpan_mesh_minimal_smoke_k64f_atmel.json": "8001",
mbed_official 52:27692043e962 24 // "lowpan_mesh_minimal_smoke_k64f_mcr20.json": "8034",
mbed_official 52:27692043e962 25 // "lowpan_mesh_minimal_smoke_429zi_atmel.json": "8030",
mbed_official 52:27692043e962 26 // "lowpan_mesh_minimal_smoke_429zi_mcr20.json": "8033",
mbed_official 52:27692043e962 27 // "lowpan_mesh_minimal_smoke_ublox_atmel.json": "8031",
mbed_official 52:27692043e962 28 // "thread_mesh_minimal_smoke_k64f_atmel.json": "8007"
mbed_official 26:b28ab71ff595 29 "thread_mesh_minimal_smoke_k64f_mcr20.json": "8034",
mbed_official 52:27692043e962 30 // "thread_mesh_minimal_smoke_429zi_atmel.json": "8030",
mbed_official 52:27692043e962 31 // "thread_mesh_minimal_smoke_429zi_mcr20.json": "8033",
mbed_official 52:27692043e962 32 // "thread_mesh_minimal_smoke_ublox_atmel.json": "8031"
mbed_official 26:b28ab71ff595 33 ]
mbed_official 26:b28ab71ff595 34
mbed_official 21:6c1e9147037c 35 // List of targets with supported RF shields to compile
mbed_official 21:6c1e9147037c 36 def targets = [
mbed_official 123:7626a5c3e063 37 "K64F": ["ATMEL", "MCR20A", "S2LP"],
mbed_official 105:0b691b27144a 38 "NUCLEO_F401RE": ["ATMEL", "MCR20A"],
mbed_official 123:7626a5c3e063 39 "NUCLEO_F429ZI": ["ATMEL", "MCR20A", "S2LP"],
mbed_official 105:0b691b27144a 40 //"NCS36510": ["internal"],
mbed_official 52:27692043e962 41 "UBLOX_EVK_ODIN_W2": ["ATMEL"],
mbed_official 119:9974bf303a9c 42 "KW24D": ["internal"],
mbed_official 119:9974bf303a9c 43 "KW41Z": ["internal"]
mbed_official 21:6c1e9147037c 44 ]
mbed_official 34:bc1827b97c5e 45
mbed_official 21:6c1e9147037c 46 // Map toolchains to compilers
mbed_official 21:6c1e9147037c 47 def toolchains = [
mbed_official 21:6c1e9147037c 48 ARM: "armcc",
mbed_official 21:6c1e9147037c 49 GCC_ARM: "arm-none-eabi-gcc",
mbed_official 58:e0f2bf24e6db 50 IAR: "IAR-linux"
mbed_official 21:6c1e9147037c 51 ]
mbed_official 21:6c1e9147037c 52
mbed_official 21:6c1e9147037c 53 // Supported RF shields
mbed_official 21:6c1e9147037c 54 def radioshields = [
mbed_official 21:6c1e9147037c 55 "ATMEL",
mbed_official 105:0b691b27144a 56 "MCR20A",
mbed_official 123:7626a5c3e063 57 "internal",
mbed_official 123:7626a5c3e063 58 "S2LP"
mbed_official 21:6c1e9147037c 59 ]
mbed_official 21:6c1e9147037c 60
mbed_official 21:6c1e9147037c 61 // Mesh interfaces: 6LoWPAN and Thread
mbed_official 21:6c1e9147037c 62 def meshinterfaces = [
mbed_official 21:6c1e9147037c 63 "6lp",
mbed_official 123:7626a5c3e063 64 "thd",
mbed_official 123:7626a5c3e063 65 "ws"
mbed_official 21:6c1e9147037c 66 ]
mbed_official 34:bc1827b97c5e 67
mbed_official 21:6c1e9147037c 68 def stepsForParallel = [:]
mbed_official 21:6c1e9147037c 69
mbed_official 21:6c1e9147037c 70 // Jenkins pipeline does not support map.each, we need to use oldschool for loop
mbed_official 21:6c1e9147037c 71 for (int i = 0; i < targets.size(); i++) {
mbed_official 21:6c1e9147037c 72 for(int j = 0; j < toolchains.size(); j++) {
mbed_official 21:6c1e9147037c 73 for(int k = 0; k < radioshields.size(); k++) {
mbed_official 21:6c1e9147037c 74 for(int l = 0; l < meshinterfaces.size(); l++) {
mbed_official 21:6c1e9147037c 75 def target = targets.keySet().asList().get(i)
mbed_official 21:6c1e9147037c 76 def allowed_shields = targets.get(target)
mbed_official 21:6c1e9147037c 77 def toolchain = toolchains.keySet().asList().get(j)
mbed_official 21:6c1e9147037c 78 def compilerLabel = toolchains.get(toolchain)
mbed_official 21:6c1e9147037c 79 def radioshield = radioshields.get(k)
mbed_official 21:6c1e9147037c 80 def meshInterface = meshinterfaces.get(l)
mbed_official 27:2b3fc6ca5872 81
mbed_official 123:7626a5c3e063 82 // Build Wi-SUN only with S2LP and use S2LP only with Wi-SUN
mbed_official 123:7626a5c3e063 83 if (("${meshInterface}" == "ws" && "${radioshield}" == "S2LP") || ("${meshInterface}" != "ws" && "${radioshield}" != "S2LP")) {
mbed_official 123:7626a5c3e063 84 def stepName = "${target} ${toolchain} ${radioshield} ${meshInterface}"
mbed_official 123:7626a5c3e063 85 if(allowed_shields.contains(radioshield)) {
mbed_official 123:7626a5c3e063 86 stepsForParallel[stepName] = buildStep(target, compilerLabel, toolchain, radioshield, meshInterface)
mbed_official 123:7626a5c3e063 87 }
mbed_official 21:6c1e9147037c 88 }
mbed_official 21:6c1e9147037c 89 }
mbed_official 21:6c1e9147037c 90 }
mbed_official 21:6c1e9147037c 91 }
mbed_official 21:6c1e9147037c 92 }
mbed_official 21:6c1e9147037c 93
mbed_official 26:b28ab71ff595 94 def parallelRunSmoke = [:]
mbed_official 26:b28ab71ff595 95
mbed_official 26:b28ab71ff595 96 // Need to compare boolean against string value
mbed_official 34:bc1827b97c5e 97 if ( params.smoke_test == true ) {
mbed_official 26:b28ab71ff595 98 // Generate smoke tests based on suite amount
mbed_official 26:b28ab71ff595 99 for(int i = 0; i < raas.size(); i++) {
mbed_official 26:b28ab71ff595 100 def suite_to_run = raas.keySet().asList().get(i)
mbed_official 26:b28ab71ff595 101 def raasPort = raas.get(suite_to_run)
mbed_official 26:b28ab71ff595 102 // Parallel execution needs unique step names. Remove .json file ending.
mbed_official 26:b28ab71ff595 103 def smokeStep = "${raasPort} ${suite_to_run.substring(0, suite_to_run.indexOf('.'))}"
mbed_official 26:b28ab71ff595 104 parallelRunSmoke[smokeStep] = run_smoke(targets, toolchains, radioshields, meshinterfaces, raasPort, suite_to_run)
mbed_official 26:b28ab71ff595 105 }
mbed_official 26:b28ab71ff595 106 }
mbed_official 26:b28ab71ff595 107
mbed_official 21:6c1e9147037c 108 timestamps {
mbed_official 21:6c1e9147037c 109 parallel stepsForParallel
mbed_official 26:b28ab71ff595 110 parallel parallelRunSmoke
mbed_official 21:6c1e9147037c 111 }
mbed_official 21:6c1e9147037c 112
mbed_official 21:6c1e9147037c 113 def buildStep(target, compilerLabel, toolchain, radioShield, meshInterface) {
mbed_official 21:6c1e9147037c 114 return {
mbed_official 21:6c1e9147037c 115 stage ("${target}_${compilerLabel}_${radioShield}_${meshInterface}") {
mbed_official 21:6c1e9147037c 116 node ("${compilerLabel}") {
mbed_official 21:6c1e9147037c 117 deleteDir()
mbed_official 21:6c1e9147037c 118 dir("mbed-os-example-mesh-minimal") {
mbed_official 21:6c1e9147037c 119 checkout scm
mbed_official 50:5d4045379c2f 120 def config_file = "mbed_app.json"
mbed_official 105:0b691b27144a 121 def config_suffix = ""
mbed_official 105:0b691b27144a 122
mbed_official 105:0b691b27144a 123 if ("${radioShield}" != "internal") {
mbed_official 105:0b691b27144a 124 config_suffix = "_${radioShield}"
mbed_official 105:0b691b27144a 125 }
mbed_official 21:6c1e9147037c 126
mbed_official 21:6c1e9147037c 127 if ("${meshInterface}" == "thd") {
mbed_official 105:0b691b27144a 128 config_file = "./configs/mesh_thread${config_suffix}.json"
mbed_official 111:b51a8fd84785 129 // Use systest Thread Border Router for testing (CH=26, PANID=BAAB)
mbed_official 111:b51a8fd84785 130 execute("sed -i '/mbed-mesh-api.thread-device-type\":/a \"mbed-mesh-api.thread-config-channel\": 26,' ${config_file}")
mbed_official 51:de6c96c52689 131 execute("sed -i '/mbed-mesh-api.thread-device-type\":/a \"mbed-mesh-api.thread-config-panid\": \"0xBAAB\",' ${config_file}")
mbed_official 68:2330fbeb4926 132 execute("sed -i 's/\"nanostack.configuration\": \"thread_router\"/\"nanostack.configuration\": \"thread_end_device\"/' ${config_file}")
mbed_official 52:27692043e962 133 execute("sed -i 's/\"mbed-mesh-api.thread-device-type\": \"MESH_DEVICE_TYPE_THREAD_ROUTER\"/\"mbed-mesh-api.thread-device-type\": \"MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE\"/' ${config_file}")
mbed_official 53:82a191e2c133 134 }
mbed_official 21:6c1e9147037c 135
mbed_official 21:6c1e9147037c 136 if ("${meshInterface}" == "6lp") {
mbed_official 105:0b691b27144a 137 config_file = "./configs/mesh_6lowpan${config_suffix}.json"
mbed_official 51:de6c96c52689 138 // Use systest 6LoWPAN Border Router for testing (CH=17, PANID=ABBA)
mbed_official 51:de6c96c52689 139 execute("sed -i 's/\"mbed-mesh-api.6lowpan-nd-channel\": 12/\"mbed-mesh-api.6lowpan-nd-channel\": 17/' ${config_file}")
mbed_official 51:de6c96c52689 140 execute("sed -i 's/\"mbed-mesh-api.6lowpan-nd-panid-filter\": \"0xffff\"/\"mbed-mesh-api.6lowpan-nd-panid-filter\": \"0xABBA\"/' ${config_file}")
mbed_official 21:6c1e9147037c 141 }
mbed_official 26:b28ab71ff595 142
mbed_official 123:7626a5c3e063 143 if ("${meshInterface}" == "ws") {
mbed_official 123:7626a5c3e063 144 config_file = "./configs/mesh_wisun${config_suffix}.json"
mbed_official 123:7626a5c3e063 145 // Possibly in future use systest Wi-SUN Border Router for testing (Network name = "ARM-WS-TESTING")
mbed_official 123:7626a5c3e063 146 execute("sed -i 's/\"mbed-mesh-api.wisun-network-name\": \"\\\"Wi-SUN Network\\\"\"/\"mbed-mesh-api.wisun-network-name\": \"\\\"ARM-WS-LAB-NWK\\\"\"/' ${config_file}")
mbed_official 123:7626a5c3e063 147 }
mbed_official 123:7626a5c3e063 148
mbed_official 52:27692043e962 149 // For KW24D, we need to optimize for low memory
mbed_official 52:27692043e962 150 if ("${target}" == "KW24D") {
mbed_official 52:27692043e962 151 // Use optimal mbed TLS config file, need double escaping of '\' characters, first ones to escape Grooy, second ones to escape shell
mbed_official 52:27692043e962 152 // Need to use SH shells
mbed_official 52:27692043e962 153 sh("sed -i '/\"target_overrides\"/ i \"macros\": [\"MBEDTLS_USER_CONFIG_FILE=\\\\\"mbedtls_config.h\\\\\"\"],' ${config_file}")
mbed_official 117:c841ae60db06 154 // Limit mesh heap size to 15kB
mbed_official 117:c841ae60db06 155 execute("sed -i 's/mbed-mesh-api.heap-size\": .*,/mbed-mesh-api.heap-size\": 15000,/' ${config_file}")
mbed_official 52:27692043e962 156 // Limit event loop heap size
mbed_official 52:27692043e962 157 execute("sed -i '/target.features_add/ i \"nanostack-hal.event_loop_thread_stack_size\": 2048,' ${config_file}")
mbed_official 115:833bb975c5e5 158 execute("sed -i '/mbed-mesh-api.thread-device-type\":/a \"mbed-mesh-api.use-malloc-for-heap\": true,' ${config_file}")
mbed_official 52:27692043e962 159 }
mbed_official 52:27692043e962 160
mbed_official 51:de6c96c52689 161 // Activate traces
mbed_official 51:de6c96c52689 162 execute("sed -i 's/\"mbed-trace.enable\": false/\"mbed-trace.enable\": true/' ${config_file}")
mbed_official 51:de6c96c52689 163
mbed_official 26:b28ab71ff595 164 // Set mbed-os to revision received as parameter
mbed_official 21:6c1e9147037c 165 execute ("mbed deploy --protocol ssh")
mbed_official 52:27692043e962 166 if (params.mbed_os_revision != '') {
mbed_official 52:27692043e962 167 dir ("mbed-os") {
mbed_official 52:27692043e962 168 if (params.mbed_os_revision.matches('pull/\\d+/head')) {
mbed_official 52:27692043e962 169 execute("git fetch origin ${params.mbed_os_revision}:PR")
mbed_official 52:27692043e962 170 execute("git checkout PR")
mbed_official 52:27692043e962 171 } else {
mbed_official 52:27692043e962 172 execute ("git checkout ${params.mbed_os_revision}")
mbed_official 52:27692043e962 173 }
mbed_official 52:27692043e962 174 }
mbed_official 21:6c1e9147037c 175 }
mbed_official 103:9982165eb577 176
mbed_official 50:5d4045379c2f 177 execute ("mbed compile --build out/${target}_${toolchain}_${radioShield}_${meshInterface}/ -m ${target} -t ${toolchain} -c --app-config ${config_file}")
mbed_official 21:6c1e9147037c 178 }
mbed_official 26:b28ab71ff595 179 stash name: "${target}_${toolchain}_${radioShield}_${meshInterface}", includes: '**/mbed-os-example-mesh-minimal.bin'
mbed_official 21:6c1e9147037c 180 archive '**/mbed-os-example-mesh-minimal.bin'
mbed_official 26:b28ab71ff595 181 step([$class: 'WsCleanup'])
mbed_official 21:6c1e9147037c 182 }
mbed_official 21:6c1e9147037c 183 }
mbed_official 21:6c1e9147037c 184 }
mbed_official 21:6c1e9147037c 185 }
mbed_official 26:b28ab71ff595 186
mbed_official 26:b28ab71ff595 187 def run_smoke(targets, toolchains, radioshields, meshinterfaces, raasPort, suite_to_run) {
mbed_official 26:b28ab71ff595 188 return {
mbed_official 26:b28ab71ff595 189 // Remove .json from suite name
mbed_official 26:b28ab71ff595 190 def suiteName = suite_to_run.substring(0, suite_to_run.indexOf('.'))
mbed_official 26:b28ab71ff595 191 stage ("smoke_${raasPort}_${suiteName}") {
mbed_official 30:81d713ba997d 192 node ("mesh-test") {
mbed_official 26:b28ab71ff595 193 deleteDir()
mbed_official 26:b28ab71ff595 194 dir("mbed-clitest") {
mbed_official 26:b28ab71ff595 195 git "git@github.com:ARMmbed/mbed-clitest.git"
mbed_official 65:cb583d690d43 196 execute("git checkout ${env.LATEST_CLITEST_STABLE_REL}")
mbed_official 52:27692043e962 197 }
mbed_official 52:27692043e962 198 dir("testcases") {
mbed_official 52:27692043e962 199 git "git@github.com:ARMmbed/mbed-clitest-suites.git"
mbed_official 52:27692043e962 200 execute("git checkout master")
mbed_official 52:27692043e962 201 execute("git submodule update --init --recursive")
mbed_official 52:27692043e962 202 dir("6lowpan") {
mbed_official 26:b28ab71ff595 203 execute("git checkout master")
mbed_official 26:b28ab71ff595 204 }
mbed_official 52:27692043e962 205 dir("thread-tests") {
mbed_official 52:27692043e962 206 execute("git checkout master")
mbed_official 52:27692043e962 207 }
mbed_official 52:27692043e962 208 }
mbed_official 26:b28ab71ff595 209
mbed_official 52:27692043e962 210 for (int i = 0; i < targets.size(); i++) {
mbed_official 52:27692043e962 211 for(int j = 0; j < toolchains.size(); j++) {
mbed_official 52:27692043e962 212 for(int k = 0; k < radioshields.size(); k++) {
mbed_official 52:27692043e962 213 for(int l = 0; l < meshinterfaces.size(); l++) {
mbed_official 52:27692043e962 214 def target = targets.keySet().asList().get(i)
mbed_official 52:27692043e962 215 def allowed_shields = targets.get(target)
mbed_official 52:27692043e962 216 def toolchain = toolchains.keySet().asList().get(j)
mbed_official 52:27692043e962 217 def radioshield = radioshields.get(k)
mbed_official 52:27692043e962 218 def meshInterface = meshinterfaces.get(l)
mbed_official 52:27692043e962 219 // Skip unwanted combination
mbed_official 52:27692043e962 220 if (target == "NUCLEO_F401RE" && toolchain == "IAR") {
mbed_official 52:27692043e962 221 continue
mbed_official 52:27692043e962 222 }
mbed_official 52:27692043e962 223 if(allowed_shields.contains(radioshield)) {
mbed_official 52:27692043e962 224 unstash "${target}_${toolchain}_${radioshield}_${meshInterface}"
mbed_official 26:b28ab71ff595 225 }
mbed_official 26:b28ab71ff595 226 }
mbed_official 26:b28ab71ff595 227 }
mbed_official 26:b28ab71ff595 228 }
mbed_official 26:b28ab71ff595 229 }
mbed_official 52:27692043e962 230 env.RAAS_USERNAME = "user"
mbed_official 52:27692043e962 231 env.RAAS_PASSWORD = "user"
mbed_official 79:4425f61286a3 232 execute("./mbed-clitest/clitest.py --tcdir testcases --suitedir testcases/suites/ --suite ${suite_to_run} --type hardware --reset --raas http://rauni.mbedcloudtesting.com/ --raas_share_allocs --failure_return_value -vvv -w --log log_${raasPort}_${suiteName}")
mbed_official 52:27692043e962 233 archive "log_${raasPort}_${suiteName}/**/*"
mbed_official 26:b28ab71ff595 234 }
mbed_official 26:b28ab71ff595 235 }
mbed_official 26:b28ab71ff595 236 }
mbed_official 26:b28ab71ff595 237 }