mbed-os-sensor-node

Getting started with mbed Client on mbed OS

Warning

This example application is not supported anymore.

Information

History project:

  • 17/01/2018 - Using mbed-cli the project is compiled using the use-malloc-for-heap feature enabled
  • 24/11/2017 - Added support for uvision5, here instructions
  • 02/10/2017 - First Release

This is the mbed Client example for mbed OS. It demonstrates how to register a device with mbed Device Connector, how to read and write values, and how to deregister. If you are unfamiliar with mbed Device Connector, we recommend that you read the introduction to the data model first.

The application:

  • Connects to network with 6LoWPAN ND connection.
  • Registers with mbed Device Connector.
  • Gives mbed Device Connector access to its resources (read and write).
  • Sends an incremental number to mbed Device Connector.

You can compile this project in three ways:

1. Using the Online compiler. Just clicking here:

/media/uploads/rspelta/image001.png

Information

Learn how to use the Online compiler reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/online_comp/ page.

2. Using the compiler on your PC

Information

Learn how to use the mbed-cli reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/cli/ page.
The name of the machine is SILICA_SENSOR_NODE.

3. Exporting to 3rd party tools (IDE)

Information

Learn how to use the mbed-cli reading https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/third_party/ page. We have exported the project for you, please read here

Warning

This example requires a Border Router board. For more details please read the Border Router paragraph from this page.

Please read carefully the next pages:

  • What to do before to compile the project: read here. This step is indipendent from the way you compile the project.
Committer:
rspelta
Date:
Wed Jan 17 13:42:55 2018 +0100
Revision:
7:e89dae7682f7
Parent:
0:e9b834175c38
fixed memory heap

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rspelta 0:e9b834175c38 1 # Getting started with mbed Client on mbed OS
rspelta 0:e9b834175c38 2
rspelta 0:e9b834175c38 3 This is the mbed Client example for mbed OS (we also have one for [Linux](https://github.com/ARMmbed/mbed-client-linux-example)). It demonstrates how to register a device with mbed Device Connector, how to read and write values, and how to deregister. If you are unfamiliar with mbed Device Connector, we recommend that you read [the introduction to the data model](https://docs.mbed.com/docs/mbed-device-connector-web-interfaces/en/latest/#the-mbed-device-connector-data-model) first.
rspelta 0:e9b834175c38 4
rspelta 0:e9b834175c38 5 ## Required software
rspelta 0:e9b834175c38 6
rspelta 0:e9b834175c38 7 * [ARM mbed account](https://developer.mbed.org/account/login/?next=/).
rspelta 0:e9b834175c38 8 * [mbed-cli](https://github.com/ARMmbed/mbed-cli) - to build the example programs. To learn how to build mbed OS applications with mbed-cli, see [the user guide](https://github.com/ARMmbed/mbed-cli/blob/master/README.md).
rspelta 0:e9b834175c38 9 * [Serial port monitor](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications).
rspelta 0:e9b834175c38 10
rspelta 0:e9b834175c38 11 The application:
rspelta 0:e9b834175c38 12
rspelta 0:e9b834175c38 13 * Connects to network with WiFi, Ethernet, 6LoWPAN ND or Thread connection.
rspelta 0:e9b834175c38 14 * Registers with mbed Device Connector.
rspelta 0:e9b834175c38 15 * Gives mbed Device Connector access to its resources (read and write).
rspelta 0:e9b834175c38 16 * Records the number of clicks on the device’s button and sends the number to mbed Device Connector.
rspelta 0:e9b834175c38 17 * Lets you control the blink pattern of the LED on the device (through mbed Device Connector).
rspelta 0:e9b834175c38 18
rspelta 0:e9b834175c38 19 ## Application setup
rspelta 0:e9b834175c38 20
rspelta 0:e9b834175c38 21 To configure the example application:
rspelta 0:e9b834175c38 22
rspelta 0:e9b834175c38 23 1. [Select network and board](#select-network-and-board)
rspelta 0:e9b834175c38 24 * [Ethernet](#ethernet)
rspelta 0:e9b834175c38 25 * [Mesh (6LoWPAN and Thread)](#mesh)
rspelta 0:e9b834175c38 26 * [WiFi](#wifi)
rspelta 0:e9b834175c38 27 * [Non listed boards](#non-listed-board-support)
rspelta 0:e9b834175c38 28 1. [Set the client credentials](#client-credentials).
rspelta 0:e9b834175c38 29 1. [Set up an IP address](#ip-address-setup). This step is optional.
rspelta 0:e9b834175c38 30 1. [Change the socket type](#changing-the-socket-type). This step is optional.
rspelta 0:e9b834175c38 31
rspelta 0:e9b834175c38 32 ### Select network and board
rspelta 0:e9b834175c38 33
rspelta 0:e9b834175c38 34 This example supports following hardware-network combinations:
rspelta 0:e9b834175c38 35
rspelta 0:e9b834175c38 36 ### Ethernet
rspelta 0:e9b834175c38 37
rspelta 0:e9b834175c38 38 #### Supported boards
rspelta 0:e9b834175c38 39
rspelta 0:e9b834175c38 40 * K64F
rspelta 0:e9b834175c38 41 * NUCLEO_F429ZI
rspelta 0:e9b834175c38 42 * UBLOX_EVK_ODIN_W2 (use the supplied `configs/eth_v4.json`)
rspelta 0:e9b834175c38 43
rspelta 0:e9b834175c38 44 For running the example application using Ethernet, you need:
rspelta 0:e9b834175c38 45
rspelta 0:e9b834175c38 46 - An Ethernet cable.
rspelta 0:e9b834175c38 47 - An Ethernet connection to the internet.
rspelta 0:e9b834175c38 48
rspelta 0:e9b834175c38 49 ### Mesh
rspelta 0:e9b834175c38 50
rspelta 0:e9b834175c38 51 There are example settings under the configs directory, which provide the easiest way to start with the applications.
rspelta 0:e9b834175c38 52 The [mbed-mesh-api](https://github.com/ARMmbed/mbed-os/tree/master/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed_lib.json)
rspelta 0:e9b834175c38 53 defines the defaults settings for applications. The most relevant parameters are described in more detail in the following sections.
rspelta 0:e9b834175c38 54
rspelta 0:e9b834175c38 55 #### Supported boards
rspelta 0:e9b834175c38 56
rspelta 0:e9b834175c38 57 * K64F + NXP MCR20 15.4 shield (mesh `NANOSTACK_FULL` mode)
rspelta 0:e9b834175c38 58 * [NUCLEO_F429ZI](https://developer.mbed.org/platforms/ST-Nucleo-F429ZI/) + [X-NUCLEO-IDS01A4](https://github.com/ARMmbed/stm-spirit1-rf-driver) Spirit1 6LoWPAN expansion board (mesh `LOWPAN_ROUTER` mode)
rspelta 0:e9b834175c38 59 * NUCLEO_F429ZI + ATMEL AT233 15.4 shield (mesh `LOWPAN_ROUTER` mode)
rspelta 0:e9b834175c38 60 * [Supported combinations of board and shields](#supported-combinations-of-board-and-shields)
rspelta 0:e9b834175c38 61
rspelta 0:e9b834175c38 62 First, you need to select the RF driver to be used by the 6LoWPAN/Thread stack.
rspelta 0:e9b834175c38 63
rspelta 0:e9b834175c38 64 This example supports these shields:
rspelta 0:e9b834175c38 65
rspelta 0:e9b834175c38 66 * [AT86RF233/212B](https://github.com/ARMmbed/atmel-rf-driver)
rspelta 0:e9b834175c38 67 * [NXP-MCR20a](https://github.com/ARMmbed/mcr20a-rf-driver)
rspelta 0:e9b834175c38 68 * [X-NUCLEO-IDS01A4](https://github.com/ARMmbed/stm-spirit1-rf-driver) (*a.k.a.* Spirit1) radio shields. Check instructions for compilation [here](#compile-configuration-for-spirit1)
rspelta 0:e9b834175c38 69
rspelta 0:e9b834175c38 70 To select the radio shield make sure that the `mbed_app.json` file points to the correct radio driver type:
rspelta 0:e9b834175c38 71
rspelta 0:e9b834175c38 72 ```json
rspelta 0:e9b834175c38 73 "mesh_radio_type": {
rspelta 0:e9b834175c38 74 "help": "options are ATMEL, MCR20, SPIRIT1",
rspelta 0:e9b834175c38 75 "value": "ATMEL"
rspelta 0:e9b834175c38 76 },
rspelta 0:e9b834175c38 77 ```
rspelta 0:e9b834175c38 78
rspelta 0:e9b834175c38 79 Then you need to enable ARM IPv6/6LoWPAN stack. Edit the `mbed_app.json` file to add `NANOSTACK` feature with the particular configuration of the stack:
rspelta 0:e9b834175c38 80
rspelta 0:e9b834175c38 81 ```
rspelta 0:e9b834175c38 82 "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
rspelta 0:e9b834175c38 83 ```
rspelta 0:e9b834175c38 84
rspelta 0:e9b834175c38 85 If your connection type is `MESH_THREAD` then you may want to use the `THREAD_ROUTER` configuration:
rspelta 0:e9b834175c38 86
rspelta 0:e9b834175c38 87 ```
rspelta 0:e9b834175c38 88 "target.features_add": ["NANOSTACK", "THREAD_ROUTER", "COMMON_PAL"],
rspelta 0:e9b834175c38 89 ```
rspelta 0:e9b834175c38 90
rspelta 0:e9b834175c38 91 Since 6LoWPAN ND and Thread use IPv6 for connectivity, you need to verify first that you have a working IPv6 connection.
rspelta 0:e9b834175c38 92 To do that, ping the Connector IPv6 address `2607:f0d0:2601:52::20` from your network.
rspelta 0:e9b834175c38 93
rspelta 0:e9b834175c38 94 #### Compile configuration for Spirit1
rspelta 0:e9b834175c38 95
rspelta 0:e9b834175c38 96 <span class="notes">**Note:** In case you want to use the STM Spirit1 Sub-1 GHz RF expansion board (X-NUCLEO-IDS01A4), you also need to configure its MAC address in the `mbed_app.json` file, for example:</span>
rspelta 0:e9b834175c38 97
rspelta 0:e9b834175c38 98 ```json
rspelta 0:e9b834175c38 99 "target_overrides": {
rspelta 0:e9b834175c38 100 "*": {
rspelta 0:e9b834175c38 101 "spirit1.mac-address": "{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7}"
rspelta 0:e9b834175c38 102 },
rspelta 0:e9b834175c38 103 }
rspelta 0:e9b834175c38 104 ```
rspelta 0:e9b834175c38 105
rspelta 0:e9b834175c38 106 #### Channel settings
rspelta 0:e9b834175c38 107
rspelta 0:e9b834175c38 108 The default 2.4GHz channel settings are already defined by the [mbed-mesh-api](https://github.com/ARMmbed/mbed-os/tree/master/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api) to match the Border Router settings. The application can override these settings by adding them to the `.json` file. For example:
rspelta 0:e9b834175c38 109
rspelta 0:e9b834175c38 110 ```json
rspelta 0:e9b834175c38 111 "target_overrides": {
rspelta 0:e9b834175c38 112 "*": {
rspelta 0:e9b834175c38 113 "mbed-mesh-api.6lowpan-nd-channel-page": 0,
rspelta 0:e9b834175c38 114 "mbed-mesh-api.6lowpan-nd-channel": 12,
rspelta 0:e9b834175c38 115 "mbed-mesh-api.thread-config-channel-page": 0,
rspelta 0:e9b834175c38 116 "mbed-mesh-api.thread-config-channel": 22
rspelta 0:e9b834175c38 117 }
rspelta 0:e9b834175c38 118 }
rspelta 0:e9b834175c38 119 ```
rspelta 0:e9b834175c38 120
rspelta 0:e9b834175c38 121 For sub-GHz shields ([Spirit1](https://github.com/ARMmbed/stm-spirit1-rf-driver) or AT86RF212B) use the following overrides, **6LoWPAN ND only**:
rspelta 0:e9b834175c38 122
rspelta 0:e9b834175c38 123 ```json
rspelta 0:e9b834175c38 124 "mbed-mesh-api.6lowpan-nd-channel-page": 2,
rspelta 0:e9b834175c38 125 "mbed-mesh-api.6lowpan-nd-channel": 1
rspelta 0:e9b834175c38 126 ```
rspelta 0:e9b834175c38 127
rspelta 0:e9b834175c38 128 For more information about the radio shields, see [the related documentation](docs/radio_module_identify.md).
rspelta 0:e9b834175c38 129
rspelta 0:e9b834175c38 130 =======
rspelta 0:e9b834175c38 131 #### Supported combinations of board and shields
rspelta 0:e9b834175c38 132
rspelta 0:e9b834175c38 133 See Mesh-minimal's [Notes on different hardware](https://github.com/ARMmbed/mbed-os-example-mesh-minimal/blob/master/Hardware.md) for known combinations of development boards and RF shields that have been tested with mesh networking stack.
rspelta 0:e9b834175c38 134
rspelta 0:e9b834175c38 135 #### Border router
rspelta 0:e9b834175c38 136
rspelta 0:e9b834175c38 137 There are two options for border router.
rspelta 0:e9b834175c38 138
rspelta 0:e9b834175c38 139 ##### Nanostack-border-router
rspelta 0:e9b834175c38 140
rspelta 0:e9b834175c38 141 You can configure and build the [nanostack-border-router](https://github.com/ARMmbed/nanostack-border-router) for the 6LoWPAN ND or Thread mode.
rspelta 0:e9b834175c38 142
rspelta 0:e9b834175c38 143 ##### mbed gateway
rspelta 0:e9b834175c38 144
rspelta 0:e9b834175c38 145 The mbed gateway is a binary release only. Please note, the mbed gateway will not be supported after the mbed-os 5.5 release.
rspelta 0:e9b834175c38 146
rspelta 0:e9b834175c38 147 To connect the example application in 6LoWPAN ND or Thread mode to mbed Device Connector, you need to set up an mbed 6LoWPAN gateway router as follows:
rspelta 0:e9b834175c38 148
rspelta 0:e9b834175c38 149 1. Use an Ethernet cable to connect the mbed 6LoWPAN gateway router to the internet.
rspelta 0:e9b834175c38 150 2. Use a micro-USB cable to connect the mbed 6LoWPAN gateway router to your computer. The computer will list the router as removable storage.
rspelta 0:e9b834175c38 151 3. The firmware for the gateway is located in the `GW_Binary` folder in the root of this example. Select the binary matching your application bootstrap mode:
rspelta 0:e9b834175c38 152
rspelta 0:e9b834175c38 153 * For the **6LoWPAN ND** bootstrap, use `gateway6LoWPANDynamic.bin`.
rspelta 0:e9b834175c38 154 * For the **Thread** bootstrap, use `gatewayThreadDynamic.bin`.
rspelta 0:e9b834175c38 155
rspelta 0:e9b834175c38 156 The dynamic binaries use IPv6 autoconfiguration and enable the client to connect to the mbed Device Connector service. The static binaries create a site-local IPv6 network and packets cannot be routed outside.
rspelta 0:e9b834175c38 157
rspelta 0:e9b834175c38 158 4. Copy the gateway binary file to the mbed 6LoWPAN gateway router to flash the device. The device reboots automatically after flashing. If that does not happen, press the **Reset** button on the board.
rspelta 0:e9b834175c38 159
rspelta 0:e9b834175c38 160 You can view debug traces from the gateway with a serial port monitor. The gateway uses baud rate 460800. The gateway IPv6 address is correctly configured when the following trace is visible: `Eth bootstrap ready, IP=XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX`.
rspelta 0:e9b834175c38 161
rspelta 0:e9b834175c38 162 #### Thread-specific settings
rspelta 0:e9b834175c38 163
rspelta 0:e9b834175c38 164 With Thread, you can change the operating mode of the client from the default router mode to a sleepy end device by adding the following override to the `mbed_app.json` file:
rspelta 0:e9b834175c38 165
rspelta 0:e9b834175c38 166 ```json
rspelta 0:e9b834175c38 167 "mbed-mesh-api.thread-device-type": "MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE"
rspelta 0:e9b834175c38 168 ```
rspelta 0:e9b834175c38 169
rspelta 0:e9b834175c38 170 ## WiFi
rspelta 0:e9b834175c38 171
rspelta 0:e9b834175c38 172 #### Supported boards
rspelta 0:e9b834175c38 173
rspelta 0:e9b834175c38 174 * UBLOX_EVK_ODIN_W2. Check instructions for compilation [here](#compile-configuration-for-odin-wifi).
rspelta 0:e9b834175c38 175 * K64F + GROVE SEEED shield using [ESP8266](https://en.wikipedia.org/wiki/ESP8266) WiFi module.
rspelta 0:e9b834175c38 176 * NUCLEO_F429ZI + GROVE SEEED shield using [ESP8266](https://en.wikipedia.org/wiki/ESP8266) WiFi module.
rspelta 0:e9b834175c38 177
rspelta 0:e9b834175c38 178 To run this application using ESP8266 WiFi Interface, you need:
rspelta 0:e9b834175c38 179
rspelta 0:e9b834175c38 180 1. An [ESP8266](https://en.wikipedia.org/wiki/ESP8266) WiFi module.
rspelta 0:e9b834175c38 181 1. Updated [Espressif Firmware](https://developer.mbed.org/teams/ESP8266/wiki/Firmware-Update).
rspelta 0:e9b834175c38 182 1. Mount the WiFi module onto [K64F Grove Shield v2](https://developer.mbed.org/platforms/FRDM-K64F/#supported-seeed-studio-grove-extension).
rspelta 0:e9b834175c38 183 1. Attach the shield on your board.
rspelta 0:e9b834175c38 184 1. In the `mbed_app.json` file, change:
rspelta 0:e9b834175c38 185
rspelta 0:e9b834175c38 186 ```json
rspelta 0:e9b834175c38 187 "network-interface": {
rspelta 0:e9b834175c38 188 "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.",
rspelta 0:e9b834175c38 189 "value": "WIFI"
rspelta 0:e9b834175c38 190 }
rspelta 0:e9b834175c38 191 ```
rspelta 0:e9b834175c38 192
rspelta 0:e9b834175c38 193 Provide your WiFi SSID and password here and leave `\"` in the beginning and end of your SSID and password (as shown in the example below). Otherwise, the example cannot pick up the SSID and password in correct format.
rspelta 0:e9b834175c38 194
rspelta 0:e9b834175c38 195 ```json
rspelta 0:e9b834175c38 196 "wifi-ssid": {
rspelta 0:e9b834175c38 197 "help": "WiFi SSID",
rspelta 0:e9b834175c38 198 "value": "\"SSID\""
rspelta 0:e9b834175c38 199 },
rspelta 0:e9b834175c38 200 "wifi-password": {
rspelta 0:e9b834175c38 201 "help": "WiFi Password",
rspelta 0:e9b834175c38 202 "value": "\"Password\""
rspelta 0:e9b834175c38 203 }
rspelta 0:e9b834175c38 204 ```
rspelta 0:e9b834175c38 205
rspelta 0:e9b834175c38 206 <span class="notes">**Note:** Some devices do not support the Grove Shield or use the primary UART for USB communication. On such devices, modify the `mbed_app.json` to use the serial pins connected to the ESP8266.</span>
rspelta 0:e9b834175c38 207
rspelta 0:e9b834175c38 208 For example, NUCLEO_F401RE requires a different serial connection:
rspelta 0:e9b834175c38 209
rspelta 0:e9b834175c38 210 ```json
rspelta 0:e9b834175c38 211 "wifi-tx": {
rspelta 0:e9b834175c38 212 "help": "TX pin for serial connection to external device",
rspelta 0:e9b834175c38 213 "value": "PA_11"
rspelta 0:e9b834175c38 214 },
rspelta 0:e9b834175c38 215 "wifi-rx": {
rspelta 0:e9b834175c38 216 "help": "RX pin for serial connection to external device",
rspelta 0:e9b834175c38 217 "value": "PA_12"
rspelta 0:e9b834175c38 218 }
rspelta 0:e9b834175c38 219 ```
rspelta 0:e9b834175c38 220
rspelta 0:e9b834175c38 221 #### Compile configuration for ODIN WiFi
rspelta 0:e9b834175c38 222
rspelta 0:e9b834175c38 223 To compile ODIN WiFi configuration, you need to tell mbed NOT to compile the related files. To do that, set up a `.mbedignore` file. An example file is available in the `configs` folder.
rspelta 0:e9b834175c38 224
rspelta 0:e9b834175c38 225 This should resolve the issue:
rspelta 0:e9b834175c38 226
rspelta 0:e9b834175c38 227 ```
rspelta 0:e9b834175c38 228 cp configs/eth-wifi-mbedignore ./.mbedignore
rspelta 0:e9b834175c38 229 ```
rspelta 0:e9b834175c38 230
rspelta 0:e9b834175c38 231 ### Non listed board support
rspelta 0:e9b834175c38 232
rspelta 0:e9b834175c38 233 Apart from the listed configurations, this example can work on other mbed OS supported hardware boards which support any of the given network interface including Ethernet, WiFi, Mesh (6LoWPAN) or Thread, provided the configuration fulfills condition that the target hardware has TLS entropy implemented for it. On devices where hardware entropy is not present, TLS is disabled by default. This would result in compile time failures or linking failures.
rspelta 0:e9b834175c38 234
rspelta 0:e9b834175c38 235 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/).
rspelta 0:e9b834175c38 236
rspelta 0:e9b834175c38 237 Also, the complete example configuration of mbed Client, the selected network interface and mbed OS components must fit into hardware's given memory size (Flash size and RAM size).
rspelta 0:e9b834175c38 238
rspelta 0:e9b834175c38 239 <span class="notes">**Note:** On non-K64F boards, there is no unregistration functionality and button presses are simulated through timer ticks incrementing every 15 seconds.</span>
rspelta 0:e9b834175c38 240
rspelta 0:e9b834175c38 241 <span class="notes">**Note:** To see how different targets are built please see the supplied `build_all.sh script`.</span>
rspelta 0:e9b834175c38 242
rspelta 0:e9b834175c38 243
rspelta 0:e9b834175c38 244 ### Client credentials
rspelta 0:e9b834175c38 245
rspelta 0:e9b834175c38 246 To register the application with the mbed Device Connector service, you need to create and set the client side certificate.
rspelta 0:e9b834175c38 247
rspelta 0:e9b834175c38 248 1. Go to [mbed Device Connector](https://connector.mbed.com) and log in with your mbed account.
rspelta 0:e9b834175c38 249 1. On mbed Device Connector, go to [My Devices > Security credentials](https://connector.mbed.com/#credentials) and click the **Get my device security credentials** to get new credentials for your device.
rspelta 0:e9b834175c38 250 1. Replace the contents in the `security.h` file of this project's folder with the content copied above.
rspelta 0:e9b834175c38 251
rspelta 0:e9b834175c38 252 ### IP address setup
rspelta 0:e9b834175c38 253
rspelta 0:e9b834175c38 254 This example uses IPv4 to communicate with the [mbed Device Connector Server](https://api.connector.mbed.com) except for 6LoWPAN ND and Thread. However, you can easily change it to IPv6 by changing the `mbed_app.json` you make:
rspelta 0:e9b834175c38 255
rspelta 0:e9b834175c38 256 ```
rspelta 0:e9b834175c38 257 "target_overrides": {
rspelta 0:e9b834175c38 258 "*": {
rspelta 0:e9b834175c38 259 "target.features_add": ["LWIP", "NANOSTACK", "COMMON_PAL"],
rspelta 0:e9b834175c38 260 "lwip.ipv4-enabled": false,
rspelta 0:e9b834175c38 261 "lwip.ipv6-enabled": true,
rspelta 0:e9b834175c38 262 "mbed-trace.enable": 0
rspelta 0:e9b834175c38 263 }
rspelta 0:e9b834175c38 264 ```
rspelta 0:e9b834175c38 265
rspelta 0:e9b834175c38 266 by modifying the `ipv4-enabled` or `ipv6-enabled` to `true/false`. Only one should be true.
rspelta 0:e9b834175c38 267
rspelta 0:e9b834175c38 268 The example program should automatically get an IP address from the router when connected over Ethernet or WiFi.
rspelta 0:e9b834175c38 269
rspelta 0:e9b834175c38 270 If your network does not have DHCP enabled, you have to manually assign a static IP address to the board. We recommend having DHCP enabled to make everything run smoothly.
rspelta 0:e9b834175c38 271
rspelta 0:e9b834175c38 272 ### Changing the socket type
rspelta 0:e9b834175c38 273
rspelta 0:e9b834175c38 274 Your device can connect to mbed Device Connector via UDP or TCP binding mode. The default and only allowed value is UDP for Thread and 6LoWPAN. TCP is the default for other connections. The binding mode cannot be changed in 6LoWPAN ND or Thread mode.
rspelta 0:e9b834175c38 275
rspelta 0:e9b834175c38 276 To change the binding mode:
rspelta 0:e9b834175c38 277
rspelta 0:e9b834175c38 278 1. In the `simpleclient.h` file, find the parameter `SOCKET_MODE`. The default is `M2MInterface::UDP` for mesh and `M2MInterface::TCP` for others.
rspelta 0:e9b834175c38 279 1. To switch to UDP, change it to `M2MInterface::UDP`.
rspelta 0:e9b834175c38 280 1. Rebuild and flash the application.
rspelta 0:e9b834175c38 281
rspelta 0:e9b834175c38 282 <span class="tips">**Tip:** The instructions in this document remain the same, irrespective of the socket mode you select.</span>
rspelta 0:e9b834175c38 283
rspelta 0:e9b834175c38 284 Possible socket types per connection:
rspelta 0:e9b834175c38 285
rspelta 0:e9b834175c38 286 | Network interface | UDP | TCP |
rspelta 0:e9b834175c38 287 | ------------------------------|:-----:|:-----:|
rspelta 0:e9b834175c38 288 | Ethernet (IPv4) | X | X |
rspelta 0:e9b834175c38 289 | Ethernet (IPv6) | X | |
rspelta 0:e9b834175c38 290 | Wifi (IPv4) | X | X |
rspelta 0:e9b834175c38 291 | Wifi (IPv6) - Not supported | | |
rspelta 0:e9b834175c38 292 | 6LoWPAN/Thread (IPv6) | X | |
rspelta 0:e9b834175c38 293
rspelta 0:e9b834175c38 294 ## Building the example
rspelta 0:e9b834175c38 295
rspelta 0:e9b834175c38 296 To build the example using mbed CLI:
rspelta 0:e9b834175c38 297
rspelta 0:e9b834175c38 298 1. Open a command line tool and navigate to the project’s directory.
rspelta 0:e9b834175c38 299
rspelta 0:e9b834175c38 300 2. Import this example:
rspelta 0:e9b834175c38 301
rspelta 0:e9b834175c38 302 ```
rspelta 0:e9b834175c38 303 mbed import mbed-os-example-client
rspelta 0:e9b834175c38 304 ```
rspelta 0:e9b834175c38 305
rspelta 0:e9b834175c38 306 3. To build the application, select the hardware board and build the toolchain using the command:
rspelta 0:e9b834175c38 307
rspelta 0:e9b834175c38 308 (Specify the config file in the build command, for example for 6LoWPAN)
rspelta 0:e9b834175c38 309
rspelta 0:e9b834175c38 310 ```
rspelta 0:e9b834175c38 311 mbed compile -m K64F -t GCC_ARM -c --app-config configs/6lowpan_Atmel_RF.json
rspelta 0:e9b834175c38 312 ```
rspelta 0:e9b834175c38 313
rspelta 0:e9b834175c38 314 If you are using either of the following configurations remember to copy .mbedignore as well:
rspelta 0:e9b834175c38 315
rspelta 0:e9b834175c38 316 ```
rspelta 0:e9b834175c38 317 configs/eth_*
rspelta 0:e9b834175c38 318 configs/wifi_*
rspelta 0:e9b834175c38 319 ```
rspelta 0:e9b834175c38 320
rspelta 0:e9b834175c38 321 ```
rspelta 0:e9b834175c38 322 cp configs/eth-wifi-mbedignore ./.mbedignore
rspelta 0:e9b834175c38 323 ```
rspelta 0:e9b834175c38 324
rspelta 0:e9b834175c38 325 mbed CLI builds a binary file under the project’s `BUILD/` directory.
rspelta 0:e9b834175c38 326
rspelta 0:e9b834175c38 327 4. Plug the Ethernet cable into the board if you are using Ethernet mode.
rspelta 0:e9b834175c38 328
rspelta 0:e9b834175c38 329 5. If you are using 6LoWPAN ND or Thread mode, connect and power on the gateway first.
rspelta 0:e9b834175c38 330
rspelta 0:e9b834175c38 331 6. Plug the micro-USB cable into the **OpenSDA** port. The board is listed as a mass-storage device.
rspelta 0:e9b834175c38 332
rspelta 0:e9b834175c38 333 7. Drag the binary `BUILD/K64F/GCC_ARM/mbed-os-example-client.bin` to the board to flash the application.
rspelta 0:e9b834175c38 334
rspelta 0:e9b834175c38 335 8. The board is automatically programmed with the new binary. A flashing LED on it indicates that it is still working. When the LED stops blinking, the board is ready to work.
rspelta 0:e9b834175c38 336
rspelta 0:e9b834175c38 337 9. Press the **Reset** button on the board to run the program.
rspelta 0:e9b834175c38 338
rspelta 0:e9b834175c38 339 10. For verification, continue to the [Monitoring the application](#monitoring-the-application) chapter.
rspelta 0:e9b834175c38 340
rspelta 0:e9b834175c38 341 **To build the example using the Online IDE:**
rspelta 0:e9b834175c38 342
rspelta 0:e9b834175c38 343 Import this repository in the Online IDE and continue from step 3 onwards.
rspelta 0:e9b834175c38 344
rspelta 0:e9b834175c38 345 ## Monitoring the application
rspelta 0:e9b834175c38 346
rspelta 0:e9b834175c38 347 The application prints debug messages over the serial port, so you can monitor its activity with a serial port monitor. The application uses baud rate 115200.
rspelta 0:e9b834175c38 348
rspelta 0:e9b834175c38 349 <span class="notes">**Note:** Instructions to set this up are located [here](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications).</span>
rspelta 0:e9b834175c38 350
rspelta 0:e9b834175c38 351 After connecting, you should see messages about connecting to mbed Device Connector:
rspelta 0:e9b834175c38 352
rspelta 0:e9b834175c38 353 ```
rspelta 0:e9b834175c38 354 Starting mbed Client example
rspelta 0:e9b834175c38 355 [EasyConnect] IPv4 mode
rspelta 0:e9b834175c38 356 [EasyConnect] Using Ethernet
rspelta 0:e9b834175c38 357 [EasyConnect] Connected to Network successfully
rspelta 0:e9b834175c38 358 [EasyConnect] IP address 192.168.8.110
rspelta 0:e9b834175c38 359 [EasyConnect] MAC address 5c:cf:7f:86:de:bf
rspelta 0:e9b834175c38 360
rspelta 0:e9b834175c38 361 SOCKET_MODE : TCP
rspelta 0:e9b834175c38 362
rspelta 0:e9b834175c38 363 Connecting to coap://api.connector.mbed.com:5684
rspelta 0:e9b834175c38 364
rspelta 0:e9b834175c38 365 Registered object succesfully!
rspelta 0:e9b834175c38 366 ```
rspelta 0:e9b834175c38 367
rspelta 0:e9b834175c38 368 <span class="notes">**Note:** Device name is the endpoint name you will need later on when [testing the application](https://github.com/ARMmbed/mbed-os-example-client#testing-the-application).</span>
rspelta 0:e9b834175c38 369
rspelta 0:e9b834175c38 370 When you press the **SW2** button on your board you should see messages about the value changes:
rspelta 0:e9b834175c38 371
rspelta 0:e9b834175c38 372 ```
rspelta 0:e9b834175c38 373 handle_button_click, new value of counter is 1
rspelta 0:e9b834175c38 374 ```
rspelta 0:e9b834175c38 375
rspelta 0:e9b834175c38 376 ## Testing the application
rspelta 0:e9b834175c38 377
rspelta 0:e9b834175c38 378 1. Flash the application.
rspelta 0:e9b834175c38 379 2. Verify that the registration succeeded. You should see `Registered object successfully!` printed to the serial port.
rspelta 0:e9b834175c38 380 3. On mbed Device Connector, go to [My devices > Connected devices](https://connector.mbed.com/#endpoints). Your device should be listed here.
rspelta 0:e9b834175c38 381 4. Press the **SW2** button on the device a number of times (make a note of how many times you did that).
rspelta 0:e9b834175c38 382 5. Go to [Device Connector > API Console](https://connector.mbed.com/#console).
rspelta 0:e9b834175c38 383 6. Click the **Endpoint directory lookups** drop down menu.
rspelta 0:e9b834175c38 384 ![](/docs/img/ep_lookup.PNG)
rspelta 0:e9b834175c38 385 7. In the menu, click **GET** next to **Endpoint's resource representation**. Select your _endpoint_ and _resource-path_. For example, the _endpoint_ is the identifier of your endpoint that can be found in the `security.h` file as `MBED_ENDPOINT_NAME`. Select `3200/0/5501`as a resource path and click **TEST API**.
rspelta 0:e9b834175c38 386 8. The number of times you pressed **SW2** is shown.
rspelta 0:e9b834175c38 387 9. Press the **SW3** button to unregister from mbed Device Connector. You should see `Unregistered Object Successfully` printed to the serial port and the LED starts blinking. This will also stop your application. Press the **Reset** button to run the program again.
rspelta 0:e9b834175c38 388
rspelta 0:e9b834175c38 389 <span class="notes">**Note:** On non-K64F boards, there is no unregistration functionality and button presses are simulated through timer ticks incrementing every 15 seconds.</span>
rspelta 0:e9b834175c38 390
rspelta 0:e9b834175c38 391 ![SW2 pressed five times, as shown by the API Console](clicks.png)
rspelta 0:e9b834175c38 392
rspelta 0:e9b834175c38 393 <span class="tips">**Tip:** If you get an error, for example `Server Response: 410 (Gone)`, clear your browser's cache, log out, and log back in.</span>
rspelta 0:e9b834175c38 394
rspelta 0:e9b834175c38 395 <span class="notes">**Note:** Only GET methods can be executed through [Device Connector > API Console](https://connector.mbed.com/#console). For other methods, check the [mbed Device Connector Quick Start](https://github.com/ARMmbed/mbed-connector-api-node-quickstart).
rspelta 0:e9b834175c38 396
rspelta 0:e9b834175c38 397 ### Application resources
rspelta 0:e9b834175c38 398
rspelta 0:e9b834175c38 399 The application exposes three [resources](https://docs.mbed.com/docs/mbed-device-connector-web-interfaces/en/latest/#the-mbed-device-connector-data-model):
rspelta 0:e9b834175c38 400
rspelta 0:e9b834175c38 401 1. `3200/0/5501`. Number of presses of **SW2** (GET).
rspelta 0:e9b834175c38 402 2. `3201/0/5850`. Blink function, blinks **LED1** when executed (POST).
rspelta 0:e9b834175c38 403 3. `3201/0/5853`. Blink pattern, used by the blink function to determine how to blink. In the format of `1000:500:1000:500:1000:500` (PUT).
rspelta 0:e9b834175c38 404
rspelta 0:e9b834175c38 405 To learn how to get notifications when resource 1 changes, or how to use resources 2 and 3, read the [mbed Device Connector Quick Start](https://github.com/ARMmbed/mbed-connector-api-node-quickstart).
rspelta 0:e9b834175c38 406
rspelta 0:e9b834175c38 407 ## Known issues
rspelta 0:e9b834175c38 408
rspelta 0:e9b834175c38 409 ### mbed OS 5.4
rspelta 0:e9b834175c38 410
rspelta 0:e9b834175c38 411 * [UBLOX_EVK_ODIN_W2]: This example is not compiling with IAR. See [#194](https://github.com/ARMmbed/mbed-os-example-client/issues/194)
rspelta 0:e9b834175c38 412 * [NUCLEO_F429ZI]: This example is not compiling with IAR. See [#194](https://github.com/ARMmbed/mbed-os-example-client/issues/194)
rspelta 0:e9b834175c38 413
rspelta 0:e9b834175c38 414 Fix for those issues coming via; [mbed-os PR 3920] (https://github.com/ARMmbed/mbed-os/pull/3920)