Skip to content

Latest commit

 

History

History
167 lines (114 loc) · 6.77 KB

pdmc-connection-to-standard-lwm2m-server-tutorial.md

File metadata and controls

167 lines (114 loc) · 6.77 KB

Device Management Client connection to a standard OMA LwM2M server tutorial

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.

Linux

Requirements

This requires a Linux PC (64-bit Ubuntu/XUbuntu OS desktop environment). See also the Mbed CLI instructions.

Connecting the device

  1. 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 as mbed-os.lib and the drivers/ folder.

  2. Deploy the example repository:

    mbed deploy
    
  3. Create a developer certificate.

  4. Copy the mbed_cloud_dev_credentials.c file to the root folder of the example.

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

  6. 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
      
  7. Compile the application:

    make mbedCloudClientExample.elf
    
  8. The build creates binaries under mbed-cloud-client-example/__x86_x64_NativeLinux_mbedtls. In both cases, there are subdirectories Debug and Release respectively created for the two profiles.

  9. 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>
    
  10. 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.

Mbed OS

Prerequisites

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.
  • Updated DAPLink software (version 250 or later), if your board uses DAPLink.

Connecting the device

  1. 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
    
  2. Configure Mbed CLI to use your board:

    mbed target K64F
    mbed toolchain GCC_ARM
    
  3. Create a developer certificate.

  4. Copy the mbed_cloud_dev_credentials.c file to the root folder of the example application.

  5. Configure the example application:

    1. If you want your application to bypass the Bootstrap server and work directly with the LwM2M server, please set the disable-bootstrap-feature feature to true in mbed_app_lwm2m_compliant.json.

      mbed-client.disable-bootstrap-feature: true
      
  6. 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.

  7. Flash the binary to the device:

    1. Connect the device to your computer over USB. It's listed as a mass storage device.
    2. 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.
  8. Press the Reset button to restart the device and reset the terminal.

  9. When the client has successfully connected, the terminal shows:

    Client registered
    Endpoint Name: <YOUR_ENDPOINT_NAME>
    Device ID: <YOUR_ENDPOINT_NAME>
    

Create a developer certificate

  1. 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
    
  2. Run the python script cert_convert.py to generate a mbed_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:

    1. Generate a root CA key and certificate the first time the script is running. All CA outputs are stored in CA folder.
    2. Generate a private key and a certificate signed by this CA.
    3. Convert the private key, certificate, and server certificate to a C file.
    4. All non-CA outputs are stored in a folder named YOUR_ENDPOINT_NAME.