IoT Device Management Using LwM2M

2023-03-10
关注

IoT Device Management using LwM2M
Illustration: © IoT For All

In today’s market, IoT devices come in different forms and shapes. Each device has a unique communication stack which comes with a particular data packet structure and a thoughtfully designed device management layer. Now imagine the struggles of an energy distributor who deployed various brands of smart meters over the years to measure the use of electricity in thousands of buildings. Each meter comes with a different data structure which needs to be formatted. Specific processes need to be implemented to remotely manage the different devices, and particular mechanisms need to be put in place to update the devices’ firmware.

When devices use the LwM2M standard, IoT integrators can be assured that each device similarly reports its data. The configurations and firmware can be updated using similar server commands independent of the hardware, firmware version, or sensors used. Let’s explore the three fundamental components of LwM2M that ensure interoperability: the standardized data format, LwM2M architecture, and LwM2M operations.

“When devices use the LwM2M standard, IoT integrators can be assured that each device similarly reports its data.”

-AVSystem

LwM2M Data Format

IoT Device Management using LwM2M
Welvolver

LwM2M is an application-layer communication protocol developed by OMA SpecWorks to simplify messaging and device management of IoT devices. The protocol defines communication semantics, device management mechanisms, over-the-air updates (FOTA), and telemetry data collection and is well-suited for resource-constrained devices. The LwM2M standard uses so-called IPSO Smart Objects to represent configurations, functionalities, and sensors to realize data interoperability. When structuring the IPSO Smart Objects in a specific way, a language is created that both the LwM2M Client and the LwM2M Server can comprehend. This language contains objects, object instances, and resources.

Wevolver

#1: Objects

Objects represent a physical component (a sensor, LED, or actuator) or a logical entity (such as the preferred radio technology, firmware update configuration, or security implementation). All objects are defined by an object ID. The LwM2M standard defines three mandatory objects which are considered essential for the device to connect and communicate with an LwM2M server. The mandatory objects are:

  1. Object ID 0: LwM2M Security: Contains confidential information about connections to the LwM2M Servers configured on the Client.
  2. Object ID 1: LwM2M Server: Contains non-confidential information about connections to the LwM2M Servers configured on the Client.
  3. Object ID 3: Device: Contains basic information about the device, such as e.g. serial number and firmware version.

Next to the mandatory objects, additional objects can be implemented. Examples of non-mandatory objects are:

  • Object ID 4: Connectivity Monitoring: Provides information about the device’s connectivity status, such as the signal strength and network type.
  • Object ID 5: Firmware Update: Allows for remote firmware updates to be performed.
  • Object ID 6: Location: Provides information about the device’s geographic location, such as its latitude and longitude.
  • Object ID 11: LwM2M APN Connection Profile: Enables a device to connect to an APN.
  • Object ID 3303: Temperature: Reports temperature measurements.
  • Object ID 3313: Accelerometer: Represents a 1-3 axis accelerometer.

#2: Object Instances

Some objects may have multiple object instances. Examples of such objects include the object that manages connections to LwM2M Servers as multiple LwM2M Servers can be configured or devices that contain multiple SIMs with different APN profiles. When devices contain multiple identical sensors, object instances are used to distinguish the different sensors.

#3: Resources

Resources represent specific properties of an object which can be read, written, or executed. Each resource is identified by a unique resource ID. For example, a temperature object has the resource current temperature, a unit of measurement, and a timestamp. Similarly, the device object has resources like manufacturer name, serial number, and firmware version. The location object has the resource’s latitude, longitude, and altitude. All details of the objects and resources are defined in the OMA Registry. There is also a possibility to define your custom object if a specific feature or sensor is not listed in the OMA Registry.

Each resource contains an identifier, a type (float, string, int, opaque), and allowed server operations (such as READ, WRITE or EXECUTE). Let’s take a look at a few examples.

Examples

The device object is represented with the identifier 3, and the resources include:

Resource IDResource nameServer OperationType
0ManufacturerReadString
1Model NumberReadString
3Firmware VersionReadString
4RebootExecutable
13Current TimeWriteableTime
Device Object

The temperature object is represented with the identifier 3303, and the resources include:

Resource IDResource nameServer OperationType
5700Sensor ValueReadFloat
5701Sensor UnitsReadString
5518TimestampReadTime
Temperature Object

When sending data, each message is formatted as: <object id>/<object instance id>/<resource id> = <data>

To send the latest temperature data, it could look something like:  3303/0/5700 = 23.5

To optimize bandwidth, the data is usually encoded to a space-efficient binary payload. Although the data can be sent with plain JSON, more common is to use CBOR or SenML to reduce the payload size.

Sending Latitude and Longitude using the LwM2M data format

Resource Instances

In some cases, resources have multiple resource instances. For example, the Device object 3 includes the resource 6: Available Power Sources. The different instances describe the different power sources:

0: DC power
1: Internal Battery
2: External Battery
3: Fuel Cell
4: Power over Ethernet
5: USB
6: AC (Mains) power
7: Solar

To describe the availability of solar power, the message format becomes: 3/0/6/7.

LwM2M Architecture: Client & Server

The LwM2M architecture comprises the LwM2M Client and the LwM2M Server. The communication works independently of the (wireless) technology used and can run on top of both IP and non-IP networks. Popular IP technologies include WiFi and cellular. Non-IP includes Bluetooth, LoRaWAN, or Wirepas. Non-IP networks can be addressed using IEEE 802.15.4 (6LoWPAN) networks. For example, by running a thread over Bluetooth. 

The LwM2M standard uses the CoAP protocol to let devices easily communicate with the cloud. Think of CoAP as the HTTP protocol, but designed for resource-constrained devices. CoAP is often compared to MQTT as both protocols are commonly used in IoT applications. A key difference is that CoAP uses UDP by default while MQTT relies on TCP. The small overhead of UDP is often seen as an advantage when compared to TCP. Although CoAP can be used with TCP, UDP is often the preferred choice when efficient use of network resources is a priority.

Popular LwM2M Clients include Anjay (maintained by AVSystem) and Zephyr LwM2M Client (maintained by the Zephyr Project). The LwM2M Server provided by AVSystem is called Coiote and can be used to process device data, configurations, and firmware updates.

The LwM2M Client runs on the end device and communicates with the LwM2M server using a secure connection. The client informs the server about the supported objects and resources during its first connection as well as during periodic status updates. Throughout the lifetime of the device, the client sends a notification to the server with telemetry data formatted as defined by the LwM2M standard. All data is captured and stored by the LwM2M Server where it can be further processed or forwarded to specific databases of platforms such as Azure IoT Hub, or AWS IoT Core.

LwM2M Operations

The third core feature of the LwM2M protocol is operations that can be initiated from both the client and the server. Client operations are used to inform the server about telemetry data or the state of the devices. Server operations are used to read or write data, or to remotely update device configurations or firmware over time. Two interfaces can be distinguished: The Information Reporting Interface, and the Device Management Interface.

#1: Information Reporting Interface

Wevolver

The LwM2M Client can inform the server about telemetry data or state changes in real-time, initiated by the Client. The Server can also define the device’s behavior by requesting the device to send data at periodic intervals, or when values exceed a certain threshold (e.g. when the temperature rises above 30 degrees). This can be accomplished using the operations: OBSERVE, SEND, and NOTIFY.

  • OBSERVE: When the Observe operation is invoked, the Client will start sending NOTIFY messages to the Server about its data or state at configurable intervals. The OBSERVE operation can also be canceled when sending CANCEL OBSERVE.

  • SEND: The SEND message is used by the Client to send data to the server without explicit request. Depending on the application firmware it can be used to report new measurements, or inform the server about a change in telemetry data or state.

  • NOTIFY: In response to the OBSERVE operation initiated from the server, the client sends NOTIFY operations with data. Usually, the server provides a bandwidth in which the client needs to send its data. E.g. At least every 1 hour, but no more than once every 15 minutes.

#2: Device Management Interface

The Device Management Interface allows the server to remotely connect with the LwM2M Client and manage its configuration, software, security, etc. The interface comes with a set of standardized operations, all of which are initiated by the Server.

  • DISCOVER: Retrieving the list of objects and resources supported by the Client.
  • READ: Retrieving the current value of a specific resource or an object as a whole.
  • WRITE: Modifying the value of a specific resource, or an object as a whole.
  • EXECUTE: Invoking an action or operation on a resource. For example instructing a device to reset, reboot or upgrade its firmware.
  • CREATE: Creating a new object instance.
  • DELETE: Deleting an object instance.

Simplify With LwM2M

The IoT landscape is fragmented and it’s easy to get lost when digging through wireless technologies, messaging protocols, and data formats. LwM2M promises to simplify the connected world through standardization and interoperability. This is accomplished as a result of the IPSO Smart Objects with predefined identifiers, allowing for the creation of a digital representation of the device. The standardized data format allows any LwM2M Server to easily interpret the data. The client-server architecture specifies how data flows between the end devices and the web. Lastly, the pre-defined operations enable devices to send data and be reconfigured over time.

Tweet

Share

Share

Email

  • Cellular
  • Connectivity
  • Data Analytics
  • IT and Security
  • Mobile

  • Cellular
  • Connectivity
  • Data Analytics
  • IT and Security
  • Mobile

参考译文
物联网设备管理使用LwM2M
在今天的市场上,物联网设备有不同的形式和形状。每个设备都有一个独特的通信堆栈,该堆栈具有特定的数据包结构和经过精心设计的设备管理层。现在想象一下,一个能源分销商多年来部署了各种品牌的智能电表来测量数千栋建筑的用电量。每个仪表都有不同的数据结构,需要格式化。需要实现特定的流程来远程管理不同的设备,并且需要设置特定的机制来更新设备的固件。当设备使用LwM2M标准时,物联网集成商可以确保每个设备都类似地报告其数据。可以使用类似的服务器命令更新配置和固件,而不受硬件、固件版本或所使用的传感器的影响。让我们探讨LwM2M确保互操作性的三个基本组件:标准化的数据格式、LwM2M体系结构和LwM2M操作。“当设备使用LwM2M标准时,物联网集成商可以确保每个设备都类似地报告其数据。”LwM2M是OMA SpecWorks开发的应用层通信协议,旨在简化物联网设备的消息传递和设备管理。该协议定义了通信语义、设备管理机制、无线更新(FOTA)和遥测数据收集,非常适合资源受限的设备。LwM2M标准使用所谓的IPSO智能对象来表示配置、功能和传感器,以实现数据互操作性。当以特定的方式构建IPSO智能对象时,创建了LwM2M客户端和LwM2M服务器都能理解的语言。该语言包含对象、对象实例和资源。对象表示物理组件(传感器、LED或执行器)或逻辑实体(例如首选的无线电技术、固件更新配置或安全实现)。所有对象都由对象ID定义。LwM2M标准定义了三个必需的对象,它们被认为是设备与LwM2M服务器连接和通信所必需的。必选对象包括:在必选对象的基础上,可执行附加对象。一些对象可能有多个对象实例。此类对象的示例包括管理到LwM2M服务器的连接的对象,因为可以配置多个LwM2M服务器,或者包含多个具有不同APN配置文件的SIMs的设备。当设备包含多个相同的传感器时,使用对象实例来区分不同的传感器。资源表示对象的特定属性,可以读、写或执行。每个资源都由唯一的资源ID标识。例如,温度对象具有资源当前温度、测量单位和时间戳。类似地,设备对象具有制造商名称、序列号和固件版本等资源。location对象具有资源的纬度、经度和海拔高度。对象和资源的所有详细信息都在OMA Registry中定义。如果OMA Registry中没有列出特定的功能或传感器,也可以定义自定义对象。每个资源包含一个标识符、一个类型(float、string、int、opaque)和允许的服务器操作(比如READ、WRITE或EXECUTE)。让我们看几个例子。设备对象用标识符3表示,资源包括:温度对象用标识符3303表示,资源包括:发送数据时,每条消息格式化为:<对象id>/<对象实例id>/<资源id>要发送最新的温度数据,它可以是这样的:3303/0/5700 = 23.5 为了优化带宽,数据通常被编码为节省空间的二进制有效负载。虽然可以使用纯JSON发送数据,但更常见的是使用cor或SenML来减小有效负载大小。使用LwM2M数据格式发送纬度和经度在某些情况下,资源有多个资源实例。例如,Device对象3包含资源6:Available Power Sources。不同的实例描述了不同的电源:0:直流电源1:内部电池2:外部电池3:燃料电池4:over电源支持5:USB6: AC(市电)电源7:太阳能为了描述太阳能的可用性,消息格式变成:3/0/6/7。LwM2M架构包括LwM2M客户端和LwM2M服务器。通信工作独立于所使用的(无线)技术,可以运行在IP和非IP网络之上。流行的IP技术包括WiFi和蜂窝网络。非ip包括蓝牙、LoRaWAN或Wirepas。非ip网络可以使用IEEE 802.15.4 (6LoWPAN)网络寻址。例如,通过在蓝牙上运行线程。LwM2M标准使用CoAP协议让设备轻松地与云通信。可以将CoAP看作HTTP协议,但它是为资源受限的设备设计的。CoAP经常与MQTT进行比较,因为这两种协议都常用在物联网应用中。一个关键的区别是CoAP默认使用UDP,而MQTT依赖于TCP。与TCP相比,UDP的小开销通常被视为一个优势。虽然CoAP可以与TCP一起使用,但在高效使用网络资源是优先考虑的情况下,UDP通常是首选。流行的LwM2M客户端包括Anjay(由AVSystem维护)和Zephyr LwM2M客户端(由Zephyr项目维护)。AVSystem提供的LwM2M Server称为Coiote,用于处理设备数据、配置和固件更新。LwM2M Client运行在终端设备上,通过安全连接与LwM2M server通信。客户端在第一次连接期间以及在定期状态更新期间通知服务器所支持的对象和资源。在设备的整个生命周期内,客户端向服务器发送带有LwM2M标准定义的遥测数据格式的通知。所有数据都由LwM2M服务器捕获和存储,可以进一步处理或转发到Azure IoT Hub或AWS IoT Core等平台的特定数据库。LwM2M协议的第三个核心特性是可以从客户机和服务器发起的操作。客户端操作用于通知服务器有关遥测数据或设备的状态。服务器操作用于读取或写入数据,或远程更新设备配置或固件。可以区分两个接口:信息上报接口和设备管理接口。LwM2M客户端可以实时通知服务器遥测数据或状态变化,由客户端发起。服务器还可以通过请求设备定期发送数据,或者当值超过一定阈值(例如当温度上升到30度以上)来定义设备的行为。这可以通过以下操作来完成:OBSERVE、SEND和NOTIFY。设备管理接口允许服务器远程连接到LwM2M客户端并管理其配置、软件、安全等。该接口带有一组标准化操作,所有这些操作都是由服务器发起的。 物联网领域是碎片化的,在挖掘无线技术、消息协议和数据格式时,很容易迷失方向。LwM2M承诺通过标准化和互操作性简化互联世界。这是IPSO智能对象具有预定义标识符的结果,允许创建设备的数字表示。标准化的数据格式允许任何LwM2M服务器轻松地解释数据。客户机-服务器体系结构指定了数据如何在终端设备和web之间流动。最后,预定义的操作使设备能够发送数据并随着时间的推移重新配置。
  • 传感器
  • 服务器类型
  • en
您觉得本篇内容如何
评分

评论

您需要登录才可以回复|注册

提交评论

提取码
复制提取码
点击跳转至百度网盘