mbedOS client example, modified to push X-Nucleo-IKS01A1/2 Environmental Sensor data to mbed Cloud Connector.

Dependencies:   X_NUCLEO_IKS01A1 X_NUCLEO_IKS01A2

The application is derived from the official mbedOS client example (link) and has been tested using a X-NUCLEO-IKS01A2 (default) or a X-NUCLEO-IKS01A1 motion and environmental sensors expansion board connected to a ST NUCLEO-F429ZI platform.
The following steps should be performed to make the application work:

  • Register and login into ARM mbed Connector.
  • Replace the default and empty security.h file with the one associated with your account and provided by the Connector (Security Credentials menu).
  • In order to use X-NUCLEO-IKS01A1 instead of default X-NUCLEO-IKS02A1 comment out the IKS01A2 macro definition in main.cpp file.
  • Choose NUCLEO-F429ZI as a target either from online compiler or from CLI, compile and flash.
  • Connect the board to your ethernet network, open a serial terminal (params 115200N1) and wait that the client is connected to the mbed Connector.
  • Press user button to start acquiring and pushing the environmental (pressure, temperature and humidity) data.

Note: environmental data are expressed using IPSO representation based on OMA LWM2M standard.

Committer:
nikapov
Date:
Wed Apr 26 18:23:56 2017 +0200
Revision:
0:003e60a0deb8
First version.
Original repository: https://github.com/ARMmbed/mbed-os-example-client
Version hash: 629b972f41109fd1b54bb755ea454d736a50069b

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nikapov 0:003e60a0deb8 1 # Getting started with mbed Client on mbed OS
nikapov 0:003e60a0deb8 2
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 4
nikapov 0:003e60a0deb8 5 ## Required software
nikapov 0:003e60a0deb8 6
nikapov 0:003e60a0deb8 7 * [ARM mbed account](https://developer.mbed.org/account/login/?next=/).
nikapov 0:003e60a0deb8 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).
nikapov 0:003e60a0deb8 9 * [Serial port monitor](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications).
nikapov 0:003e60a0deb8 10
nikapov 0:003e60a0deb8 11 The application:
nikapov 0:003e60a0deb8 12
nikapov 0:003e60a0deb8 13 * Connects to network with WiFi, Ethernet, 6LoWPAN ND or Thread connection.
nikapov 0:003e60a0deb8 14 * Registers with mbed Device Connector.
nikapov 0:003e60a0deb8 15 * Gives mbed Device Connector access to its resources (read and write).
nikapov 0:003e60a0deb8 16 * Records the number of clicks on the device’s button and sends the number to mbed Device Connector.
nikapov 0:003e60a0deb8 17 * Lets you control the blink pattern of the LED on the device (through mbed Device Connector).
nikapov 0:003e60a0deb8 18
nikapov 0:003e60a0deb8 19 ## Application setup
nikapov 0:003e60a0deb8 20
nikapov 0:003e60a0deb8 21 To configure the example application:
nikapov 0:003e60a0deb8 22
nikapov 0:003e60a0deb8 23 1. [Select network and board](#select-network-and-board)
nikapov 0:003e60a0deb8 24 * [Ethernet](#ethernet)
nikapov 0:003e60a0deb8 25 * [Mesh (6LoWPAN and Thread)](#mesh)
nikapov 0:003e60a0deb8 26 * [WiFi](#wifi)
nikapov 0:003e60a0deb8 27 * [Non listed boards](#non-listed-board-support)
nikapov 0:003e60a0deb8 28 1. [Set the client credentials](#client-credentials).
nikapov 0:003e60a0deb8 29 1. [Set up an IP address](#ip-address-setup). This step is optional.
nikapov 0:003e60a0deb8 30 1. [Change the socket type](#changing-the-socket-type). This step is optional.
nikapov 0:003e60a0deb8 31
nikapov 0:003e60a0deb8 32 ### Select network and board
nikapov 0:003e60a0deb8 33
nikapov 0:003e60a0deb8 34 This example supports following hardware-network combinations:
nikapov 0:003e60a0deb8 35
nikapov 0:003e60a0deb8 36 ### Ethernet
nikapov 0:003e60a0deb8 37
nikapov 0:003e60a0deb8 38 #### Supported boards
nikapov 0:003e60a0deb8 39
nikapov 0:003e60a0deb8 40 * K64F
nikapov 0:003e60a0deb8 41 * NUCLEO_F429ZI
nikapov 0:003e60a0deb8 42 * UBLOX_EVK_ODIN_W2 (use the supplied `configs/eth_v4.json`)
nikapov 0:003e60a0deb8 43
nikapov 0:003e60a0deb8 44 For running the example application using Ethernet, you need:
nikapov 0:003e60a0deb8 45
nikapov 0:003e60a0deb8 46 - An Ethernet cable.
nikapov 0:003e60a0deb8 47 - An Ethernet connection to the internet.
nikapov 0:003e60a0deb8 48
nikapov 0:003e60a0deb8 49 ### Mesh
nikapov 0:003e60a0deb8 50
nikapov 0:003e60a0deb8 51 There are example settings under the configs directory, which provide the easiest way to start with the applications.
nikapov 0:003e60a0deb8 52 The [mbed-mesh-api](https://github.com/ARMmbed/mbed-os/tree/master/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed_lib.json)
nikapov 0:003e60a0deb8 53 defines the defaults settings for applications. The most relevant parameters are described in more detail in the following sections.
nikapov 0:003e60a0deb8 54
nikapov 0:003e60a0deb8 55 #### Supported boards
nikapov 0:003e60a0deb8 56
nikapov 0:003e60a0deb8 57 * K64F + NXP MCR20 15.4 shield (mesh `NANOSTACK_FULL` mode)
nikapov 0:003e60a0deb8 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)
nikapov 0:003e60a0deb8 59 * NUCLEO_F429ZI + ATMEL AT233 15.4 shield (mesh `LOWPAN_ROUTER` mode)
nikapov 0:003e60a0deb8 60 * [Supported combinations of board and shields](#supported-combinations-of-board-and-shields)
nikapov 0:003e60a0deb8 61
nikapov 0:003e60a0deb8 62 First, you need to select the RF driver to be used by the 6LoWPAN/Thread stack.
nikapov 0:003e60a0deb8 63
nikapov 0:003e60a0deb8 64 This example supports these shields:
nikapov 0:003e60a0deb8 65
nikapov 0:003e60a0deb8 66 * [AT86RF233/212B](https://github.com/ARMmbed/atmel-rf-driver)
nikapov 0:003e60a0deb8 67 * [NXP-MCR20a](https://github.com/ARMmbed/mcr20a-rf-driver)
nikapov 0:003e60a0deb8 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)
nikapov 0:003e60a0deb8 69
nikapov 0:003e60a0deb8 70 To select the radio shield make sure that the `mbed_app.json` file points to the correct radio driver type:
nikapov 0:003e60a0deb8 71
nikapov 0:003e60a0deb8 72 ```json
nikapov 0:003e60a0deb8 73 "mesh_radio_type": {
nikapov 0:003e60a0deb8 74 "help": "options are ATMEL, MCR20, SPIRIT1",
nikapov 0:003e60a0deb8 75 "value": "ATMEL"
nikapov 0:003e60a0deb8 76 },
nikapov 0:003e60a0deb8 77 ```
nikapov 0:003e60a0deb8 78
nikapov 0:003e60a0deb8 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:
nikapov 0:003e60a0deb8 80
nikapov 0:003e60a0deb8 81 ```
nikapov 0:003e60a0deb8 82 "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
nikapov 0:003e60a0deb8 83 ```
nikapov 0:003e60a0deb8 84
nikapov 0:003e60a0deb8 85 If your connection type is `MESH_THREAD` then you may want to use the `THREAD_ROUTER` configuration:
nikapov 0:003e60a0deb8 86
nikapov 0:003e60a0deb8 87 ```
nikapov 0:003e60a0deb8 88 "target.features_add": ["NANOSTACK", "THREAD_ROUTER", "COMMON_PAL"],
nikapov 0:003e60a0deb8 89 ```
nikapov 0:003e60a0deb8 90
nikapov 0:003e60a0deb8 91 Since 6LoWPAN ND and Thread use IPv6 for connectivity, you need to verify first that you have a working IPv6 connection.
nikapov 0:003e60a0deb8 92 To do that, ping the Connector IPv6 address `2607:f0d0:2601:52::20` from your network.
nikapov 0:003e60a0deb8 93
nikapov 0:003e60a0deb8 94 #### Compile configuration for Spirit1
nikapov 0:003e60a0deb8 95
nikapov 0:003e60a0deb8 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>
nikapov 0:003e60a0deb8 97
nikapov 0:003e60a0deb8 98 ```json
nikapov 0:003e60a0deb8 99 "target_overrides": {
nikapov 0:003e60a0deb8 100 "*": {
nikapov 0:003e60a0deb8 101 "spirit1.mac-address": "{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7}"
nikapov 0:003e60a0deb8 102 },
nikapov 0:003e60a0deb8 103 }
nikapov 0:003e60a0deb8 104 ```
nikapov 0:003e60a0deb8 105
nikapov 0:003e60a0deb8 106 #### Channel settings
nikapov 0:003e60a0deb8 107
nikapov 0:003e60a0deb8 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 mbed gateway settings. The application can override these settings by adding them to the `.json` file. For example:
nikapov 0:003e60a0deb8 109
nikapov 0:003e60a0deb8 110 ```json
nikapov 0:003e60a0deb8 111 "target_overrides": {
nikapov 0:003e60a0deb8 112 "*": {
nikapov 0:003e60a0deb8 113 "mbed-mesh-api.6lowpan-nd-channel-page": 0,
nikapov 0:003e60a0deb8 114 "mbed-mesh-api.6lowpan-nd-channel": 12,
nikapov 0:003e60a0deb8 115 "mbed-mesh-api.thread-config-channel-page": 0,
nikapov 0:003e60a0deb8 116 "mbed-mesh-api.thread-config-channel": 22
nikapov 0:003e60a0deb8 117 }
nikapov 0:003e60a0deb8 118 }
nikapov 0:003e60a0deb8 119 ```
nikapov 0:003e60a0deb8 120
nikapov 0:003e60a0deb8 121 For sub-GHz shields ([Spirit1](https://github.com/ARMmbed/stm-spirit1-rf-driver) or AT86RF212B) use the following overrides, **6LoWPAN ND only**:
nikapov 0:003e60a0deb8 122
nikapov 0:003e60a0deb8 123 ```json
nikapov 0:003e60a0deb8 124 "mbed-mesh-api.6lowpan-nd-channel-page": 2,
nikapov 0:003e60a0deb8 125 "mbed-mesh-api.6lowpan-nd-channel": 1
nikapov 0:003e60a0deb8 126 ```
nikapov 0:003e60a0deb8 127
nikapov 0:003e60a0deb8 128 For more information about the radio shields, see [the related documentation](docs/radio_module_identify.md).
nikapov 0:003e60a0deb8 129
nikapov 0:003e60a0deb8 130 =======
nikapov 0:003e60a0deb8 131 #### Supported combinations of board and shields
nikapov 0:003e60a0deb8 132
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 134
nikapov 0:003e60a0deb8 135 #### Border router
nikapov 0:003e60a0deb8 136
nikapov 0:003e60a0deb8 137 There are two options for border router.
nikapov 0:003e60a0deb8 138
nikapov 0:003e60a0deb8 139 ##### Nanostack-border-router
nikapov 0:003e60a0deb8 140
nikapov 0:003e60a0deb8 141 You can configure and build the [nanostack-border-router](https://github.com/ARMmbed/nanostack-border-router) for the 6LoWPAN ND or Thread mode.
nikapov 0:003e60a0deb8 142
nikapov 0:003e60a0deb8 143 ##### mbed gateway
nikapov 0:003e60a0deb8 144
nikapov 0:003e60a0deb8 145 The mbed gateway is a binary release only.
nikapov 0:003e60a0deb8 146
nikapov 0:003e60a0deb8 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:
nikapov 0:003e60a0deb8 148
nikapov 0:003e60a0deb8 149 1. Use an Ethernet cable to connect the mbed 6LoWPAN gateway router to the internet.
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 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:
nikapov 0:003e60a0deb8 152
nikapov 0:003e60a0deb8 153 * For the **6LoWPAN ND** bootstrap, use `gateway6LoWPANDynamic.bin`.
nikapov 0:003e60a0deb8 154 * For the **Thread** bootstrap, use `gatewayThreadDynamic.bin`.
nikapov 0:003e60a0deb8 155
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 157
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 159
nikapov 0:003e60a0deb8 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`.
nikapov 0:003e60a0deb8 161
nikapov 0:003e60a0deb8 162 #### Thread-specific settings
nikapov 0:003e60a0deb8 163
nikapov 0:003e60a0deb8 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:
nikapov 0:003e60a0deb8 165
nikapov 0:003e60a0deb8 166 ```json
nikapov 0:003e60a0deb8 167 "mbed-mesh-api.thread-device-type": "MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE"
nikapov 0:003e60a0deb8 168 ```
nikapov 0:003e60a0deb8 169
nikapov 0:003e60a0deb8 170 ## WiFi
nikapov 0:003e60a0deb8 171
nikapov 0:003e60a0deb8 172 #### Supported boards
nikapov 0:003e60a0deb8 173
nikapov 0:003e60a0deb8 174 * UBLOX_EVK_ODIN_W2. Check instructions for compilation [here](#compile-configuration-for-odin-wifi).
nikapov 0:003e60a0deb8 175 * K64F + GROVE SEEED shield using [ESP8266](https://en.wikipedia.org/wiki/ESP8266) WiFi module.
nikapov 0:003e60a0deb8 176 * NUCLEO_F429ZI + GROVE SEEED shield using [ESP8266](https://en.wikipedia.org/wiki/ESP8266) WiFi module.
nikapov 0:003e60a0deb8 177
nikapov 0:003e60a0deb8 178 To run this application using ESP8266 WiFi Interface, you need:
nikapov 0:003e60a0deb8 179
nikapov 0:003e60a0deb8 180 1. An [ESP8266](https://en.wikipedia.org/wiki/ESP8266) WiFi module.
nikapov 0:003e60a0deb8 181 1. Updated [Espressif Firmware](https://developer.mbed.org/teams/ESP8266/wiki/Firmware-Update).
nikapov 0:003e60a0deb8 182 1. Mount the WiFi module onto [K64F Grove Shield v2](https://developer.mbed.org/platforms/FRDM-K64F/#supported-seeed-studio-grove-extension).
nikapov 0:003e60a0deb8 183 1. Attach the shield on your board.
nikapov 0:003e60a0deb8 184 1. In the `mbed_app.json` file, change:
nikapov 0:003e60a0deb8 185
nikapov 0:003e60a0deb8 186 ```json
nikapov 0:003e60a0deb8 187 "network-interface": {
nikapov 0:003e60a0deb8 188 "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.",
nikapov 0:003e60a0deb8 189 "value": "WIFI"
nikapov 0:003e60a0deb8 190 }
nikapov 0:003e60a0deb8 191 ```
nikapov 0:003e60a0deb8 192
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 194
nikapov 0:003e60a0deb8 195 ```json
nikapov 0:003e60a0deb8 196 "wifi-ssid": {
nikapov 0:003e60a0deb8 197 "help": "WiFi SSID",
nikapov 0:003e60a0deb8 198 "value": "\"SSID\""
nikapov 0:003e60a0deb8 199 },
nikapov 0:003e60a0deb8 200 "wifi-password": {
nikapov 0:003e60a0deb8 201 "help": "WiFi Password",
nikapov 0:003e60a0deb8 202 "value": "\"Password\""
nikapov 0:003e60a0deb8 203 }
nikapov 0:003e60a0deb8 204 ```
nikapov 0:003e60a0deb8 205
nikapov 0:003e60a0deb8 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>
nikapov 0:003e60a0deb8 207
nikapov 0:003e60a0deb8 208 For example, NUCLEO_F401RE requires a different serial connection:
nikapov 0:003e60a0deb8 209
nikapov 0:003e60a0deb8 210 ```json
nikapov 0:003e60a0deb8 211 "wifi-tx": {
nikapov 0:003e60a0deb8 212 "help": "TX pin for serial connection to external device",
nikapov 0:003e60a0deb8 213 "value": "PA_11"
nikapov 0:003e60a0deb8 214 },
nikapov 0:003e60a0deb8 215 "wifi-rx": {
nikapov 0:003e60a0deb8 216 "help": "RX pin for serial connection to external device",
nikapov 0:003e60a0deb8 217 "value": "PA_12"
nikapov 0:003e60a0deb8 218 }
nikapov 0:003e60a0deb8 219 ```
nikapov 0:003e60a0deb8 220
nikapov 0:003e60a0deb8 221 #### Compile configuration for ODIN WiFi
nikapov 0:003e60a0deb8 222
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 224
nikapov 0:003e60a0deb8 225 This should resolve the issue:
nikapov 0:003e60a0deb8 226
nikapov 0:003e60a0deb8 227 ```
nikapov 0:003e60a0deb8 228 cp configs/eth-wifi-mbedignore ./.mbedignore
nikapov 0:003e60a0deb8 229 ```
nikapov 0:003e60a0deb8 230
nikapov 0:003e60a0deb8 231 ### Non listed board support
nikapov 0:003e60a0deb8 232
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 234
nikapov 0:003e60a0deb8 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/).
nikapov 0:003e60a0deb8 236
nikapov 0:003e60a0deb8 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).
nikapov 0:003e60a0deb8 238
nikapov 0:003e60a0deb8 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>
nikapov 0:003e60a0deb8 240
nikapov 0:003e60a0deb8 241 <span class="notes">**Note:** To see how different targets are built please see the supplied `build_all.sh script`.</span>
nikapov 0:003e60a0deb8 242
nikapov 0:003e60a0deb8 243
nikapov 0:003e60a0deb8 244 ### Client credentials
nikapov 0:003e60a0deb8 245
nikapov 0:003e60a0deb8 246 To register the application with the mbed Device Connector service, you need to create and set the client side certificate.
nikapov 0:003e60a0deb8 247
nikapov 0:003e60a0deb8 248 1. Go to [mbed Device Connector](https://connector.mbed.com) and log in with your mbed account.
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 250 1. Replace the contents in the `security.h` file of this project's folder with the content copied above.
nikapov 0:003e60a0deb8 251
nikapov 0:003e60a0deb8 252 ### IP address setup
nikapov 0:003e60a0deb8 253
nikapov 0:003e60a0deb8 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:
nikapov 0:003e60a0deb8 255
nikapov 0:003e60a0deb8 256 ```
nikapov 0:003e60a0deb8 257 "target_overrides": {
nikapov 0:003e60a0deb8 258 "*": {
nikapov 0:003e60a0deb8 259 "target.features_add": ["LWIP", "NANOSTACK", "COMMON_PAL"],
nikapov 0:003e60a0deb8 260 "lwip.ipv4-enabled": false,
nikapov 0:003e60a0deb8 261 "lwip.ipv6-enabled": true,
nikapov 0:003e60a0deb8 262 "mbed-trace.enable": 0
nikapov 0:003e60a0deb8 263 }
nikapov 0:003e60a0deb8 264 ```
nikapov 0:003e60a0deb8 265
nikapov 0:003e60a0deb8 266 by modifying the `ipv4-enabled` or `ipv6-enabled` to `true/false`. Only one should be true.
nikapov 0:003e60a0deb8 267
nikapov 0:003e60a0deb8 268 The example program should automatically get an IP address from the router when connected over Ethernet or WiFi.
nikapov 0:003e60a0deb8 269
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 271
nikapov 0:003e60a0deb8 272 ### Changing the socket type
nikapov 0:003e60a0deb8 273
nikapov 0:003e60a0deb8 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.
nikapov 0:003e60a0deb8 275
nikapov 0:003e60a0deb8 276 To change the binding mode:
nikapov 0:003e60a0deb8 277
nikapov 0:003e60a0deb8 278 1. In the `simpleclient.h` file, find the parameter `SOCKET_MODE`. The default is `M2MInterface::UDP` for mesh and `M2MInterface::TCP` for others.
nikapov 0:003e60a0deb8 279 1. To switch to UDP, change it to `M2MInterface::UDP`.
nikapov 0:003e60a0deb8 280 1. Rebuild and flash the application.
nikapov 0:003e60a0deb8 281
nikapov 0:003e60a0deb8 282 <span class="tips">**Tip:** The instructions in this document remain the same, irrespective of the socket mode you select.</span>
nikapov 0:003e60a0deb8 283
nikapov 0:003e60a0deb8 284 Possible socket types per connection:
nikapov 0:003e60a0deb8 285
nikapov 0:003e60a0deb8 286 | Network interface | UDP | TCP |
nikapov 0:003e60a0deb8 287 | ------------------------------|:-----:|:-----:|
nikapov 0:003e60a0deb8 288 | Ethernet (IPv4) | X | X |
nikapov 0:003e60a0deb8 289 | Ethernet (IPv6) | X | |
nikapov 0:003e60a0deb8 290 | Wifi (IPv4) | X | X |
nikapov 0:003e60a0deb8 291 | Wifi (IPv6) - Not supported | | |
nikapov 0:003e60a0deb8 292 | 6LoWPAN/Thread (IPv6) | X | |
nikapov 0:003e60a0deb8 293
nikapov 0:003e60a0deb8 294 ## Building the example
nikapov 0:003e60a0deb8 295
nikapov 0:003e60a0deb8 296 To build the example using mbed CLI:
nikapov 0:003e60a0deb8 297
nikapov 0:003e60a0deb8 298 1. Open a command line tool and navigate to the project’s directory.
nikapov 0:003e60a0deb8 299
nikapov 0:003e60a0deb8 300 2. Import this example:
nikapov 0:003e60a0deb8 301
nikapov 0:003e60a0deb8 302 ```
nikapov 0:003e60a0deb8 303 mbed import mbed-os-example-client
nikapov 0:003e60a0deb8 304 ```
nikapov 0:003e60a0deb8 305
nikapov 0:003e60a0deb8 306 3. To build the application, select the hardware board and build the toolchain using the command:
nikapov 0:003e60a0deb8 307
nikapov 0:003e60a0deb8 308 Specify the config file in the build command, for example for 6LoWPAN
nikapov 0:003e60a0deb8 309
nikapov 0:003e60a0deb8 310 ```
nikapov 0:003e60a0deb8 311 mbed compile -m K64F -t GCC_ARM -c --app-config configs/6lowpan_Atmel_RF.json
nikapov 0:003e60a0deb8 312 ```
nikapov 0:003e60a0deb8 313
nikapov 0:003e60a0deb8 314 mbed CLI builds a binary file under the project’s `BUILD/` directory.
nikapov 0:003e60a0deb8 315
nikapov 0:003e60a0deb8 316 4. Plug the Ethernet cable into the board if you are using Ethernet mode.
nikapov 0:003e60a0deb8 317
nikapov 0:003e60a0deb8 318 5. If you are using 6LoWPAN ND or Thread mode, connect and power on the gateway first.
nikapov 0:003e60a0deb8 319
nikapov 0:003e60a0deb8 320 6. Plug the micro-USB cable into the **OpenSDA** port. The board is listed as a mass-storage device.
nikapov 0:003e60a0deb8 321
nikapov 0:003e60a0deb8 322 7. Drag the binary `BUILD/K64F/GCC_ARM/mbed-os-example-client.bin` to the board to flash the application.
nikapov 0:003e60a0deb8 323
nikapov 0:003e60a0deb8 324 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.
nikapov 0:003e60a0deb8 325
nikapov 0:003e60a0deb8 326 9. Press the **Reset** button on the board to run the program.
nikapov 0:003e60a0deb8 327
nikapov 0:003e60a0deb8 328 10. For verification, continue to the [Monitoring the application](#monitoring-the-application) chapter.
nikapov 0:003e60a0deb8 329
nikapov 0:003e60a0deb8 330 **To build the example using the Online IDE:**
nikapov 0:003e60a0deb8 331
nikapov 0:003e60a0deb8 332 Import this repository in the Online IDE and continue from step 3 onwards.
nikapov 0:003e60a0deb8 333
nikapov 0:003e60a0deb8 334 ## Monitoring the application
nikapov 0:003e60a0deb8 335
nikapov 0:003e60a0deb8 336 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.
nikapov 0:003e60a0deb8 337
nikapov 0:003e60a0deb8 338 <span class="notes">**Note:** Instructions to set this up are located [here](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications).</span>
nikapov 0:003e60a0deb8 339
nikapov 0:003e60a0deb8 340 After connecting, you should see messages about connecting to mbed Device Connector:
nikapov 0:003e60a0deb8 341
nikapov 0:003e60a0deb8 342 ```
nikapov 0:003e60a0deb8 343 Starting mbed Client example in IPv4 mode
nikapov 0:003e60a0deb8 344 [EasyConnect] Using Ethernet
nikapov 0:003e60a0deb8 345 [EasyConnect] Connected to Network successfully
nikapov 0:003e60a0deb8 346 [EasyConnect] IP address 192.168.8.110
nikapov 0:003e60a0deb8 347 [EasyConnect] MAC address 5c:cf:7f:86:de:bf
nikapov 0:003e60a0deb8 348
nikapov 0:003e60a0deb8 349 SOCKET_MODE : TCP
nikapov 0:003e60a0deb8 350
nikapov 0:003e60a0deb8 351 Connecting to coap://api.connector.mbed.com:5684
nikapov 0:003e60a0deb8 352
nikapov 0:003e60a0deb8 353 Registered object succesfully!
nikapov 0:003e60a0deb8 354 ```
nikapov 0:003e60a0deb8 355
nikapov 0:003e60a0deb8 356 <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>
nikapov 0:003e60a0deb8 357
nikapov 0:003e60a0deb8 358 When you press the **SW2** button on your board you should see messages about the value changes:
nikapov 0:003e60a0deb8 359
nikapov 0:003e60a0deb8 360 ```
nikapov 0:003e60a0deb8 361 handle_button_click, new value of counter is 1
nikapov 0:003e60a0deb8 362 ```
nikapov 0:003e60a0deb8 363
nikapov 0:003e60a0deb8 364 ## Testing the application
nikapov 0:003e60a0deb8 365
nikapov 0:003e60a0deb8 366 1. Flash the application.
nikapov 0:003e60a0deb8 367 2. Verify that the registration succeeded. You should see `Registered object successfully!` printed to the serial port.
nikapov 0:003e60a0deb8 368 3. On mbed Device Connector, go to [My devices > Connected devices](https://connector.mbed.com/#endpoints). Your device should be listed here.
nikapov 0:003e60a0deb8 369 4. Press the **SW2** button on the device a number of times (make a note of how many times you did that).
nikapov 0:003e60a0deb8 370 5. Go to [Device Connector > API Console](https://connector.mbed.com/#console).
nikapov 0:003e60a0deb8 371 6. Click the **Endpoint directory lookups** drop down menu.
nikapov 0:003e60a0deb8 372 ![](/docs/img/ep_lookup.PNG)
nikapov 0:003e60a0deb8 373 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**.
nikapov 0:003e60a0deb8 374 8. The number of times you pressed **SW2** is shown.
nikapov 0:003e60a0deb8 375 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.
nikapov 0:003e60a0deb8 376
nikapov 0:003e60a0deb8 377 <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>
nikapov 0:003e60a0deb8 378
nikapov 0:003e60a0deb8 379 ![SW2 pressed five times, as shown by the API Console](clicks.png)
nikapov 0:003e60a0deb8 380
nikapov 0:003e60a0deb8 381 <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>
nikapov 0:003e60a0deb8 382
nikapov 0:003e60a0deb8 383 <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).
nikapov 0:003e60a0deb8 384
nikapov 0:003e60a0deb8 385 ### Application resources
nikapov 0:003e60a0deb8 386
nikapov 0:003e60a0deb8 387 The application exposes three [resources](https://docs.mbed.com/docs/mbed-device-connector-web-interfaces/en/latest/#the-mbed-device-connector-data-model):
nikapov 0:003e60a0deb8 388
nikapov 0:003e60a0deb8 389 1. `3200/0/5501`. Number of presses of **SW2** (GET).
nikapov 0:003e60a0deb8 390 2. `3201/0/5850`. Blink function, blinks **LED1** when executed (POST).
nikapov 0:003e60a0deb8 391 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).
nikapov 0:003e60a0deb8 392
nikapov 0:003e60a0deb8 393 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).
nikapov 0:003e60a0deb8 394
nikapov 0:003e60a0deb8 395 ## Known issues
nikapov 0:003e60a0deb8 396
nikapov 0:003e60a0deb8 397 ### mbed OS 5.4
nikapov 0:003e60a0deb8 398
nikapov 0:003e60a0deb8 399 * [UBLOX_EVK_ODIN_W2]: This example is not compiling with IAR. See [#194](https://github.com/ARMmbed/mbed-os-example-client/issues/194)
nikapov 0:003e60a0deb8 400 * [NUCLEO_F429ZI]: This example is not compiling with IAR. See [#194](https://github.com/ARMmbed/mbed-os-example-client/issues/194)
nikapov 0:003e60a0deb8 401
nikapov 0:003e60a0deb8 402 Fix for those issues coming via; [mbed-os PR 3920] (https://github.com/ARMmbed/mbed-os/pull/3920)