DEPRECATED: Mbed Client example program.
Branch: master
Clone or download
yogpan01 Deprecating this example
This example is deprecated and superceded by another example https://github.com/ARMmbed/mbed-os-example-client for mbed OS v5
Latest commit 15ac1b0 Nov 1, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
source Add example use of payloads more than 65KB. Add example how to access… Aug 15, 2016
.gitignore
LICENSE Changed LICENSE.txt to LICENSE Sep 2, 2015
README.md Deprecating this example Nov 1, 2016
apache-2.0.txt
clicks.png
module.json Add support to get traces from mbed client library May 2, 2016

README.md

THIS EXAMPLE IS DEPRECATED AND IS SUPERCEDED BY ANOTHER EXAMPLE AVAILABLE HERE mbed-os-example-client

Getting started with mbed Client on mbed OS

This is the mbed Client example for mbed OS (we also have one for Linux). 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:

  • 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

  • An FRDM-K64F board.
  • An Ethernet connection to the internet.
  • An Ethernet cable.
  • A micro-USB cable.

Required software

Setting up

To set up the example, please:

  1. Build the example.
  2. Set up an IP address. This step is optional.
  3. Set a socket type. This step is optional.

Building the example

To build the example application:

  1. Clone this repository.
  2. Go to mbed Device Connector and log in with your mbed account.
  3. On mbed Device Connector, go to My Devices > Security credentials, and get new credentials for your device by clicking the Get my device security credentials button.
  4. Store the credentials as source/security.h in this project's directory.
  5. Open a command line tool and navigate to the project’s directory.
  6. Set yotta's build target. For example, if you are targeting the FRDM-K64F board: yotta target frdm-k64f-gcc.
  7. Build the application by using the command yotta build. yotta builds a binary file in the project’s directory.
  8. Plug the Ethernet cable into the board.
  9. Plug the micro-USB cable into the OpenSDA port. The board is listed as a mass-storage device.
  10. Drag the binary build/frdm-k64f-gcc/source/mbed-client-examples.bin to the board to flash the application.
  11. 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.
  12. Press the RESET button to run the program.
  13. For verification, continue to the Monitoring the application chapter.

IP address setup (optional)

This example uses IPv4 to communicate with the mbed Device Connector Server. 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 (binding mode - optional)

Your device can connect to mbed Device Connector via one of two binding modes: UDP or TCP. The default is UDP.

To change the binding mode:

  1. In the simpleclient.h file, find the parameter SOCKET_MODE.
  2. The default is M2MInterface::UDP.
  3. To switch to TCP, change it to M2MInterface::TCP.

Then re-build 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.

Note: Instructions to set this up are located here.

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

Note: Device name is the endpoint name you will need later on Testing the application chapter.

After 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.
  2. Verify that the registration succeeded. You should see Registered object successfully! printed to the serial port.
  3. On mbed Device Connector, go to My devices > Connected devices. Your device should be listed here.
  4. Press the SW2 button on the device a number of times (make a note of how many times you did that).
  5. Go to Device Connector > API Console.
  6. 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 source/security.h file, see variable MBED_ENDPOINT_NAME or it can be found from the traces Monitoring the application.
  7. The number of times you pressed SW2 is shown.
  8. Press the SW3 button to unregister from mbed Device Connector. You should see Unregistered Object Successfully printed to the serial port and 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

NOTE: If you get an error, for example Server Response: 410 (Gone), clear your browser's cache, log out, and log back in. NOTE: Only GET methods can be executed through Device Connector > API Console. For the other methods check the mbed Device Connector Quick Start.

Application resources

The application exposes three resources:

  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.