You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 24, 2019. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+75-50
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,13 @@
1
-
# Getting started on mbed Client Example
1
+
# Getting started with mbed Client on mbed OS
2
2
3
-
This document describes briefly the steps required to start using the mbed Client example application on mbed OS. The mbed Client example application demonstrates how to register and read resource values to mbed Device Connector and deregister from it.
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're unfamiliar with mbed Device Connector, we recommend 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.
4
+
5
+
The application:
6
+
7
+
* Registers with mbed Device Connector.
8
+
* Gives mbed Device Connector access to its resources (read and write).
9
+
* Records the number of clicks on the device’s button and sends the number to mbed Device Connector.
10
+
* Lets you control the blink pattern of the LED on the device (through mbed Device Connector).
4
11
5
12
## Required hardware
6
13
@@ -11,79 +18,97 @@ This document describes briefly the steps required to start using the mbed Clien
11
18
12
19
## Required software
13
20
14
-
*[yotta](http://docs.yottabuild.org/#installing) - to build the example programs.
21
+
* An [ARM mbed account](https://developer.mbed.org/account/login/?next=/).
22
+
*[yotta](http://docs.yottabuild.org/#installing) - to build the example programs. To learn how to build mbed OS applications with yotta, see [the user guide](https://docs.mbed.com/docs/getting-started-mbed-os/en/latest/Full_Guide/app_on_yotta/#building-an-application).
23
+
* A [serial port monitor](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications).
24
+
25
+
## Setting up
26
+
27
+
To set up the example, please:
15
28
16
-
## Setting up the environment
29
+
1.[Build the example](#Building-the-example).
30
+
1.[Set up an IP address](#IP-address-setup). This step is optional.
31
+
1.[Set a socket type](#Setting-socket-type). This step is optional.
17
32
18
-
To set up the environment, you need to do the following:
33
+
### Building the example
19
34
20
-
1. Go to [mbed Device Connector website](https://connector.mbed.com) and log in with your mbed.org account.
21
-
2. Clone this example into your local computer.
22
-
3. Configure the mbed Client example program with desired parameters. See [mbed Build instructions](#mbed-build-instructions) chapter for more information.
23
-
4. Set yotta's target for this project, for example `yotta target frdm-k64f-gcc`.
1. Go to [mbed Device Connector](https://connector.mbed.com) and log in with your mbed account.
39
+
1. On mbed Device Connector, go to [My Devices>Security credentials](https://connector.mbed.com/#credentials), and get new credentials for your device by clicking the *Get my device security credentials* button.
40
+
1. Store the credentials as `source/security.h` in this project's directory.
41
+
1. Open a command line tool and navigate to the project’s directory.
42
+
1. Set yotta's build target. For example, if you're targeting the FRDM-K64F board: `yotta target frdm-k64f-gcc`.
43
+
1. Build the application by using the command `yotta build`. yotta builds a binary file in the project’s directory.
44
+
1. Plug the Ethernet cable into the board.
45
+
1. Plug the micro-USB cable into the *OpenSDA* port. The board is listed as a mass-storage device.
46
+
1. Drag the binary `build/frdm-k64f-gcc/source/mbed-client-examples.bin` to the board to flash the application.
47
+
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..
48
+
1. Press the *RESET* button to run the program.
27
49
28
50
### IP address setup
29
51
30
-
This example uses IPV4 to communicate with the [mbed Device Connector Server](https://api.connector.mbed.com). The example program should automatically get an IPV4 address from the router when connected via Ethernet.
52
+
This example uses IPv4 to communicate with the [mbed Device Connector Server](https://api.connector.mbed.com). The example program should automatically get an IPv4 address from the router when connected over Ethernet.
31
53
32
54
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.
33
55
34
-
## mbed Build instructions
35
-
36
-
### Building
37
-
This example uses the Certificate mode.
56
+
### Changing socket type (binding mode)
57
+
58
+
Your device can connect to mbed Device Connector via one of two binding modes: UDP or TCP. The default is UDP.
59
+
60
+
To change the binding mode:
61
+
62
+
1. In `main.cpp`, find the parameter ``SOCKET_MODE``.
63
+
1. The default is ``M2MInterface::UDP``.
64
+
1. To switch to TCP, change it to ``M2MInterface::TCP``.
38
65
39
-
#### Setting socket type
40
-
41
-
You can also connect in different socket mode. To select the binding mode for the socket, change `SOCKET_MODE` between `M2MInterface::UDP` and `M2MInterface::TCP`. The instructions further in this document remain same irrespective of the socket mode you select.
66
+
Then re-build and flash the application.
42
67
43
-
#### General
68
+
**Tip:** The instructions in this document remain the same, irrespective of the socket mode you select.
44
69
45
-
1. Connect the FRDM-K64F board to the computer with the micro-USB cable. Make sure that you are using the micro-USB port labeled **OpenSDA**.
46
-
2. Install yotta. See instructions [here](http://docs.yottabuild.org/#installing).
47
-
3. Install the necessary toolchains (`arm-none-eabi-gcc`). Refer to the yotta installation instructions (in step 3) to learn how to install the toolchains.
48
-
4. In the command prompt, go to the **mbed-client-examples** directory.
49
-
5. Select and set the certificate as instructed [below](#setting-certificate-for-the-application).
50
-
6. Set up the target device, `yotta target frdm-k64f-gcc`.
51
-
7. In the command prompt, type `yotta build`. The binary file `mbed-client-examples.bin` will be created in the `/build/frdm-k64f-gcc/source/` folder.
70
+
## Monitoring the application
52
71
53
-
#### Setting Certificate for the application
72
+
The application prints debug messages over the serial port, so you can monitor its activity with a serial port monitor. Instructions to set this up are located [here](https://developer.mbed.org/handbook/SerialPC#host-interface-and-terminal-applications).
54
73
55
-
1. Go to [mbed Device Connector website](https://connector.mbed.com).
56
-
2. Navigate to **Security credentials** under **My devices**.
57
-
3. Click **GET MY DEVICE SECURITY CREDENTIALS**. You will get the needed certificate information as well as the endpoint name and domain.
58
-
4. Copy the created security credentials to `source/security.h`.
74
+
After connecting you should see messages about connecting to mbed Device Connector:
59
75
60
-
### Flashing to target device
76
+
```
77
+
In app_start()
78
+
IP address 10.2.15.222
79
+
Device name 6868df22-d353-4150-b90a-a878130859d9
80
+
```
61
81
62
-
1. Connect the FRDM-K64F board to the internet using an Ethernet cable.
63
-
2. Connect the FRDM-K64F board to your computer using a micro-USB cable. Make sure that you plug into the micro-USB port labeled **OpenSDA**, on the bottom of the board.
64
-
3. Find the binary file named `mbed-client-examples.bin` in the folder `mbed-client-examples/build/frdm-k64f-gcc/source/`. Drag and drop the file onto the `MBED` drive on your computer.
65
-
4. The board will be programmed when the LED stops flashing. Press the **RESET** button to run the program.
82
+
And after you click the `SW2` button on your board you should see messages about the value changes:
66
83
67
-
## Testing
84
+
```
85
+
handle_button_click, new value of counter is 1
86
+
```
68
87
69
-
### Testing the mbed Client example application with the mbed Device Connector
88
+
**Note:** The application uses baud rate 115200.
70
89
71
-
Ensure that you have flashed the program to your mbed device (see [Flashing to target device](#flashing-to-target-device)).
90
+
## Testing the application
72
91
73
-
**Step 1**: Go to [mbed Device Connector website](https://connector.mbed.com).
92
+
1. Flash the application.
93
+
1. Verify that registration succeeded. You should see `Registered object successfully!` printed to the serial port.
94
+
1. On mbed Device Connector, go to [My devices>Connected devices](https://connector.mbed.com/#endpoints). Your device should be listed here.
95
+
1. Press the `SW2` button on the device a number of times (make a note of how many times you did that).
96
+
1. Go to [Device Connector>API Console](https://connector.mbed.com/#console).
97
+
1. Enter `https://api.connector.mbed.com/endpoints/DEVICE_NAME/3200/0/5501` in the URI field and click *TEST API*.
98
+
1. The number of times you pressed `SW2` is shown.
74
99
75
-
**Step 2**: Log in using your mbed account.
76
100
77
-
**Step 3**: Click the **Connected devices** link under **My devices** to see your registered mbed Client example device.
101
+

78
102
79
-
**Step 4**: You can send requests to mbed Client device with mbed Device Connector API. To do that, click **API Console** under **mbed Device Connector**. Click the URL to create a request. For example: `https://api.connector.mbed.com/endpoints/<Your-endpoint-name>/Test/0/S` creates a GET request to the static **/Test/0/S** resource.
103
+
**NOTE:** If you get an error, for example `Server Response: 410 (Gone)`, clear your browser's cache, log out, and log back in.
80
104
81
-
The **/Test/0/S** represents the static resource that is a fixed value set in the mbed Client.
105
+
### Application resources
82
106
83
-
The **/Test/0/D** represents the dynamic resource that can be read by the mbed Device Server. It is linked with the **SW2** button on the FRDM board. The value starts from zero and every time you press the **SW2** button the node increases the counter value by 1. You can make a CoAP request to the node resources to get the latest value. To do that, click **API Console** under **mbed Device Connector**. Click the URL to create a request. For example: `https://api.connector.mbed.com/endpoints/<Your-endpoint-name>/Test/0/D` creates a GET request to the **/Test/0/D** resource. This returns the latest value of **/Test/0/D**.
107
+
The application exposes three [resources](https://docs.mbed.com/docs/mbed-device-connector-web-interfaces/en/latest/#the-mbed-device-connector-data-model):
84
108
85
-
**NOTE:** In case you are getting an error, for example `Server Response : 410(Gone)` or other such error, try clearing the cache of your browser, log out and log in again and then try.
109
+
1.`3200/0/5501`. Number of presses of SW2 (GET).
110
+
2.`3201/0/5850`. Blink function, blinks `LED1` when executed (POST).
111
+
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).
86
112
87
-
For more information on the mbed Device Connector REST API, see [help pages](https://connector.mbed.com/#help-rest-api).
113
+
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.
88
114
89
-
**Step 5**: If you press the **SW3** button, the endpoint sends a deregister message to the mbed Device Connector. After a successful deregistration, LED **D12** starts blinking indicating that the application has successfully completed the task.
0 commit comments