samples/net/lwm2m_client/README.html · samples/net/lwm2m_client/README.rst 공식 원문 ↗

Zephyr 3.7.0 · Samples · Networking · Device Management

LwM2M Client

DTLS·Bootstrap·OpenThread·Queue Mode·LTE-M overlay와 Smart Object registration을 구성합니다.

Official pathsamples/net/lwm2m_client/README.html
Source filesamples/net/lwm2m_client/README.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

6개 configuration 표, Leshan 두 server, 13개 command/output와 registration lifecycle을 보존합니다.

Protocol

LwM2M · CoAP/UDP

Security

DTLS · PSK

Modes

Bootstrap · Queue

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 03313C0BDBE71636CB0F9FAFB7E0EBBE4DF9CB1D7A208EFBED49F8FC32C63294
.. zephyr:code-sample:: lwm2m-client
   :name: LwM2M client
   :relevant-api: lwm2m_api

   Implement a LwM2M client that connects to a LwM2M server.

Overview
********

Lightweight Machine to Machine (LwM2M) is an application layer protocol
based on CoAP/UDP, and is designed to expose various resources for reading,
writing and executing via an LwM2M server in a very lightweight environment.

This LwM2M client sample application for Zephyr implements the LwM2M library
and establishes a connection to an LwM2M server using the
`Open Mobile Alliance Lightweight Machine to Machine Technical Specification`_
(Section 5.3: Client Registration Interface).

.. _Open Mobile Alliance Lightweight Machine to Machine Technical Specification:
    http://www.openmobilealliance.org/release/LightweightM2M/V1_0-20170208-A/OMA-TS-LightweightM2M-V1_0-20170208-A.pdf

The source code for this sample application can be found at:
:zephyr_file:`samples/net/lwm2m_client`.

Requirements
************

- :ref:`networking_with_eth_qemu`, :ref:`networking_with_qemu` or :ref:`networking_with_native_sim`
- Linux machine
- Leshan Demo Server (https://eclipse.org/leshan/)

Building and Running
********************

There are configuration files for various setups in the
samples/net/lwm2m_client directory:

.. list-table::

    * - :file:`prj.conf`
      - This is the standard default config.

    * - :file:`overlay-bootstrap.conf`
      - This overlay config can be added to enable LWM2M Bootstrap support.

    * - :file:`overlay-ot.conf`
      - This overlay config can be added for OpenThread support.

    * - :file:`overlay-dtls.conf`
      - This overlay config can be added for DTLS support via MBEDTLS.

    * - :file:`overlay-queue.conf`
      - This overlay config can be added to enable LWM2M Queue Mode support.

    * - :file:`overlay-tickless.conf`
      - This overlay config can be used to stop LwM2M engine for periodically interrupting socket polls. It can have significant effect on power usage on certain devices.

Build the lwm2m-client sample application like this:

.. zephyr-app-commands::
   :zephyr-app: samples/net/lwm2m_client
   :board: <board to use>
   :conf: <config file to use>
   :goals: build
   :compact:

The easiest way to setup this sample application is to build and run it
as a native_sim application or as a QEMU target using the default configuration :file:`prj.conf`.
This requires a small amount of setup described in :ref:`networking_with_eth_qemu`, :ref:`networking_with_qemu` and :ref:`networking_with_native_sim`.

Download and run the latest build of the Leshan Demo Server:

.. code-block:: console

    $ wget https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar
    $ java -jar ./leshan-server-demo.jar -wp 8080

You can now open a web browser to: http://localhost:8080 This is where you
can watch and manage connected LwM2M devices.

Build the lwm2m-client sample application for QEMU like this:

.. zephyr-app-commands::
   :zephyr-app: samples/net/lwm2m_client
   :host-os: unix
   :board: qemu_x86
   :goals: run
   :compact:

The sample will start and automatically connect to the Leshan Demo Server with
an IPv6 client endpoint "qemu_x86".

To change the sample to use IPv4, disable IPv6 by changing these two
configurations in ``prj.conf``::

    CONFIG_NET_IPV6=n
    CONFIG_NET_CONFIG_NEED_IPV6=n

DTLS Support
============

To build the lwm2m-client sample for QEMU with DTLS support do the following:

.. zephyr-app-commands::
   :zephyr-app: samples/net/lwm2m_client
   :host-os: unix
   :board: qemu_x86
   :conf: "prj.conf overlay-dtls.conf"
   :goals: run
   :compact:

Setup DTLS security in Leshan Demo Server:

1. Open up the Leshan Demo Server web UI
#. Click on "Security"
#. Click on "Add new client security configuration"
#. Enter the following data:

    * Client endpoint: qemu_x86
    * Security mode: Pre-Shared Key
    * Identity: Client_identity
    * Key: 000102030405060708090a0b0c0d0e0f

#. Start the Zephyr sample

Bootstrap Support
=================

In order to run Bootstrap procedure with the sample, you need to download and
run the Leshan Demo Bootstrap Server:

.. code-block:: console

    $ wget https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-bsserver-demo.jar
    $ java -jar ./leshan-bsserver-demo.jar -wp 8888 -lp 5783 -slp 5784


You can now open a web browser to: http://localhost:8888 The Demo Bootstrap
Server web UI will open, this is where you can configure your device for
bootstrap.

Configure the lwm2m-client sample in the Demo Bootstrap Server:

1. Click on "Add new client bootstrap configuration"
#. Enter the following data:

    * Client endpoint: qemu_x86

#. In the ``LWM2M Server`` tab, enter the following data:

    * LWM2M Server URL: coap://[2001:db8::2]:5683 (or coap://192.0.2.2:5683 if IPv4 is used)
    * Security mode: No Security

#. The ``LWM2M Bootstrap Server`` tab can be left intact in the default
   configuration (No Security).

To build the lwm2m-client sample for QEMU with Bootstrap enabled do the
following:

.. zephyr-app-commands::
   :zephyr-app: samples/net/lwm2m_client
   :host-os: unix
   :board: qemu_x86
   :conf: "prj.conf overlay-bootstrap.conf"
   :goals: run
   :compact:

The sample will start and automatically connect to the Leshan Demo Bootstrap
Server to obtain the LwM2M Server information. After that, the sample will
automatically connect to the Leshan Demo Sever, as it was indicated in the
Bootstrap Server configuration.

It is possible to combine overlay files, to enable DTLS and Bootstrap for
instance. In that case, the user should make sure to update the port number in
the overlay file for Bootstrap over DTLS (5784 in case of Leshan Demo Bootstrap
Server) and to configure correct security mode in the ``LWM2M Bootstrap Server``
tab in the web UI (Pre-shared Key).

OpenThread Support
==================

To build the lwm2m-client sample for hardware requiring OpenThread for
networking do the following:

.. zephyr-app-commands::
   :zephyr-app: samples/net/lwm2m_client
   :host-os: unix
   :board: <board to use>
   :conf: "prj.conf overlay-ot.conf"
   :goals: build
   :compact:

Note: If not provisioned (fully erased before flash), device will form
new OpenThread network and promote itself to leader (Current role: leader).
To join into already existing OT network, either enable CONFIG_OPENTHREAD_JOINER=y
and CONFIG_OPENTHREAD_JOINER_AUTOSTART=y and send join request from other
already joined device with joiner capabilities, or provision it manually
from console:

.. code-block:: console

   ot thread stop
   ot channel <channel>
   ot networkname <network name>
   ot masterkey <key>
   ot panid <panid>
   ot extpanid <extpanid>
   ot thread start

You could get all parameters for existing OT network from your OTBR with
the following command:

.. code-block:: console

    wpanctl get Thread:ActiveDataset

Queue Mode Support
==================

To build the lwm2m-client sample with LWM2M Queue Mode support do the following:

.. zephyr-app-commands::
   :zephyr-app: samples/net/lwm2m_client
   :host-os: unix
   :board: <board to use>
   :conf: "prj.conf overlay-queue.conf"
   :goals: build
   :compact:

With Queue Mode enabled, the LWM2M client will register with "UDP with Queue
Mode" binding. The LWM2M engine will notify the application with
``LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF`` event when the RX window
is closed so it can e. g. turn the radio off. The next RX window will be open
with consecutive ``LWM2M_RD_CLIENT_EVENT_REG_UPDATE_COMPLETE`` event.

WNC-M14A2A LTE-M Modem Support
==============================

To build the lwm2m-client sample for use with the WNC-M14A2A LTE-M modem
shield do the following:

.. zephyr-app-commands::
   :zephyr-app: samples/net/lwm2m_client
   :host-os: unix
   :board: <board to use>
   :conf: "prj.conf overlay-wncm14a2a.conf"
   :goals: build
   :compact:

Sample output without DTLS enabled
==================================

The following is sample output from the QEMU console.  First, LwM2M engine is
initialized.  Then, several LwM2M Smart Objects register themselves with the
engine.  The sample app then sets some client values so that they can be seen
in the Leshan Demo Server interface, and finally, the registration request is
sent to the server where the endpoint is initialized.

.. code-block:: console

    To exit from QEMU enter: 'CTRL+a, x'
    [QEMU] CPU: qemu32,+nx,+pae
    qemu-system-i386: warning: Unknown firmware file in legacy mode: genroms/multiboot.bin

    shell> [lib/lwm2m_engine] [DBG] lwm2m_engine_init: LWM2M engine thread started
    [lwm2m_obj_security] [DBG] security_create: Create LWM2M security instance: 0
    [lwm2m_obj_server] [DBG] server_create: Create LWM2M server instance: 0
    [lwm2m_obj_device] [DBG] device_create: Create LWM2M device instance: 0
    [lwm2m_obj_firmware] [DBG] firmware_create: Create LWM2M firmware instance: 0
    [lwm2m-client] [INF] main: Run LWM2M client
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/0, value:0x0001c99e, len:6
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/1, value:0x0001c9ab, len:23
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/2, value:0x0001c9c9, len:9
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/3, value:0x0001c9d9, len:3
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/9, value:0x0041a3a4, len:1
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/10, value:0x0041a3b4, len:4
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/17, value:0x0001c9fc, len:16
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/18, value:0x0001ca14, len:5
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/20, value:0x0041a3a4, len:1
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/21, value:0x0041a3b4, len:4
    [lib/lwm2m_engine] [DBG] lwm2m_engine_create_obj_inst: path:3303/0
    [ipso_temp_sensor] [DBG] temp_sensor_create: Create IPSO Temperature Sensor instance: 0
    [lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3303/0/5700, value:0x0041a3b8, len:8
    [lib/lwm2m_rd_client] [INF] lwm2m_rd_client_start: LWM2M Client: qemu_x86
    [lib/lwm2m_rd_client] [INF] sm_do_init: RD Client started with endpoint 'qemu_x86' and client lifetime 0
    [lib/lwm2m_rd_client] [DBG] sm_send_registration: registration sent [2001:db8::2]
    [lib/lwm2m_engine] [DBG] lwm2m_udp_receive: checking for reply from [2001:db8::2]
    [lib/lwm2m_rd_client] [DBG] do_registration_reply_cb: Registration callback (code:2.1)
    [lwm2m-client] [DBG] rd_client_event: Registration complete
    [lib/lwm2m_rd_client] [INF] do_registration_reply_cb: Registration Done (EP='EZd501ZF26')
    [lib/lwm2m_engine] [DBG] lwm2m_udp_receive: reply 0x004001ec handled and removed

Part 3

한국어 전문 번역

개요

Lightweight Machine to Machine(LwM2M)은 CoAP/UDP 기반 application layer protocol입니다. 매우 가벼운 환경에서 LwM2M server가 여러 resource를 read, write, execute할 수 있도록 노출하도록 설계됐습니다.

이 Zephyr LwM2M client sample application은 LwM2M library를 구현하고 Open Mobile Alliance LwM2M Technical Specification의 5.3절 Client Registration Interface에 따라 LwM2M server와 연결을 수립합니다.

Sample application source code는 samples/net/lwm2m_client에 있습니다.

요구 사항

Build와 실행

samples/net/lwm2m_client directory에는 여러 구성을 위한 다음 configuration file이 있습니다.

LwM2M client configuration file
File용도
prj.conf표준 기본 configuration입니다.
overlay-bootstrap.confLwM2M Bootstrap 지원을 활성화하는 overlay입니다.
overlay-ot.confOpenThread 지원을 추가하는 overlay입니다.
overlay-dtls.confMBEDTLS를 통한 DTLS 지원을 추가하는 overlay입니다.
overlay-queue.confLwM2M Queue Mode를 활성화하는 overlay입니다.
overlay-tickless.confLwM2M engine이 주기적으로 socket poll을 interrupt하지 않게 하며, 일부 device의 power usage를 크게 줄일 수 있습니다.

다음과 같이 lwm2m-client sample application을 build합니다.

west build -b <board to use> samples/net/lwm2m_client -- -DCONF_FILE=<config file to use>

가장 간단한 방법은 기본 prj.conf로 native_sim application 또는 QEMU target을 build하고 실행하는 것입니다. 앞서 연결한 QEMU Ethernet, QEMU networking, native_sim networking 설정이 조금 필요합니다.

최신 Leshan Demo Server build를 내려받아 실행합니다.

$ wget https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-server-demo.jar
$ java -jar ./leshan-server-demo.jar -wp 8080

Web browser에서 http://localhost:8080을 열면 연결된 LwM2M device를 관찰하고 관리할 수 있습니다.

QEMU용 lwm2m-client sample을 다음과 같이 build하고 실행합니다.

west build -b qemu_x86 samples/net/lwm2m_client
west build -t run

Sample은 시작 후 IPv6 client endpoint qemu_x86으로 Leshan Demo Server에 자동 연결합니다.

IPv4를 사용하려면 prj.conf에서 다음 두 configuration으로 IPv6를 비활성화합니다.

CONFIG_NET_IPV6=n
CONFIG_NET_CONFIG_NEED_IPV6=n

DTLS 지원

DTLS 지원을 포함해 QEMU용 sample을 build하려면 다음 명령을 실행합니다.

west build -b qemu_x86 samples/net/lwm2m_client -- -DCONF_FILE="prj.conf overlay-dtls.conf"
west build -t run

Leshan Demo Server에서 DTLS security를 다음과 같이 설정합니다.

  1. Leshan Demo Server web UI를 엽니다.
  2. Security를 선택합니다.
  3. Add new client security configuration을 선택합니다.
  4. Client endpoint는 qemu_x86, Security mode는 Pre-Shared Key, Identity는 Client_identity, Key는 000102030405060708090a0b0c0d0e0f로 입력합니다.
  5. Zephyr sample을 시작합니다.

Bootstrap 지원

Sample에서 Bootstrap 절차를 실행하려면 Leshan Demo Bootstrap Server를 내려받아 실행합니다.

$ wget https://ci.eclipse.org/leshan/job/leshan/lastSuccessfulBuild/artifact/leshan-bsserver-demo.jar
$ java -jar ./leshan-bsserver-demo.jar -wp 8888 -lp 5783 -slp 5784

Web browser에서 http://localhost:8888을 열면 device의 bootstrap 설정을 구성하는 Demo Bootstrap Server web UI가 나타납니다.

Demo Bootstrap Server에서 lwm2m-client sample을 다음과 같이 구성합니다.

  1. Add new client bootstrap configuration을 선택합니다.
  2. Client endpoint에 qemu_x86을 입력합니다.
  3. LWM2M Server tab에서 URL을 IPv6이면 coap://[2001:db8::2]:5683, IPv4이면 coap://192.0.2.2:5683으로 지정하고 Security mode를 No Security로 설정합니다.
  4. LWM2M Bootstrap Server tab은 기본값인 No Security 상태로 둡니다.

Bootstrap을 활성화한 QEMU sample은 다음과 같이 build하고 실행합니다.

west build -b qemu_x86 samples/net/lwm2m_client -- -DCONF_FILE="prj.conf overlay-bootstrap.conf"
west build -t run

Sample은 Leshan Demo Bootstrap Server에 자동 연결해 LwM2M Server 정보를 얻은 다음 Bootstrap Server configuration에 지정된 Leshan Demo Server로 자동 연결합니다.

DTLS와 Bootstrap처럼 overlay file을 결합할 수도 있습니다. 이 경우 Bootstrap over DTLS용 overlay port를 Leshan Demo Bootstrap Server의 5784로 갱신하고 web UI의 LWM2M Bootstrap Server tab에서 security mode를 Pre-shared Key로 올바르게 설정해야 합니다.

OpenThread 지원

Networking에 OpenThread가 필요한 hardware용 sample은 다음과 같이 build합니다.

west build -b <board to use> samples/net/lwm2m_client -- -DCONF_FILE="prj.conf overlay-ot.conf"

Device가 provision되지 않았다면, 즉 flash 전에 완전히 erase했다면 새 OpenThread network를 만들고 자신을 leader로 승격합니다.

기존 OT network에 참가하려면 CONFIG_OPENTHREAD_JOINER=y와 CONFIG_OPENTHREAD_JOINER_AUTOSTART=y를 활성화하고 joiner 기능이 있는 기존 device에서 join request를 보내거나 console에서 수동 provision합니다.

ot thread stop
ot channel <channel>
ot networkname <network name>
ot masterkey <key>
ot panid <panid>
ot extpanid <extpanid>
ot thread start

기존 OT network의 모든 parameter는 OTBR에서 다음 명령으로 얻을 수 있습니다.

wpanctl get Thread:ActiveDataset

Queue Mode 지원

LwM2M Queue Mode 지원을 포함해 sample을 build하려면 다음 명령을 실행합니다.

west build -b <board to use> samples/net/lwm2m_client -- -DCONF_FILE="prj.conf overlay-queue.conf"

Queue Mode를 활성화하면 LwM2M client는 UDP with Queue Mode binding으로 register합니다. RX window가 닫히면 LwM2M engine이 application에 LWM2M_RD_CLIENT_EVENT_QUEUE_MODE_RX_OFF event를 알려 radio 등을 끌 수 있게 합니다. 다음 RX window는 이어지는 LWM2M_RD_CLIENT_EVENT_REG_UPDATE_COMPLETE event와 함께 열립니다.

WNC-M14A2A LTE-M Modem 지원

WNC-M14A2A LTE-M modem shield용 lwm2m-client sample은 다음과 같이 build합니다.

west build -b <board to use> samples/net/lwm2m_client -- -DCONF_FILE="prj.conf overlay-wncm14a2a.conf"

DTLS를 활성화하지 않은 Sample 출력

다음은 QEMU console의 sample 출력입니다. 먼저 LwM2M engine이 초기화되고 여러 LwM2M Smart Object가 engine에 자신을 register합니다. Sample application은 Leshan Demo Server interface에서 볼 client 값을 설정한 뒤 server로 registration request를 보내 endpoint를 초기화합니다.

To exit from QEMU enter: 'CTRL+a, x'
[QEMU] CPU: qemu32,+nx,+pae
qemu-system-i386: warning: Unknown firmware file in legacy mode: genroms/multiboot.bin

shell> [lib/lwm2m_engine] [DBG] lwm2m_engine_init: LWM2M engine thread started
[lwm2m_obj_security] [DBG] security_create: Create LWM2M security instance: 0
[lwm2m_obj_server] [DBG] server_create: Create LWM2M server instance: 0
[lwm2m_obj_device] [DBG] device_create: Create LWM2M device instance: 0
[lwm2m_obj_firmware] [DBG] firmware_create: Create LWM2M firmware instance: 0
[lwm2m-client] [INF] main: Run LWM2M client
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/0, value:0x0001c99e, len:6
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/1, value:0x0001c9ab, len:23
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/2, value:0x0001c9c9, len:9
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/3, value:0x0001c9d9, len:3
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/9, value:0x0041a3a4, len:1
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/10, value:0x0041a3b4, len:4
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/17, value:0x0001c9fc, len:16
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/18, value:0x0001ca14, len:5
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/20, value:0x0041a3a4, len:1
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3/0/21, value:0x0041a3b4, len:4
[lib/lwm2m_engine] [DBG] lwm2m_engine_create_obj_inst: path:3303/0
[ipso_temp_sensor] [DBG] temp_sensor_create: Create IPSO Temperature Sensor instance: 0
[lib/lwm2m_engine] [DBG] lwm2m_engine_set: path:3303/0/5700, value:0x0041a3b8, len:8
[lib/lwm2m_rd_client] [INF] lwm2m_rd_client_start: LWM2M Client: qemu_x86
[lib/lwm2m_rd_client] [INF] sm_do_init: RD Client started with endpoint 'qemu_x86' and client lifetime 0
[lib/lwm2m_rd_client] [DBG] sm_send_registration: registration sent [2001:db8::2]
[lib/lwm2m_engine] [DBG] lwm2m_udp_receive: checking for reply from [2001:db8::2]
[lib/lwm2m_rd_client] [DBG] do_registration_reply_cb: Registration callback (code:2.1)
[lwm2m-client] [DBG] rd_client_event: Registration complete
[lib/lwm2m_rd_client] [INF] do_registration_reply_cb: Registration Done (EP='EZd501ZF26')
[lib/lwm2m_engine] [DBG] lwm2m_udp_receive: reply 0x004001ec handled and removed

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.