This tutorial builds and flashes a Device Management Client application using either Linux (running on a PC) or Mbed OS.
The application can then connect to a standard OMA Lightweight M2M server.
In this tutorial, the application uses developer mode that relies on a developer certificate, which should be added to your software binary to allow test devices to connect to the server.
In production, the factory flow should be used instead.
This requires a Linux PC (64-bit Ubuntu/XUbuntu OS desktop environment). See also the Mbed CLI instructions.
-
Open a terminal, and clone the example repository to a convenient location in your development environment:
git clone https://github.com/PelionIoT/mbed-cloud-client-example cd mbed-cloud-client-example
Note: If you want to speed up
mbed deploy
, you can remove components that are unnecessary for Linux, such asmbed-os.lib
and thedrivers/
folder. -
Deploy the example repository:
mbed deploy
-
Copy the
mbed_cloud_dev_credentials.c
file to the root folder of the example. -
Deploy Linux dependencies:
python pal-platform/pal-platform.py deploy --target=x86_x64_NativeLinux_mbedtls generate cd __x86_x64_NativeLinux_mbedtls
Note: Python 2 is needed for the above command
-
Generate
cmake
files based on your configuration and build profile (Release or Debug):-
For the Release profile:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=./../pal-platform/Toolchain/GCC/GCC.cmake -DEXTERNAL_DEFINE_FILE=./../define_lwm2m_compliant.txt
-
For the Debug profile:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=./../pal-platform/Toolchain/GCC/GCC.cmake -DEXTERNAL_DEFINE_FILE=./../define_lwm2m_compliant.txt
-
If you want your application to bypass the Bootstrap server and work directly with the LwM2M server, add
DISABLE_BOOTSTRAP
cmake flag:cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DDISABLE_BOOTSTRAP=ON -DCMAKE_TOOLCHAIN_FILE=./../pal-platform/Toolchain/GCC/GCC.cmake -DEXTERNAL_DEFINE_FILE=./../define_lwm2m_compliant.txt
-
-
Compile the application:
make mbedCloudClientExample.elf
-
The build creates binaries under
mbed-cloud-client-example/__x86_x64_NativeLinux_mbedtls
. In both cases, there are subdirectoriesDebug
andRelease
respectively created for the two profiles. -
Run the application (at the respective path, see above):
./mbedCloudClientExample.elf
You should see a message when the device connects to the LwM2M server:
Client registered Endpoint Name: <YOUR_ENDPOINT_NAME> Device Id: <YOUR_ENDPOINT_NAME>
-
If you want to run the application with clean storage, you can remove the
pal
folder that is created in the location where you run your application.
To work with the Device Management Client example application, you need:
- A supported board with a network connection and an SD card is attached. FRDM K64F board is supported.
- Serial connection to your device with open terminal connection (baud rate 115200, 8N1).
- Arm Mbed CLI installed. See installation instructions.
- Make sure that all the Python components are on par with the
pip
package requirements.txt list from Mbed OS.
- Make sure that all the Python components are on par with the
- Updated DAPLink software (version 250 or later), if your board uses DAPLink.
-
Clone the embedded application's GitHub repository to your local computer and navigate to the new folder:
mbed import https://github.com/PelionIoT/mbed-cloud-client-example cd mbed-cloud-client-example
-
Configure Mbed CLI to use your board:
mbed target K64F mbed toolchain GCC_ARM
-
Copy the
mbed_cloud_dev_credentials.c
file to the root folder of the example application. -
Configure the example application:
-
If you want your application to bypass the Bootstrap server and work directly with the LwM2M server, please set the
disable-bootstrap-feature
feature totrue
in mbed_app_lwm2m_compliant.json.mbed-client.disable-bootstrap-feature: true
-
-
Compile the example application:
mbed compile --app-config mbed_app_lwm2m_compliant.json
For more information about Mbed CLI parameters, please see the Mbed OS documentation site.
-
Flash the binary to the device:
- Connect the device to your computer over USB. It's listed as a mass storage device.
- Drag and drop
mbed-cloud-client-example.bin
to the device, or alternatively add the-f
flag to the build command (if your device is connected to the build machine). This flashes the binary to the device. You should see the LED blink rapidly; wait for it to stop.
-
Press the Reset button to restart the device and reset the terminal.
-
When the client has successfully connected, the terminal shows:
Client registered Endpoint Name: <YOUR_ENDPOINT_NAME> Device ID: <YOUR_ENDPOINT_NAME>
-
Download the server CA certificate from the LwM2M service you want to connect to and copy it to the scripts' folder:
cp <SERVER_CA_CERT_FILE> utils/server_ca_cert.der
-
Run the python script
cert_convert.py
to generate ambed_cloud_dev_credentials.c
file.cd utils python cert_convert.py --endpoint <YOUR_ENDPOINT_NAME> --uri <The URI of the bootstrap or Device management service> --use-ca
The script will do the following steps:
- Generate a root CA key and certificate the first time the script is running. All CA outputs are stored in
CA
folder. - Generate a private key and a certificate signed by this CA.
- Convert the private key, certificate, and server certificate to a C file.
- All non-CA outputs are stored in a folder named
YOUR_ENDPOINT_NAME
.
- Generate a root CA key and certificate the first time the script is running. All CA outputs are stored in