THIS EXAMPLE IS DEPRECATED AND IS SUPERCEDED BY ANOTHER EXAMPLE AVAILABLE HERE mbed-os-example-client
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:
To set up the example, please:
To build the example application:
source/security.h
in this project's directory.yotta target frdm-k64f-gcc
.yotta build
. yotta builds a binary file in the project’s directory.build/frdm-k64f-gcc/source/mbed-client-examples.bin
to the board to flash the application.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.
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:
simpleclient.h
file, find the parameter SOCKET_MODE
.M2MInterface::UDP
.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.
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
Registered object successfully!
printed to the serial port.SW2
button on the device a number of times (make a note of how many times you did that).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.SW2
is shown.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.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.
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.