Analysis of LWM2M protocol based on NB-IoT, IoT applications in the cellular-based narrowband IoT scenario

The LWM2M protocol is a lightweight M2M protocol formulated by the OMA organization. It is mainly for IoT applications in the cellular-based Narrow Band Internet of Things (NB-IoT) scenario, focusing on the Low Power Wide Coverage (LPWA) IoT The (IoT) market is an emerging technology that can be widely used worldwide. It has the characteristics of wide coverage, multiple connections, low speed, low cost, low power consumption, and excellent architecture.
The mobile OneNET platform uses the NB-IOT-based LWM2M protocol and CoAP protocol to implement the communication between the UE and the platform. The LWM2M protocol is an application layer protocol, and the CoAP protocol is a transport layer protocol.
1. LWM2M protocol logical entities and logical interfaces
(1) LwM2M defines three logical entities:
LWM2M Server: access machine, platform server interface;
LWM2M client: client, responsible for executing server commands and reporting execution results;
Bootstrap server: The boot machine is responsible for configuring the LWM2M client.
(2) There are 4 logical interfaces between these three logical entities:
Bootstrap: Bootstrap Server uses this interface to configure Clinet-for example, the URL address of the LWM2M server;
Device Discovery and Registration: the client registers to the server and informs the server client Supported capabilities;
Device Management and Service Enablement: LWM2M Server sends instructions to Client and receives responses.
Information Reporting: LWM2M Client reports its resource information, such as sensor temperature.
The relationship between these three logical entities and the four logical interfaces is as follows:
Insert picture description here

2. LWM2M protocol stack
Lightweight M2M protocol stack structure is shown in the figure below:
Insert picture description here
2.1 LWM2M Objects
Each object (object) corresponds to a specific functional entity of the client. The LWM2M specification defines some standard Objects, such as:
urn:oma:lwm2m:oma:2; (LWM2M Server Object, where '2' is the object ID).
urn:oma:lwm2m:oma:3; (LWM2M Access Control Object, where '3' is the object ID).
In addition to the objects defined by LWM2M, the IPSO organization also defines some commonly used sensor objects, such as:
urn:oma:lwm2m:ext:3311; (IPSO Light Control, where '3311' is the object ID).
Each object can have multiple resources, and each resource represents an object attribute or function. For example, part of the resource of the sensor with object ID 3311 is described in the following table:
Insert picture description here
2.2 LWM2M Protocol
LWM2M Protocol defines some logical operations, such as Read, Write, Execute, Create and Delete. Through these logical operations, the data interaction between the cloud platform and the terminal device is realized.
3. Access to the mobile OneNet instance based on the LWM2M protocol
Here we use the AM20E module of Beijing Miracle IOT to access the OneNET platform. Before accessing, you need to complete user registration and product creation on the OneNET platform side.
3.1 Product creation

  1. After completing user registration and logging in, enter the developer center to create a product.
    Insert picture description here
  2. When creating a product, fill in your product information based on the content of the page.
    Insert picture description here
    Insert picture description here

3. After the product is created, add the device. Among them, the IMEI number of the AM20E module and the IMSI number of the SIM card can be obtained through the AT+CGSN command and the AT+CIMI command, and filled in by using the serial debugging tool.
Insert picture description here
4. After the product is created and the device is added, you can see the added device in the device management interface. The gray device bar indicates offline status.
Insert picture description here

5. In the module side access process, when the module receives the registration result +MIPLEVENT:0,6 returned by the platform side, the registration is completed. The device bar will display green, indicating the online status.
Insert picture description here
3.2 Module access to OneNET platform process After the
module completes the initialization process and successfully registers with the network, access the OneNET platform. The flowchart is shown below.

Insert picture description here
In the flow chart of the above module accessing the OneNET platform, it is necessary to explain: in the
process of data interaction, platform READ/WRITE/EXECUTE/PARAMETER operation request, module resource value report, and module update registration information, these three steps are in no particular order , So they are not numbered sequentially.
The dotted arrow in the figure indicates that OneNET platform will return the response result +MIPLEVENT to the module side. +MIPLEVENT return value please refer to the description of AT command set.
3.3 Reference example
1. Module initialization
AT
+PBREADY

AT //AT response is normal
OK

AT+CSQ
+CSQ: 20,99 OK//Check CSQ is normal

AT+CEREG?
+CEREG: 0,1 OK//Module registration network is normal

2. The module is connected to the OneNET platform, complete the registration
AT+XIIC=1 OK//Get the IP address

AT+XIIC?
+XIIC: 1,100.103.238.182 //Query IP address successfully obtained
OK

AT+MIPLVER? //Query basic communication suite version 2.2.0
OK

AT+MIPLCREATE
+MIPLCREATE:0 //Create the basic communication package successfully, the return is 0, 0 is the basic communication package identifier, and subsequent AT commands need to use it
OK

AT+MIPLADDOBJ=0,3303,2,"11",6,1
//Add object 3303, 2 instances, 6 attributes. The object Objectid3303 must comply with the naming convention, please refer to the link:
http://www.openmobilealliance.org/wp/OMNA/LwM2M/LwM2MRegistry.html,
OK

AT+MIPLOPEN=0,3600 OK
//Module request registration
+MIPLEVENT:0,1 //OneNET platform returns result BOOTSTRAP_START
+MIPLEVENT:0,2 //OneNET platform returns result BOOTSTRAP_SUCCESS
+MIPLEVENT:0,4 //OneNET platform returns Result CONNECT_SUCCESS
+MIPLEVENT:0,6 //OneNET platform returns the result REG_SUCCESS
//The above return value received by the module side indicates that the registration request is successful. At this time, refresh the OneNET platform to see that the device displays the green online status.
Insert picture description here

3. The module responds to Observer requests and Discover requests on the OneNET platform to complete the subscription.

+MIPLOBSERVE:0,87667,1,3303,0,-1 //OneNET platform object/instance Observe request
AT+MIPLOBSERVERSP=0,87667,1 //The module responds to Observe request, where msgid=87667 must correspond to OneNET platform Observe request The msgid issued in the message
OK
+MIPLEVENT:0,21 //The module responded to the Observe request successfully
+MIPLDISCOVER:0,153204,3303 //OneNET platform object Discover request
+MIPLDISCOVER:0,153204,3303
AT+MIPLDISCOVERRSP=0,153204 ,1,34,"5700;5701;5601;5602;5603;5604;5605" OK
//The module responds to the Discover request, where msgid=153204 must correspond to the msgid sent in the Discover request message on the OneNET platform. When the module responds to the
Discover request, it creates 7 resources, each resource is separated by a semicolon ";", among which the resource Resourceid 5700;5701;5601;5602;5603;5604;5605
must comply with the IPSO specification definition, please refer to the link:
http: //www.openmobilealliance.org/wp/OMNA/LwM2M/LwM2MRegistry.html,
+MIPLEVENT:0,21
//The platform returns the discovery request result to the module to complete the subscription. At this time, the resource list information corresponding to object 3303 can be viewed on the OneNET platform.
Insert picture description here
Insert picture description here

4. Module and OneNET platform data interaction

+MIPLREAD:0,21459,3303,0,5700
//The platform requests the READ request of the specified resource (here, Resourceid 5700)
AT+MIPLREADRSP=0,21459,1,3303,0,5700,4,5,20.22, 0,0
//The module responds to the platform READ request, where msgid=21459 must correspond to the msgid issued in the OneNET platform READ request message, and 4 represents the float data type. The module returns the resource value of 20.22 to the OneNET platform side.
OK
+MIPLEVENT:0,21
//The platform requests the EXECUTE of the specified resource (here, Resourceid 5605)
+MIPLEXECUTE:0,11671,3303,0,5605,5,"reset
AT+MIPLEXECUTERSP=0,11671,2/module Execute EXECUTE request
OK
+MIPLEVENT:0,21 //The module receives the response result returned by the platform
AT+MIPLNOTIFY=0,77861,3303,0,5700,4,4,23.5,0,0 OK
//The module faces the platform side Report the specified resource value, here the float type value 810.56 is reported to Resourceid 5700, where msgid=129584 must correspond
to the msgid issued in the Observer request message of the OneNET platform.
+MIPLEVENT:0,26
//The module receives the response from the platform As a result, the resource value is successfully reported. Click the "Operation" details button to see the data flow of the resource value reported.
//The module receives the response result returned by the platform and refreshes the OneNET platform. You can see instance 0 and the attribute value of resource 5700 is updated to 20.2199999.
Insert picture description here

AT+MIPLUPDATE=0,3600,1//Module update registration information
+MIPLEVENT:0,11//The module receives the response result returned by the platform, and the update registration information is successful
Insert picture description here

5. Module delete object

AT+MIPLDELOBJ=0,3303 OK

6. Module request logout

AT+MIPLCLOSE=0 OK
+MIPLEVENT:0,15

7. Delete the basic communication suite

AT+MIPLDELETE=0 OK

Insert picture description here

Guess you like

Origin blog.csdn.net/AmazIOT/article/details/107207596