George Djabarov / Mbed OS mbed-os-example-mesh-minimal
Committer:
mbed_official
Date:
Fri Oct 21 09:15:09 2016 +0100
Revision:
19:f55c7983f8ab
Parent:
17:ee2610e1cb78
Child:
49:425a1889434d
Updating mbed-os to mbed-os-5.2.0-rc4


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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Seppo Takalo 0:bde1843b9885 1 # Example mesh application for mbed OS
Seppo Takalo 0:bde1843b9885 2
Seppo Takalo 0:bde1843b9885 3 This application is the simplest one to utilize our mesh networking stack. It just joins your device to the unsecure *6LoWPAN-ND* network.
Seppo Takalo 0:bde1843b9885 4
Seppo Takalo 0:bde1843b9885 5 ## Setup
Seppo Takalo 0:bde1843b9885 6
Seppo Takalo 0:bde1843b9885 7 ### Download the application
Seppo Takalo 0:bde1843b9885 8
Seppo Takalo 0:bde1843b9885 9 ```
Seppo Takalo 0:bde1843b9885 10 mbed import mbed-os-example-mesh-minimal
Seppo Takalo 0:bde1843b9885 11 cd mbed-os-example-mesh-minimal
Seppo Takalo 0:bde1843b9885 12 ```
Seppo Takalo 0:bde1843b9885 13
Seppo Takalo 0:bde1843b9885 14 ### Change the channel settings (optional)
Seppo Takalo 0:bde1843b9885 15
Seppo Takalo 0:bde1843b9885 16 See the file `mbed_app.json` for an example of defining an IEEE 802.15.4 channel to use.
Seppo Takalo 0:bde1843b9885 17
mbed_official 19:f55c7983f8ab 18 ### Selecting optimal Nanostack configuration
mbed_official 19:f55c7983f8ab 19
mbed_official 19:f55c7983f8ab 20 If you want to optimize the flash usage, you need to select a proper configuration for Nanostack. The configuration depends mostly on the preferred use case.
mbed_official 19:f55c7983f8ab 21
mbed_official 19:f55c7983f8ab 22 See [6LoWPAN overview](https://docs.mbed.com/docs/arm-ipv66lowpan-stack/en/latest/quick_start_intro/index.html) for the definition of star and mesh networks. These same principles apply also to Thread protocol.
mbed_official 19:f55c7983f8ab 23
mbed_official 19:f55c7983f8ab 24 Select the protocol the network is based on:
mbed_official 19:f55c7983f8ab 25
mbed_official 19:f55c7983f8ab 26 - 6LoWPAN-ND
mbed_official 19:f55c7983f8ab 27 - Thread
mbed_official 19:f55c7983f8ab 28
mbed_official 19:f55c7983f8ab 29 Select the device role:
mbed_official 19:f55c7983f8ab 30
mbed_official 19:f55c7983f8ab 31 - Mesh network. A router. (default)
mbed_official 19:f55c7983f8ab 32 - Star network. Non routing device. Also known as a host, or sleepy host.
mbed_official 19:f55c7983f8ab 33
mbed_official 19:f55c7983f8ab 34 Modify your `mbed_app.json` file to tell which Nanostack build to choose and which configrations to use on [mbed Mesh API](https://github.com/ARMmbed/mbed-os/blob/master/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/README.md).
mbed_official 19:f55c7983f8ab 35
mbed_official 19:f55c7983f8ab 36 An example of the `mbed_app.json` file:
mbed_official 19:f55c7983f8ab 37
mbed_official 19:f55c7983f8ab 38 ```
mbed_official 19:f55c7983f8ab 39 ...
mbed_official 19:f55c7983f8ab 40 "mesh-type":{
mbed_official 19:f55c7983f8ab 41 "help": "options are MESH_LOWPAN, MESH_THREAD",
mbed_official 19:f55c7983f8ab 42 "value": "MESH_LOWPAN"
mbed_official 19:f55c7983f8ab 43 }
mbed_official 19:f55c7983f8ab 44 },
mbed_official 19:f55c7983f8ab 45 "target_overrides": {
mbed_official 19:f55c7983f8ab 46 "*": {
mbed_official 19:f55c7983f8ab 47 "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
mbed_official 19:f55c7983f8ab 48 "mbed-mesh-api.6lowpan-nd-device-type": "NET_6LOWPAN_ROUTER",
mbed_official 19:f55c7983f8ab 49 "mbed-mesh-api.thread-device-type": "MESH_DEVICE_TYPE_THREAD_ROUTER",
mbed_official 19:f55c7983f8ab 50 "mbed-mesh-api.heap-size": 32000,
mbed_official 19:f55c7983f8ab 51 "mbed-trace.enable": false
mbed_official 19:f55c7983f8ab 52 }
mbed_official 19:f55c7983f8ab 53 }
mbed_official 19:f55c7983f8ab 54 ```
mbed_official 19:f55c7983f8ab 55
mbed_official 19:f55c7983f8ab 56 The following tables show the values you should use in the `mbed_app.json` file for your devices in different networks.
mbed_official 19:f55c7983f8ab 57
mbed_official 19:f55c7983f8ab 58 - For 6LoWPAN-ND based network use `mesh-type: MESH_LOWPAN`.
mbed_official 19:f55c7983f8ab 59 - For Thread based network use `mesh-type: MESH_THREAD`.
mbed_official 19:f55c7983f8ab 60
mbed_official 19:f55c7983f8ab 61 **mesh-type: MESH_LOWPAN**
mbed_official 19:f55c7983f8ab 62
mbed_official 19:f55c7983f8ab 63 |Device role|`target.features_add` value|`mbed-mesh-api.6lowpan-nd-device-type`|
mbed_official 19:f55c7983f8ab 64 |-----------|-------------------------|------------------------------------|
mbed_official 19:f55c7983f8ab 65 |Mesh router (default) | LOWPAN_ROUTER | NET_6LOWPAN_ROUTER |
mbed_official 19:f55c7983f8ab 66 |Non routing device | LOWPAN_HOST | NET_6LOWPAN_HOST |
mbed_official 19:f55c7983f8ab 67
mbed_official 19:f55c7983f8ab 68 **mesh-type: MESH_THREAD**
mbed_official 19:f55c7983f8ab 69
mbed_official 19:f55c7983f8ab 70 |Device role|`target.features_add` value|`mbed-mesh-api.thread-device-type`|
mbed_official 19:f55c7983f8ab 71 |-----------|-------------------------|------------------------------------|
mbed_official 19:f55c7983f8ab 72 |Mesh router (default) | THREAD_ROUTER | MESH_DEVICE_TYPE_THREAD_ROUTER |
mbed_official 19:f55c7983f8ab 73 |Non routing device | THREAD_END_DEVICE | MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE |
mbed_official 19:f55c7983f8ab 74
mbed_official 19:f55c7983f8ab 75 **Note:** You need to recompile your application after modifying the configurations by issuing the command `mbed compile -c`.
mbed_official 19:f55c7983f8ab 76
mbed_official 19:f55c7983f8ab 77 ### Requirements for hardware
mbed_official 19:f55c7983f8ab 78
mbed_official 19:f55c7983f8ab 79 The networking stack used in this example requires TLS functionality to be enabled on mbed TLS.
mbed_official 19:f55c7983f8ab 80 On devices where hardware entropy is not present, TLS is disabled by default. This would result in compile time failures or linking failures.
mbed_official 19:f55c7983f8ab 81
mbed_official 19:f55c7983f8ab 82 To learn why entropy is required, read the [TLS Porting guide](https://docs.mbed.com/docs/mbed-os-handbook/en/5.2/advanced/tls_porting/).
mbed_official 19:f55c7983f8ab 83
Seppo Takalo 0:bde1843b9885 84 ### Compile the application
Seppo Takalo 0:bde1843b9885 85
Seppo Takalo 0:bde1843b9885 86 ```
Seppo Takalo 0:bde1843b9885 87 mbed compile -m K64F -t GCC_ARM
Seppo Takalo 0:bde1843b9885 88 ```
Seppo Takalo 0:bde1843b9885 89
Seppo Takalo 0:bde1843b9885 90 A binary is generated at the end of the build process.
Seppo Takalo 0:bde1843b9885 91
Seppo Takalo 0:bde1843b9885 92 ### Connect the RF shield to the board
Seppo Takalo 0:bde1843b9885 93
Seppo Takalo 0:bde1843b9885 94 By default, we are using the Atmel AT86RF233 and it can be purchased [here](https://firefly-iot.com/product/firefly-arduino-shield-2-4ghz/). Place the shield on top of your board and power it up.
Seppo Takalo 0:bde1843b9885 95
Seppo Takalo 0:bde1843b9885 96 ### Program the target
Seppo Takalo 0:bde1843b9885 97
Seppo Takalo 0:bde1843b9885 98 Drag and drop the binary to the target to program the application.
Seppo Takalo 0:bde1843b9885 99
Seppo Takalo 0:bde1843b9885 100 ### Update the firmware of the border router
Seppo Takalo 0:bde1843b9885 101
mbed_official 19:f55c7983f8ab 102 This example supports the following two border routers:
Seppo Takalo 0:bde1843b9885 103
mbed_official 19:f55c7983f8ab 104 - [k64f-border-router](https://github.com/ARMmbed/k64f-border-router), 6LoWPAN only
mbed_official 19:f55c7983f8ab 105 - [mbed gateway](https://firefly-iot.com/product/firefly-6lowpan-gateway-2-4ghz/)
mbed_official 19:f55c7983f8ab 106
mbed_official 19:f55c7983f8ab 107 Read the instructions on updating the firmware of your mbed gateway working as 6LoWPAN [here](https://github.com/ARMmbed/mbed-os-example-client#mbed-gateway).
mbed_official 19:f55c7983f8ab 108
mbed_official 19:f55c7983f8ab 109 Both border routers support static and dynamic backhaul configuration. The static configuration is good for testing but the dynamic one works if your network infrastructure is supplying an IPv6 address. Make sure that you use the appropiate mode.
mbed_official 19:f55c7983f8ab 110
mbed_official 19:f55c7983f8ab 111 Remember to connect the Ethernet cable between the border router and your home/office router. Then power up the board.
Seppo Takalo 0:bde1843b9885 112
Seppo Takalo 0:bde1843b9885 113 ## Testing
Seppo Takalo 0:bde1843b9885 114
Seppo Takalo 0:bde1843b9885 115 As soon as both the border router and the target are up and running you can verify the correct behaviour. Open a serial console and see the IP address obtained by the device.
Seppo Takalo 0:bde1843b9885 116
mbed_official 13:4a0466077538 117 <span class="notes">**Note:** This application uses the baud rate of 115200.</span>
Seppo Takalo 0:bde1843b9885 118
Seppo Takalo 0:bde1843b9885 119 ```
Seppo Takalo 0:bde1843b9885 120 connected. IP = 2001:db8:a0b:12f0::1
Seppo Takalo 0:bde1843b9885 121 ```
Seppo Takalo 0:bde1843b9885 122
Seppo Takalo 0:bde1843b9885 123 You can use this IP address to `ping` from your PC and verify that the connection is working correctly.
Seppo Takalo 0:bde1843b9885 124
Seppo Takalo 0:bde1843b9885 125 ### Changing the radio driver (optional)
Seppo Takalo 0:bde1843b9885 126
Seppo Takalo 0:bde1843b9885 127 To run a 6LoWPAN-ND network, you need a working RF driver for Nanostack. This example uses the Atmel AT86RF233 by default.
Seppo Takalo 0:bde1843b9885 128
Seppo Takalo 0:bde1843b9885 129 To change the RF driver:
Seppo Takalo 0:bde1843b9885 130
Seppo Takalo 0:bde1843b9885 131 1. Uninstall the Atmel RF driver.
Seppo Takalo 0:bde1843b9885 132
Seppo Takalo 0:bde1843b9885 133 mbed remove atmel-rf-driver
Seppo Takalo 0:bde1843b9885 134
Seppo Takalo 0:bde1843b9885 135 2. Install the new driver. (For example, for the FRDM-CR20A radio shield based on the MCR20A device.)
Seppo Takalo 0:bde1843b9885 136
Seppo Takalo 0:bde1843b9885 137 mbed add mcr20a-rf-driver
Seppo Takalo 0:bde1843b9885 138
Seppo Takalo 0:bde1843b9885 139 3. Recompile your application.
Seppo Takalo 0:bde1843b9885 140
Seppo Takalo 0:bde1843b9885 141 mbed compile -m K64F -t GCC_ARM
Seppo Takalo 0:bde1843b9885 142
mbed_official 19:f55c7983f8ab 143 **Note:** Make sure that the `mbed_app.json` file is also updated to reflect the usage of a particular RF driver. For example,
mbed_official 17:ee2610e1cb78 144
mbed_official 17:ee2610e1cb78 145 ```json
mbed_official 17:ee2610e1cb78 146 "radio-type":{
mbed_official 17:ee2610e1cb78 147 "help": "options are ATMEL, MCR20",
mbed_official 17:ee2610e1cb78 148 "value": "ATMEL"
mbed_official 17:ee2610e1cb78 149 },
mbed_official 17:ee2610e1cb78 150 ```