Skip to content

MLopezJ/minimalist-lwm2m-client

Minimalist LwM2M Client

Test and Release semantic-release Renovate Commitizen friendly code style: prettier ESLint: TypeScript

a minimal LwM2M client which performe the following operations:

  • Client registration from Register interface
  • Discover from Dev Mang & Serv Enab interface
  • Read from Dev Mang & Serv Enab interface
  • Send from Information Reporting interface

Installation

npm install

Test

npm test

Execution

npx tsx src/index.ts

Usage

  1. Create a device in coiote using No-Sec security mode
  2. Update value of deviceName with the name of the device just created in Coiote. deviceName
  3. Runs execution command

Description

After the execution is initialized, the device send a register operation to the LwM2M server and wait for the response. If the server accept the registratrion request, the client open a socket connection to hear about Discover and Read operation. After that, the device wait 10 seconds and onces the time is expired, the device trigger a send operation to update the value of resource /3/0/0.

Client Registration from Register interface

This action is executed by the LwM2M client, in this case this device.

Details

  • host: eu.iot.avsystem.cloud
  • port: 5683
  • method: POST
  • pathname: /rd
  • query: ep=xxxx&lt=xxxx&lwm2m=xxxx&b=xxxx, where:
    • ep is the name of the device
    • lt is the lifetime of the opening conenction
    • lwm2m is the version of the protocol suported by the device
    • b stands for biding mode
  • payload: </>;ct=110,112,11543;hb,<1/0>, <3/0> , where:
    • ct stands for content type
    • 110 is the id of SenML JSON
    • 112 is the id of SenML CBOR
    • 11543 is the id of LwM2M JSON

If request is successful, it returns a port number.

Discover from Dev Mang & Serv Enab interface

This action is triggered by the server, in this case Coiote, and the client should listen from the port returned in the Client Registration operation in order to receive the request.

Discover from Dev Mang & Serv Enab interface

This action is triggered by the server, in this case Coiote, and the client should listen from the port returned in the Client Registration operation in order to receive the request.

Details

  • port: the one returned in Client Registration operation from Register interface
  • content-format: 'application/vnd.oma.lwm2m+json'
  • payload:
    {
    bn: '/3/0/',
    e: [
     { n: '0/0', sv: 'Nordic' },
     { n: '0/1', sv: '00010' },
     { n: '0/2', sv: '00000',},
     // ....
     ]
    }

Send from Information Reporting interface

This action is executed by the LwM2M client, in this case this device.

Details

  • host: eu.iot.avsystem.cloud
  • port: 5683
  • method: POST
  • pathname: /dp
  • content-format: application/senml+cbor & application/senml+json
  • payload:
  // for application/senml+cbor'
  81 a2 00 66 2f 33 2f 30 2f 30 03 6f 6e 65 77 4d 61 6e 75 66 61 63 74 75 72 65 72
  // { 0: '/3/0/0', 3: 'newManufacturer' }

or

  // for application/senml+json
  [{ 'n': '/3/0/0', 'vs': newManufacturer }]

Links