This is a simple mbed client example demonstrating, registration of a device with mbed Device Connector and reading and writing values as well as deregistering on different Network Interfaces including Ethernet, WiFi, 6LoWPAN ND and Thread respectively.

Getting started with mbed Client on mbed OS

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 WiFi, Ethernet, 6LoWPAN ND or Thread connection.
  • Registers with mbed Device Connector.
  • Gives mbed Device Connector access to its resources (read and write).
  • Records the number of clicks on the device’s button and sends the number to mbed Device Connector.
  • Lets you control the blink pattern of the LED on the device (through mbed Device Connector).

Required hardware

  • K64F board.
  • 1-2 micro-USB cables.
  • mbed 6LoWPAN gateway router for 6LoWPAN ND and Thread.
  • mbed 6LoWPAN shield (AT86RF212B/AT86RF233 for 6LoWPAN ND and Thread.
  • Ethernet cable and connection to the internet.

Requirements for non K64F board

This example application is primarily designed for FRDM-K64F board but you can also use other mbed OS supported boards to run this example application , with some minor modifications for setup.

  • To get the application registering successfully on non K64F boards , you need Edit the mbed_app.json file to add NULL_ENTROPY feature for mbedTLS:

""macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_mbed_client_config.h\"",
            "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES",
            "MBEDTLS_TEST_NULL_ENTROPY"],
  • On non K64F boards, there is no unregistration functionality and button press is simulated through timer ticks incrementing every 15 seconds.

Application setup

To configure the example application, please check following:

Connection type

The application uses Ethernet as the default connection type. To change the connection type, set one of them in mbed_app.json. For example, to enable 6LoWPAN ND mode:

    "network-interface": {
        "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.",
        "value": "MESH_LOWPAN_ND"
    }

Client credentials

To register the application to the Connector service, you need to create and set the client side certificate.

  • Go to mbed Device Connector and log in with your mbed account.
  • On mbed Device Connector, go to My Devices > Security credentials and click the Get my device security credentials button to get new credentials for your device.
  • Replace the contents in `security.h` of this project's directory with content copied above.

6LoWPAN ND and Thread settings

First you need to select the RF driver to be used by 6LoWPAN/Thread stack.

For example Atmel AT86RF233/212B driver is located in https://github.com/ARMmbed/atmel-rf-driver

To add that driver to you application , import library from following URL:

https://github.com/ARMmbed/atmel-rf-driver

Then you need to enable the IPV6 functionality as the 6LoWPAN and Thread are part of IPv6 stack. Edit the mbed_app.json file to add IPV6 feature:

"target.features_add": ["CLIENT", "IPV6", "COMMON_PAL"],

6LoWPAN ND and Thread use IPv6 for connectivity. Therefore, you need to verify first that you have a working IPv6 connection. To do that, ping the Connector IPv6 address 2607:f0d0:2601:52::20 from your network.

mbed gateway

To connect the example application in 6LoWPAN ND or Thread mode to Connector, you need to set up an mbed 6LoWPAN gateway router as follows:

  • Use an Ethernet cable to connect the mbed 6LoWPAN gateway router to the internet.
  • Use a micro-USB cable to connect the mbed 6LoWPAN gateway router to your computer. The computer will list the router as removable storage.
  • 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:
  • For the 6LoWPAN ND bootstrap, use `gateway6LoWPANDynamic.bin`.
  • For the Thread bootstrap, use `gatewayThreadDynamic.bin`.

The dynamic binaries use IPv6 autoconfiguration and enable the client to connect to the Connector service. The static binaries create a site-local IPv6 network and packets cannot be routed outside.

  • 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.

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`.

Channel settings

The default 2.4GHz channel settings are already defined by the mbed-mesh-api to match the mbed gateway settings. The application can override these settings by adding them to the mbed_app.json file in the main project directory. For example:

    "target_overrides": {
        "*": {
            "mbed-mesh-api.6lowpan-nd-channel-page": 0,
            "mbed-mesh-api.6lowpan-nd-channel": 12,
            "mbed-mesh-api.thread-config-channel-page": 0,
            "mbed-mesh-api.thread-config-channel": 12
        }
    }

For sub-GHz shields (AT86RF212B) use the following overrides, 6LoWPAN ND only:

"mbed-mesh-api.6lowpan-nd-channel-page": 2,
"mbed-mesh-api.6lowpan-nd-channel": 1

For more information about the radio shields, see [the related documentation](docs/radio_module_identify.md). All the configurable settings can be found in the mbed-os-example-client/mbed-os/features/FEATURE_IPV6/mbed-mesh-api/mbed_lib.json file.

Thread-specific settings

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:

    "mbed-mesh-api.thread-device-type": "MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE"

Ethernet settings

For running the example application using Ethernet, you need:

  • An Ethernet cable.
  • An Ethernet connection to the internet.

Wi-Fi settings

The example application uses ESP8266 WiFi Interface for managing the wireless connectivity. To run this application using WiFi, you need:

    "network-interface": {
        "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.",
        "value": "WIFI"
    }

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.

    "wifi-ssid": {
        "help": "WiFi SSID",
        "value": "\"SSID\""
    },
    "wifi-password": {
        "help": "WiFi Password",
        "value": "\"Password\""
    }

IP address setup

This example uses IPv4 to communicate with the mbed Device Connector Server except for 6LoWPAN ND and Thread. The example program should automatically get an IPv4 address from the router when connected over Ethernet.

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.

Changing socket type

Your device can connect to mbed Device Connector via UDP or TCP binding mode. The default is UDP. The binding mode cannot be changed in 6LoWPAN ND or Thread mode.

To change the binding mode:

  • In the `simpleclient.h` file, find the parameter `SOCKET_MODE`. The default is `M2MInterface::UDP`.
  • To switch to TCP, change it to `M2MInterface::TCP`.
  • Rebuild and flash the application.

Tip: The instructions in this document remain the same, irrespective of the socket mode you select.

Monitoring the application

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.

SerialPC

After connecting, you should see messages about connecting to mbed Device Connector:

In app_start()
IP address 10.2.15.222
Device name 6868df22-d353-4150-b90a-a878130859d9

When you click the `SW2` button on your board you should see messages about the value changes:

handle_button_click, new value of counter is 1

Testing the application

  • Flash the application.
  • Verify that the registration succeeded. You should see `Registered object successfully!` printed to the serial port.
  • On mbed Device Connector, go to My devices > Connected devices. Your device should be listed here.
  • Press the `SW2` button on the device a number of times (make a note of how many times you did that).
  • Go to Device Connector > API Console.
  • Enter https://api.connector.mbed.com/endpoints/DEVICE_NAME/3200/0/5501 in the URI field and click TEST API. Replace DEVICE_NAME with your actual endpoint name. The device name can be found in the security.h file, see variable MBED_ENDPOINT_NAME or it can be found from the traces.
  • The number of times you pressed SW2 is shown.
  • 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.

For more methods check the mbed Device Connector Quick Start.

Application resources

The application exposes three resources:

  • 3200/0/5501. Number of presses of SW2 (GET).
  • 3201/0/5850. Blink function, blinks LED1 when executed (POST).
  • 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).

For information on how to get notifications when resource 1 changes, or how to use resources 2 and 3, take a look at the mbed Device Connector Quick Start.

Building this example

Building with mbed CLI

If you'd like to use mbed CLI to build this, then you should follow the instructions in the Handbook TODO - new link. The instructions here relate to using the developer.mbed.org Online Compiler

If you'd like to use the online Compiler, then you can Import this code into your compiler, select your platform from the top right, compile the code using the compile button, load it onto your board, press the reset button on the board and you code will run. See the client go online!

More instructions for using the mbed Online Compiler can be found at TODO - update this

Files at this revision

API Documentation at this revision

Comitter:
Yogesh Pande
Date:
Mon Jul 25 16:32:20 2016 +0300
Child:
1:e06e899acba6
Commit message:
Update example home repo at https://github.com/ARMmbed/mbed-os-example-client

Changed in this revision

GW_Binary/gateway6LoWPANDynamic.bin Show annotated file Show diff for this revision Revisions of this file
GW_Binary/gateway6LoWPANStatic.bin Show annotated file Show diff for this revision Revisions of this file
GW_Binary/gatewayThreadDynamic.bin Show annotated file Show diff for this revision Revisions of this file
GW_Binary/gatewayThreadStatic.bin Show annotated file Show diff for this revision Revisions of this file
LICENSE Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
apache-2.0.txt Show annotated file Show diff for this revision Revisions of this file
atmel-rf-driver.lib Show annotated file Show diff for this revision Revisions of this file
clicks.png Show annotated file Show diff for this revision Revisions of this file
docs/img/Radio_Identifications.png Show annotated file Show diff for this revision Revisions of this file
docs/img/Radio_Identifications_GW.png Show annotated file Show diff for this revision Revisions of this file
docs/radio_module_identify.md Show annotated file Show diff for this revision Revisions of this file
esp8266-driver.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
mbed_client_config.h Show annotated file Show diff for this revision Revisions of this file
security.h Show annotated file Show diff for this revision Revisions of this file
simpleclient.h Show annotated file Show diff for this revision Revisions of this file
Binary file GW_Binary/gateway6LoWPANDynamic.bin has changed
Binary file GW_Binary/gateway6LoWPANStatic.bin has changed
Binary file GW_Binary/gatewayThreadDynamic.bin has changed
Binary file GW_Binary/gatewayThreadStatic.bin has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LICENSE	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,2 @@
+Unless specifically indicated otherwise in a file, files are licensed
+under the Apache 2.0 license, as can be found in: apache-2.0.txt
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,231 @@
+# Getting started with mbed Client on mbed OS
+
+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.
+
+The application:
+
+* Connects to network with WiFi, Ethernet, 6LoWPAN ND or Thread connection.
+* Registers with mbed Device Connector.
+* Gives mbed Device Connector access to its resources (read and write).
+* Records the number of clicks on the device’s button and sends the number to mbed Device Connector.
+* Lets you control the blink pattern of the LED on the device (through mbed Device Connector).
+
+## Required hardware
+
+* [FRDM-K64F](http://developer.mbed.org/platforms/frdm-k64f/) board.
+* 1-2 micro-USB cables.
+* [mbed 6LoWPAN gateway router](https://firefly-iot.com/product/firefly-6lowpan-gateway-2-4ghz/) for 6LoWPAN ND and Thread.
+* mbed 6LoWPAN shield (AT86RF212B/[AT86RF233](https://firefly-iot.com/product/firefly-arduino-shield-2-4ghz/)) for 6LoWPAN ND and Thread.
+* Ethernet cable and connection to the internet.
+
+## Required software
+
+* [ARM mbed account](https://developer.mbed.org/account/login/?next=/).
+* [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).
+* [Serial port monitor](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications).
+
+## Application setup
+
+To configure the example application, please:
+
+1. [Select the connection type](#connection-type).
+1. [Set the client credentials](#client-credentials).
+1. [Change 6LoWPAN ND & Thread settings](#6lowpan-nd-and-thread-settings).
+1. [Change Ethernet settings](#ethernet-settings).
+1. [Change Wi-Fi settings](#wi-fi-settings).
+1. [Set up an IP address](#ip-address-setup). This step is optional.
+1. [Change the socket type](#changing-socket-type). This step is optional.
+
+### Connection type
+
+The application uses Ethernet as the default connection type. To change the connection type, set one of them in `mbed_app.json`. For example, to enable 6LoWPAN ND mode:
+
+```json
+    "network-interface": {
+        "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.",
+        "value": "MESH_LOWPAN_ND"
+    }
+```
+
+### Client credentials
+
+To register the application to the Connector service, you need to create and set the client side certificate.
+
+1. Go to [mbed Device Connector](https://connector.mbed.com) and log in with your mbed account.
+1. On mbed Device Connector, go to [My Devices > Security credentials](https://connector.mbed.com/#credentials) and click the **Get my device security credentials** button to get new credentials for your device.
+1. Replace the contents in `security.h` of this project's directory with content copied above.
+
+### 6LoWPAN ND and Thread settings
+
+6LoWPAN ND and Thread use IPv6 for connectivity. Therefore, you need to verify first that you have a working IPv6 connection. To do that, ping the Connector IPv6 address `2607:f0d0:2601:52::20` from your network.
+
+#### mbed gateway
+
+To connect the example application in 6LoWPAN ND or Thread mode to Connector, you need to set up an mbed 6LoWPAN gateway router as follows:
+
+1. Use an Ethernet cable to connect the mbed 6LoWPAN gateway router to the internet.
+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.
+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:
+
+	* For the **6LoWPAN ND** bootstrap, use `gateway6LoWPANDynamic.bin`.
+	* For the **Thread** bootstrap, use `gatewayThreadDynamic.bin`.
+
+	The dynamic binaries use IPv6 autoconfiguration and enable the client to connect to the Connector service. The static binaries create a site-local IPv6 network and packets cannot be routed outside.
+
+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.
+
+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`.
+
+#### Channel settings
+
+The default 2.4GHz channel settings are already defined by the [mbed-mesh-api](https://github.com/ARMmbed/mbed-mesh-api) to match the mbed gateway settings. The application can override these settings by adding them to the `mbed_app.json` file in the main project directory. For example:
+
+```json
+    "target_overrides": {
+        "*": {
+            "mbed-mesh-api.6lowpan-nd-channel-page": 0,
+            "mbed-mesh-api.6lowpan-nd-channel": 12,
+            "mbed-mesh-api.thread-config-channel-page": 0,
+            "mbed-mesh-api.thread-config-channel": 12
+        }
+    }
+```
+
+For sub-GHz shields (AT86RF212B) use the following overrides, **6LoWPAN ND only**:
+
+```json
+"mbed-mesh-api.6lowpan-nd-channel-page": 2,
+"mbed-mesh-api.6lowpan-nd-channel": 1
+```
+
+For more information about the radio shields, see [the related documentation](docs/radio_module_identify.md). All the configurable settings can be found in the `mbed-os-example-client/mbed-os/features/FEATURE_IPV6/mbed-mesh-api/mbed_lib.json` file.
+
+#### Thread-specific settings
+
+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:
+
+```json
+    "mbed-mesh-api.thread-device-type": "MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE"
+```
+
+### Ethernet settings
+
+For running the example application using Ethernet, you need:
+
+- An Ethernet cable.
+- An Ethernet connection to the internet.
+
+### Wi-Fi settings
+
+The example application uses ESP8266 WiFi Interface for managing the wireless connectivity. To run this application using WiFi, you need:
+
+1. An [ESP8266](https://en.wikipedia.org/wiki/ESP8266) WiFi module
+1. Updated [Espressif Firmware](https://developer.mbed.org/teams/ESP8266/wiki/Firmware-Update)
+1. Mount the WiFi module onto [K64F Grove Shield v2](https://developer.mbed.org/platforms/FRDM-K64F/#supported-seeed-studio-grove-extension)
+1. Attach the shield on the K64F board.
+1. In the `mbed_app.json` file, change
+```json
+    "network-interface": {
+        "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.",
+        "value": "WIFI"
+    }
+```
+
+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.
+```json
+    "wifi-ssid": {
+        "help": "WiFi SSID",
+        "value": "\"SSID\""
+    },
+    "wifi-password": {
+        "help": "WiFi Password",
+        "value": "\"Password\""
+    }
+```
+
+### IP address setup
+
+This example uses IPv4 to communicate with the [mbed Device Connector Server](https://api.connector.mbed.com) except for 6LoWPAN ND and Thread. The example program should automatically get an IPv4 address from the router when connected over Ethernet.
+
+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.
+
+### Changing socket type
+
+Your device can connect to mbed Device Connector via UDP or TCP binding mode. The default is UDP. The binding mode cannot be changed in 6LoWPAN ND or Thread mode.
+
+To change the binding mode:
+
+1. In the `simpleclient.h` file, find the parameter `SOCKET_MODE`. The default is `M2MInterface::UDP`.
+1. To switch to TCP, change it to `M2MInterface::TCP`.
+1. Rebuild and flash the application.
+
+<span class="tips">**Tip:** The instructions in this document remain the same, irrespective of the socket mode you select.</span>
+
+## Building the example
+
+To build the example application:
+
+1. Clone [this](https://github.com/ARMmbed/mbed-os-example-client) repository.
+1. Open a command line tool and navigate to the project’s directory.
+1. Update mbed-os sources using the `mbed update` command.
+1. [Configure](#application-setup) the client application.
+1. Build the application by selecting the hardware board and build the toolchain using the command `mbed compile -m K64F -t GCC_ARM -c -j0`. mbed-cli builds a binary file under the project’s `.build` directory.
+1. Plug the Ethernet cable into the board if you are using Ethernet mode.
+1. If you are using 6LoWPAN ND or Thread mode, connect and power on the gateway first.
+1. Plug the micro-USB cable into the **OpenSDA** port. The board is listed as a mass-storage device.
+1. Drag the binary `.build/K64F/GCC_ARM/mbed-os-example-client.bin` to the board to flash the application.
+1. 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.
+1. Press the **RESET** button on the board to run the program.
+1. For verification, continue to the [Monitoring the application](#monitoring-the-application) chapter.
+
+
+## Monitoring the application
+
+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.
+
+<span class="notes">**Note:** Instructions to set this up are located [here](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications).</span>
+
+After connecting, you should see messages about connecting to mbed Device Connector:
+
+```
+In app_start()
+IP address 10.2.15.222
+Device name 6868df22-d353-4150-b90a-a878130859d9
+```
+
+<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) chapter.</span>
+
+When you click the `SW2` button on your board you should see messages about the value changes:
+
+```
+handle_button_click, new value of counter is 1
+```
+
+## Testing the application
+
+1. Flash the application.
+1. Verify that the registration succeeded. You should see `Registered object successfully!` printed to the serial port.
+1. On mbed Device Connector, go to [My devices > Connected devices](https://connector.mbed.com/#endpoints). Your device should be listed here.
+1. Press the `SW2` button on the device a number of times (make a note of how many times you did that).
+1. Go to [Device Connector > API Console](https://connector.mbed.com/#console).
+1. Enter `https://api.connector.mbed.com/endpoints/DEVICE_NAME/3200/0/5501` in the URI field and click **TEST API**. Replace `DEVICE_NAME` with your actual endpoint name. The device name can be found in the `security.h` file, see variable `MBED_ENDPOINT_NAME` or it can be found from the traces [Monitoring the application](https://github.com/ARMmbed/mbed-os-example-client#monitoring-the-application).
+1. The number of times you pressed `SW2` is shown.
+1. 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.
+
+
+![SW2 pressed five times, as shown by the API Console](clicks.png)
+
+<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>
+
+<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).
+
+### Application resources
+
+The application exposes three [resources](https://docs.mbed.com/docs/mbed-device-connector-web-interfaces/en/latest/#the-mbed-device-connector-data-model):
+
+1. `3200/0/5501`. Number of presses of SW2 (GET).
+2. `3201/0/5850`. Blink function, blinks `LED1` when executed (POST).
+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).
+
+For information on how to get notifications when resource 1 changes, or how to use resources 2 and 3, take a look at the [mbed Device Connector Quick Start](https://github.com/ARMmbed/mbed-connector-api-node-quickstart).
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apache-2.0.txt	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,56 @@
+
+
+Apache License
+
+Version 2.0, January 2004
+
+http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+
+    You must give any other recipients of the Work or Derivative Works a copy of this License; and
+    You must cause any modified files to carry prominent notices stating that You changed the files; and
+    You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
+    If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
+
+    You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/atmel-rf-driver.lib	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/atmel-rf-driver/#4fb763e3a34c8ad501c111c1e007854349ae18ed
Binary file clicks.png has changed
Binary file docs/img/Radio_Identifications.png has changed
Binary file docs/img/Radio_Identifications_GW.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/radio_module_identify.md	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,17 @@
+## Radio module identification
+
+* Make sure that you are using the same radio modules on both server and client sides:
+
+	* If the radio module on the gateway router supports the 2.4 GHz frequency band, the client side must have an mbed 6LoWPAN shield that uses a 2.4 GHz radio module (such as Atmel AT86RF233).
+
+	* If the radio module on the gateway router supports the sub-GHz frequency band, the client side must have an mbed 6LoWPAN shield that uses a sub-GHz radio module (such as Atmel AT86RF212B).
+
+* An easy way to identify which frequency band your setup uses is to check the **Antenna size** on the radio module:
+
+	* The sub-GHz band antenna is larger than the 2.4 GHz antenna.
+
+	* For the client side (mbed 6LoWPAN shield connected to an FRDM-K64F board), see the image below:
+  ![](img/Radio_Identifications.png) 
+
+	* For the gateway router, see the image below:
+  ![](img/Radio_Identifications_GW.png) 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/esp8266-driver.lib	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/esp8266-driver/#636af254ddfee68e83cd550e5184e253efa469a0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,342 @@
+/*
+ * Copyright (c) 2015 ARM Limited. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "simpleclient.h"
+#include <string>
+#include <sstream>
+#include <vector>
+#include "mbed-trace/mbed_trace.h"
+
+#include "security.h"
+
+#include "mbed.h"
+#include "rtos.h"
+
+#define ETHERNET        1
+#define WIFI            2
+#define MESH_LOWPAN_ND  3
+#define MESH_THREAD     4
+
+#define STRINGIFY(s) #s
+
+#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI
+#include "ESP8266Interface.h"
+ESP8266Interface esp(D1, D0);
+#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET
+#include "EthernetInterface.h"
+EthernetInterface eth;
+#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND
+#define MESH
+#include "NanostackInterface.h"
+LoWPANNDInterface mesh;
+#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD
+#define MESH
+#include "NanostackInterface.h"
+ThreadInterface mesh;
+#endif
+
+#ifndef MESH
+// This is address to mbed Device Connector
+#define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684"
+#else
+// This is address to mbed Device Connector
+#define MBED_SERVER_ADDRESS "coaps://[2607:f0d0:2601:52::20]:5684"
+#endif
+
+Serial output(USBTX, USBRX);
+
+// These are example resource values for the Device Object
+struct MbedClientDevice device = {
+    "Manufacturer_String",      // Manufacturer
+    "Type_String",              // Type
+    "ModelNumber_String",       // ModelNumber
+    "SerialNumber_String"       // SerialNumber
+};
+
+// Instantiate the class which implements LWM2M Client API (from simpleclient.h)
+MbedClient mbed_client(device);
+
+// Set up Hardware interrupt button.
+InterruptIn obs_button(SW2);
+InterruptIn unreg_button(SW3);
+
+// LED Output
+DigitalOut led1(LED1);
+
+/*
+ * The Led contains one property (pattern) and a function (blink).
+ * When the function blink is executed, the pattern is read, and the LED
+ * will blink based on the pattern.
+ */
+class LedResource {
+public:
+    LedResource() {
+        // create ObjectID with metadata tag of '3201', which is 'digital output'
+        led_object = M2MInterfaceFactory::create_object("3201");
+        M2MObjectInstance* led_inst = led_object->create_object_instance();
+
+        // 5853 = Multi-state output
+        M2MResource* pattern_res = led_inst->create_dynamic_resource("5853", "Pattern",
+            M2MResourceInstance::STRING, false);
+        // read and write
+        pattern_res->set_operation(M2MBase::GET_PUT_ALLOWED);
+        // set initial pattern (toggle every 200ms. 7 toggles in total)
+        pattern_res->set_value((const uint8_t*)"500:500:500:500:500:500:500", 27);
+
+        // there's not really an execute LWM2M ID that matches... hmm...
+        M2MResource* led_res = led_inst->create_dynamic_resource("5850", "Blink",
+            M2MResourceInstance::OPAQUE, false);
+        // we allow executing a function here...
+        led_res->set_operation(M2MBase::POST_ALLOWED);
+        // when a POST comes in, we want to execute the led_execute_callback
+        led_res->set_execute_function(execute_callback(this, &LedResource::blink));
+    }
+
+    M2MObject* get_object() {
+        return led_object;
+    }
+
+    void blink(void *) {
+        // read the value of 'Pattern'
+        M2MObjectInstance* inst = led_object->object_instance();
+        M2MResource* res = inst->resource("5853");
+
+        // values in mbed Client are all buffers, and we need a vector of int's
+        uint8_t* buffIn = NULL;
+        uint32_t sizeIn;
+        res->get_value(buffIn, sizeIn);
+
+        // turn the buffer into a string, and initialize a vector<int> on the heap
+        std::string s((char*)buffIn, sizeIn);
+        std::vector<uint32_t>* v = new std::vector<uint32_t>;
+
+        output.printf("led_execute_callback pattern=%s\r\n", s.c_str());
+
+        // our pattern is something like 500:200:500, so parse that
+        std::size_t found = s.find_first_of(":");
+        while (found!=std::string::npos) {
+
+            v->push_back(atoi((const char*)s.substr(0,found).c_str()));
+            s = s.substr(found+1);
+            found=s.find_first_of(":");
+            if(found == std::string::npos) {
+                v->push_back(atoi((const char*)s.c_str()));
+            }
+        }
+
+
+        // do_blink is called with the vector, and starting at -1
+        do_blink(v, 0);
+    }
+
+private:
+    M2MObject* led_object;
+
+    void do_blink(std::vector<uint32_t>* pattern, uint16_t position) {
+        // blink the LED
+        led1 = !led1;
+
+        // up the position, if we reached the end of the vector
+        if (position >= pattern->size()) {
+            // free memory, and exit this function
+            delete pattern;
+            return;
+        }
+
+        // how long do we need to wait before the next blink?
+        uint32_t delay_ms = pattern->at(position);
+
+        // Invoke same function after `delay_ms` (upping position)
+        Thread::wait(delay_ms);
+        do_blink(pattern, ++position);
+    }
+};
+
+/*
+ * The button contains one property (click count).
+ * When `handle_button_click` is executed, the counter updates.
+ */
+class ButtonResource {
+public:
+    ButtonResource(): counter(0) {
+        // create ObjectID with metadata tag of '3200', which is 'digital input'
+        btn_object = M2MInterfaceFactory::create_object("3200");
+        M2MObjectInstance* btn_inst = btn_object->create_object_instance();
+        // create resource with ID '5501', which is digital input counter
+        M2MResource* btn_res = btn_inst->create_dynamic_resource("5501", "Button",
+            M2MResourceInstance::INTEGER, true /* observable */);
+        // we can read this value
+        btn_res->set_operation(M2MBase::GET_ALLOWED);
+        // set initial value (all values in mbed Client are buffers)
+        // to be able to read this data easily in the Connector console, we'll use a string
+        btn_res->set_value((uint8_t*)"0", 1);        
+    }
+
+    ~ButtonResource() {
+    }
+
+    M2MObject* get_object() {
+        return btn_object;
+    }
+
+    /*
+     * When you press the button, we read the current value of the click counter
+     * from mbed Device Connector, then up the value with one.
+     */
+    void handle_button_click() {
+        M2MObjectInstance* inst = btn_object->object_instance();
+        M2MResource* res = inst->resource("5501");
+
+        // up counter
+        counter++;
+
+        printf("handle_button_click, new value of counter is %d\r\n", counter);
+
+        // serialize the value of counter as a string, and tell connector
+        char buffer[20];
+        int size = sprintf(buffer,"%d",counter);
+        res->set_value((uint8_t*)buffer, size);
+    }
+
+private:
+    M2MObject* btn_object;
+    uint16_t counter;
+};
+
+// Network interaction must be performed outside of interrupt context
+Semaphore updates(0);
+volatile bool registered = false;
+volatile bool clicked = false;
+osThreadId mainThread;
+
+void unregister() {
+    registered = false;
+    updates.release();
+}
+
+void button_clicked() {
+    clicked = true;
+    updates.release();
+}
+
+// debug printf function
+void trace_printer(const char* str) {
+    printf("%s\r\n", str);
+}
+
+// Status indication
+Ticker status_ticker;
+DigitalOut status_led(LED1);
+void blinky() { status_led = !status_led; }
+
+
+// Entry point to the program
+int main() {
+    status_ticker.attach_us(blinky, 250000);
+
+    // Keep track of the main thread
+    mainThread = osThreadGetId();
+
+    // Sets the console baud-rate
+    output.baud(115200);
+
+    output.printf("Starting mbed Client example...\r\n");
+
+    mbed_trace_init();
+    mbed_trace_print_function_set(trace_printer);
+
+    NetworkInterface *network_interface = 0;
+    int connect_success = -1;
+#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI
+    output.printf("\n\rUsing WiFi \r\n");
+    output.printf("\n\rConnecting to WiFi..\r\n");
+    connect_success = esp.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD);
+    network_interface = &esp;
+#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET
+    output.printf("Using Ethernet\r\n");
+    connect_success = eth.connect();
+    network_interface = &eth;
+#endif
+#ifdef MESH
+    output.printf("Using Mesh\r\n");
+    output.printf("\n\rConnecting to Mesh..\r\n");
+    connect_success = mesh.connect();
+    network_interface = &mesh;
+#endif
+    if(connect_success == 0) {
+    output.printf("\n\rConnected to Network successfully\r\n");
+    } else {
+        output.printf("\n\rConnection to Network Failed %d! Exiting application....\r\n", connect_success);
+        return 0;
+    }
+    const char *ip_addr = network_interface->get_ip_address();
+    if (ip_addr) {
+        output.printf("IP address %s\r\n", ip_addr);
+    } else {
+        output.printf("No IP address\r\n");
+    }
+
+    // we create our button and LED resources
+    ButtonResource button_resource;
+    LedResource led_resource;
+
+    // On press of SW3 button on K64F board, example application
+    // will call unregister API towards mbed Device Connector
+    //unreg_button.fall(&mbed_client,&MbedClient::test_unregister);
+    unreg_button.fall(&unregister);
+
+    // Observation Button (SW2) press will send update of endpoint resource values to connector
+    obs_button.fall(&button_clicked);
+
+    // Create endpoint interface to manage register and unregister
+    mbed_client.create_interface(MBED_SERVER_ADDRESS, network_interface);
+
+    // Create Objects of varying types, see simpleclient.h for more details on implementation.
+    M2MSecurity* register_object = mbed_client.create_register_object(); // server object specifying connector info
+    M2MDevice*   device_object   = mbed_client.create_device_object();   // device resources object
+
+    // Create list of Objects to register
+    M2MObjectList object_list;
+
+    // Add objects to list
+    object_list.push_back(device_object);
+    object_list.push_back(button_resource.get_object());
+    object_list.push_back(led_resource.get_object());
+
+    // Set endpoint registration object
+    mbed_client.set_register_object(register_object);
+
+    // Register with mbed Device Connector
+    mbed_client.test_register(register_object, object_list);
+    registered = true;
+
+    while (true) {
+        updates.wait(25000);
+        if(registered) {
+            if(!clicked) {
+                mbed_client.test_update_register();
+            }
+        }else {
+            break;
+        }
+        if(clicked) {
+           clicked = false;
+            button_resource.handle_button_click();
+        }
+    }
+
+    mbed_client.test_unregister();
+    status_ticker.detach();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#c872ebba8ee0b6256a8aa492dd6bd3122ea64448
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,23 @@
+{
+    "config": {
+        "network-interface":{
+            "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD",
+            "value": "ETHERNET"
+        },
+        "wifi-ssid": {
+            "help": "WiFi SSID",
+            "value": "\"SSID\""
+        },
+        "wifi-password": {
+            "help": "WiFi Password",
+            "value": "\"Password\""
+        }
+    },
+    "target_overrides": {
+        "*": {
+            "target.features_add": ["IPV6", "CLIENT", "IPV4"],
+            "mbed-client.reconnection-count": 3,
+            "mbed-client.reconnection-interval": 5
+        }
+    }
+} 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_client_config.h	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016 ARM Limited. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef MBED_CLIENT_CONFIG_H
+#define MBED_CLIENT_CONFIG_H
+
+
+// Defines the number of times client should try re-connection towards
+// Server in case of connectivity loss , also defines the number of CoAP
+// re-transmission attempts.Default value is 3
+#define M2M_CLIENT_RECONNECTION_COUNT		3
+
+// Defines the interval (in seconds) in which client should try re-connection towards
+// Server in case of connectivity loss , also use the same interval for CoAP
+// re-transmission attempts. Default value is 5 seconds
+#define M2M_CLIENT_RECONNECTION_INTERVAL	5
+
+// Defines the keep-alive interval (in seconds) in which client should send keep alive
+// pings to server while connected through TCP mode. Default value is 300 seconds
+#define M2M_CLIENT_TCP_KEEPALIVE_TIME 		300
+
+// Defines the maximum CoAP messages that client can hold, maximum value is 6
+#define SN_COAP_DUPLICATION_MAX_MSGS_COUNT  2
+
+// Defines the size of blockwise CoAP messages that client can handle.
+// The values that can be defined uust be 2^x and x is at least 4.
+// Suitable values: 0, 16, 32, 64, 128, 256, 512 and 1024
+#define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE  1024
+
+// Many pure LWM2M servers doen't accept 'obs' text in registration message.
+// While using Client against such servers, this flag can be set to define to
+// disable client sending 'obs' text for observable resources.
+#undef COAP_DISABLE_OBS_FEATURE
+
+// Disable Bootstrap functionality in client in order to reduce code size, if bootstrap
+// functionality is not required.
+#undef M2M_CLIENT_DISABLE_BOOTSTRAP_FEATURE
+
+#endif // MBED_CLIENT_CONFIG_H
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/security.h	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2015 ARM Limited. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SECURITY_H__
+#define __SECURITY_H__
+ 
+#include <inttypes.h>
+ 
+#define MBED_DOMAIN "DOMAIN"
+#define MBED_ENDPOINT_NAME "ENDPOINT_NAME"
+ 
+const uint8_t SERVER_CERT[] = "-----BEGIN CERTIFICATE-----\r\n"
+"-----END CERTIFICATE-----\r\n";
+ 
+const uint8_t CERT[] = "-----BEGIN CERTIFICATE-----\r\n"
+"-----END CERTIFICATE-----\r\n";
+ 
+const uint8_t KEY[] = "-----BEGIN PRIVATE KEY-----\r\n"
+"-----END PRIVATE KEY-----\r\n";
+ 
+#endif //__SECURITY_H__
+ 
+#error "You need to get security.h credentials from connector.mbed.com and replace the content of this security.h file"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/simpleclient.h	Mon Jul 25 16:32:20 2016 +0300
@@ -0,0 +1,329 @@
+/*
+ * Copyright (c) 2015 ARM Limited. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __SIMPLECLIENT_H__
+#define __SIMPLECLIENT_H__
+
+#include "mbed-client/m2minterfacefactory.h"
+#include "mbed-client/m2mdevice.h"
+#include "mbed-client/m2minterfaceobserver.h"
+#include "mbed-client/m2minterface.h"
+#include "mbed-client/m2mobject.h"
+#include "mbed-client/m2mobjectinstance.h"
+#include "mbed-client/m2mresource.h"
+#include "mbed-client/m2mconfig.h"
+#include "security.h"
+#include "mbed.h"
+
+//Select binding mode: UDP or TCP
+M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP;
+
+// MBED_DOMAIN and MBED_ENDPOINT_NAME come
+// from the security.h file copied from connector.mbed.com
+
+struct MbedClientDevice {
+    const char* Manufacturer;
+    const char* Type;
+    const char* ModelNumber;
+    const char* SerialNumber;
+};
+
+/*
+* Wrapper for mbed client stack that handles all callbacks, error handling, and
+* other shenanigans to make the mbed client stack easier to use.
+*
+* The end user should only have to care about configuring the parameters at the
+* top of this file and making sure they add the security.h file correctly.
+* To add resources you can copy the _TODO__ function and add as many instances as
+* you want.
+*
+*/
+class MbedClient: public M2MInterfaceObserver {
+public:
+
+    // constructor for MbedClient object, initialize private variables
+    MbedClient(struct MbedClientDevice device) {
+        _interface = NULL;
+        _bootstrapped = false;
+        _error = false;
+        _registered = false;
+        _unregistered = false;
+        _register_security = NULL;
+        _value = 0;
+        _object = NULL;
+        _device = device;
+    }
+
+    // de-constructor for MbedClient object, you can ignore this
+    ~MbedClient() {
+        if(_interface) {
+            delete _interface;
+        }
+        if(_register_security){
+            delete _register_security;
+        }
+    }
+
+    // debug printf function
+    void trace_printer(const char* str) {
+        printf("\r\n%s\r\n", str);
+    }
+
+    /*
+    *  Creates M2MInterface using which endpoint can
+    *  setup its name, resource type, life time, connection mode,
+    *  Currently only LwIPv4 is supported.
+    */
+    void create_interface(const char *server_address,
+                          void *handler=NULL) {
+	// Randomizing listening port for Certificate mode connectivity
+    _server_address = server_address;
+	srand(time(NULL));
+	uint16_t port = rand() % 65535 + 12345;
+
+    // create mDS interface object, this is the base object everything else attaches to
+    _interface = M2MInterfaceFactory::create_interface(*this,
+                                                      MBED_ENDPOINT_NAME,       // endpoint name string
+                                                      "test",                   // endpoint type string
+                                                      100,                      // lifetime
+                                                      port,                     // listen port
+                                                      MBED_DOMAIN,              // domain string
+                                                      SOCKET_MODE,              // binding mode
+                                                      M2MInterface::LwIP_IPv4,  // network stack
+                                                      "");                      // context address string
+    const char *binding_mode = (SOCKET_MODE == M2MInterface::UDP) ? "UDP" : "TCP";
+    printf("\r\nSOCKET_MODE : %s\r\n", binding_mode);
+    printf("Connecting to %s\r\n", server_address);
+
+    if(_interface) {
+        _interface->set_platform_network_handler(handler);
+    }
+
+    }
+
+    /*
+    *  check private variable to see if the registration was sucessful or not
+    */
+    bool register_successful() {
+        return _registered;
+    }
+
+    /*
+    *  check private variable to see if un-registration was sucessful or not
+    */
+    bool unregister_successful() {
+        return _unregistered;
+    }
+
+    /*
+    *  Creates register server object with mbed device server address and other parameters
+    *  required for client to connect to mbed device server.
+    */
+    M2MSecurity* create_register_object() {
+        // create security object using the interface factory.
+        // this will generate a security ObjectID and ObjectInstance
+        M2MSecurity *security = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer);
+
+        // make sure security ObjectID/ObjectInstance was created successfully
+        if(security) {
+            // Add ResourceID's and values to the security ObjectID/ObjectInstance
+            security->set_resource_value(M2MSecurity::M2MServerUri, _server_address);
+            security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate);
+            security->set_resource_value(M2MSecurity::ServerPublicKey, SERVER_CERT, sizeof(SERVER_CERT));
+            security->set_resource_value(M2MSecurity::PublicKey, CERT, sizeof(CERT));
+            security->set_resource_value(M2MSecurity::Secretkey, KEY, sizeof(KEY));
+        }
+        return security;
+    }
+
+    /*
+    * Creates device object which contains mandatory resources linked with
+    * device endpoint.
+    */
+    M2MDevice* create_device_object() {
+        // create device objectID/ObjectInstance
+        M2MDevice *device = M2MInterfaceFactory::create_device();
+        // make sure device object was created successfully
+        if(device) {
+            // add resourceID's to device objectID/ObjectInstance
+            device->create_resource(M2MDevice::Manufacturer, _device.Manufacturer);
+            device->create_resource(M2MDevice::DeviceType, _device.Type);
+            device->create_resource(M2MDevice::ModelNumber, _device.ModelNumber);
+            device->create_resource(M2MDevice::SerialNumber, _device.SerialNumber);
+        }
+        return device;
+    }
+
+    /*
+    * register an object
+    */
+    void test_register(M2MSecurity *register_object, M2MObjectList object_list){
+        if(_interface) {
+            // Register function
+            _interface->register_object(register_object, object_list);
+        }
+    }
+
+    /*
+    * unregister all objects
+    */
+    void test_unregister() {
+        if(_interface) {
+            // Unregister function
+            _interface->unregister_object(NULL); // NULL will unregister all objects
+        }
+    }
+
+    //Callback from mbed client stack when the bootstrap
+    // is successful, it returns the mbed Device Server object
+    // which will be used for registering the resources to
+    // mbed Device server.
+    void bootstrap_done(M2MSecurity *server_object){
+        if(server_object) {
+            _bootstrapped = true;
+            _error = false;
+            trace_printer("Bootstrapped");
+        }
+    }
+
+    //Callback from mbed client stack when the registration
+    // is successful, it returns the mbed Device Server object
+    // to which the resources are registered and registered objects.
+    void object_registered(M2MSecurity */*security_object*/, const M2MServer &/*server_object*/){
+        _registered = true;
+        _unregistered = false;
+        trace_printer("Registered object successfully!");
+    }
+
+    //Callback from mbed client stack when the unregistration
+    // is successful, it returns the mbed Device Server object
+    // to which the resources were unregistered.
+    void object_unregistered(M2MSecurity */*server_object*/){
+        trace_printer("Unregistered Object Successfully");
+        _unregistered = true;
+        _registered = false;               
+    }
+
+    /*
+    * Callback from mbed client stack when registration is updated
+    */
+    void registration_updated(M2MSecurity */*security_object*/, const M2MServer & /*server_object*/){
+        /* The registration is updated automatically and frequently by the
+        *  mbed client stack. This print statement is turned off because it
+        *  tends to happen alot.
+        */
+        //trace_printer("\r\nRegistration Updated\r\n");
+    }
+
+    // Callback from mbed client stack if any error is encountered
+    // during any of the LWM2M operations. Error type is passed in
+    // the callback.
+    void error(M2MInterface::Error error){
+        _error = true;
+        switch(error){
+            case M2MInterface::AlreadyExists:
+                trace_printer("[ERROR:] M2MInterface::AlreadyExist");
+                break;
+            case M2MInterface::BootstrapFailed:
+                trace_printer("[ERROR:] M2MInterface::BootstrapFailed");
+                break;
+            case M2MInterface::InvalidParameters:
+                trace_printer("[ERROR:] M2MInterface::InvalidParameters");
+                break;
+            case M2MInterface::NotRegistered:
+                trace_printer("[ERROR:] M2MInterface::NotRegistered");
+                break;
+            case M2MInterface::Timeout:
+                trace_printer("[ERROR:] M2MInterface::Timeout");
+                break;
+            case M2MInterface::NetworkError:
+                trace_printer("[ERROR:] M2MInterface::NetworkError");
+                break;
+            case M2MInterface::ResponseParseFailed:
+                trace_printer("[ERROR:] M2MInterface::ResponseParseFailed");
+                break;
+            case M2MInterface::UnknownError:
+                trace_printer("[ERROR:] M2MInterface::UnknownError");
+                break;
+            case M2MInterface::MemoryFail:
+                trace_printer("[ERROR:] M2MInterface::MemoryFail");
+                break;
+            case M2MInterface::NotAllowed:
+                trace_printer("[ERROR:] M2MInterface::NotAllowed");
+                break;
+            case M2MInterface::SecureConnectionFailed:
+                trace_printer("[ERROR:] M2MInterface::SecureConnectionFailed");
+                break;
+            case M2MInterface::DnsResolvingFailed:
+                trace_printer("[ERROR:] M2MInterface::DnsResolvingFailed");
+                break;
+
+            default:
+                break;
+        }
+    }
+
+    /* Callback from mbed client stack if any value has changed
+    *  during PUT operation. Object and its type is passed in
+    *  the callback.
+    *  BaseType enum from m2mbase.h
+    *       Object = 0x0, Resource = 0x1, ObjectInstance = 0x2, ResourceInstance = 0x3
+    */
+    void value_updated(M2MBase *base, M2MBase::BaseType type) {
+        printf("\r\nPUT Request Received!");
+        printf("\r\nName :'%s', \r\nType : '%d' (0 for Object, 1 for Resource), \r\nType : '%s'\r\n",
+               base->name().c_str(),
+               type,
+               base->resource_type().c_str()
+               );
+    }
+
+    /*
+    * update the registration period
+    */
+    void test_update_register() {
+        if (_registered) {
+            _interface->update_registration(_register_security, 100);
+        }
+    }
+
+    /*
+    * manually configure the security object private variable
+    */
+   void set_register_object(M2MSecurity *register_object) {
+        if (_register_security == NULL) {
+            _register_security = register_object;
+        }
+    }
+
+private:
+
+    /*
+    *  Private variables used in class
+    */
+    M2MInterface    	     *_interface;
+    M2MSecurity              *_register_security;
+    M2MObject                *_object;
+    volatile bool            _bootstrapped;
+    volatile bool            _error;
+    volatile bool            _registered;
+    volatile bool            _unregistered;
+    int                      _value;
+    struct MbedClientDevice  _device;
+    String                   _server_address;
+};
+
+#endif // __SIMPLECLIENT_H__