Skip to content
peter edited this page Jan 24, 2018 · 33 revisions



1. Overview

OMA Lightweight M2M (LWM2M) is a resource constrained device management protocol relies on CoAP. And CoAP is an application layer protocol that allows devices to communicate with each other RESTfully over the Internet.

coap-shepherd, coap-node and lwm2m-bs-server modules aim to provide a simple way to build and manage a LWM2M machine network.

coap-shepherd net

LWM2M Bootstrap Server: lwm2m-bs-server

  • It is a LWM2M Bootstrap Server application framework running on node.js.
  • It is used to provision the LwM2M Client with the information required to register the LwM2M Server(s).
  • It works well with Wakaama.
  • Support LwM2M Client Initiated Bootstrap.

Acronyms and Abbreviations

  • Server: LWM2M Server (server running with coap-shepherd)
  • Client or Client Device: LWM2M Client (machine running with coap-node)
  • bsServer: instance of BootstrapServer Class
  • cnode: instance of CoapNode Class



2. Features

  • Constrained Application Protocol (CoAP)
  • Based on node-coap, a node.js CoAP client/server library
  • Easy to Bootstrap LwM2M Client
  • Client/server interaction through LWM2M-defined interfaces



3. Installation

$ npm install lwm2m-bs-server --save



4. Usage

This example shows how to start a bootstrap server and set a client bootstrap configuration after the server is ready:

var bsServer = require('lwm2m-bs-server');

bsServer.on('ready', function () {
	console.log('Bootstrap server is ready.');

    bsServer.configure('node1', { 
        serverURI: 'coap://leshan.eclipse.org:5683',
        lifetime: 600
    }, function (err, data) {
        if (err)
            console.log(err);
        else 
            console.log(data + ' add a new config');
    });
});

bsServer.start(function (err) {
    if (err) 
        console.log(err);
});



5. Bootstrap Server Class

Exposed by require('lwm2m-bs-server')

  • This class brings you a LWM2M Bootstrap Server. This document uses bsServer to denote the instance of this class.
  • Bootstrap Server default port is 5783.
  • Server configuration is read from file config.js in the lib folder of this module.



bsServer.start([callback])

Start the bsServer.

Arguments:

  1. callback (Function): function (err) { }. Get called after starting procedure is done.

Returns:

  • (none)

Examples:

bsServer.start(function (err) {
    console.log('server is started.');
});



bsServer.stop([callback])

Stop the bsServer.

Arguments:

  1. callback (Function): function (err) { }. Get called after stopping procedure is done.

Returns:

  • (none)

Examples:

bsServer.stop(function (err) {
    console.log('server is stopped.');
});



bsServer.list([clientNames])

list client configurations on bsServer.

Arguments:

  1. clientNames ( String | Array ): A single client name or an array of client names to query for their configurations. All client configurations will be returned if clientNames is not given.

Returns:

  • (Object): client configurations.

Examples:

// list all client configurations.
bsServer.list();
/*
{
    'node1': {
        '0': {
            serverURI: 'coap://leshan.eclipse.org:5683',
            lifetime: 600
        },
        '1':{
            serverURI: 'coap://192.168.1.109:5683',
            lifetime: 240
        }
    },
    'node2': {
        '0': {
            serverURI: 'coap://192.168.1.108:5683',
            lifetime: 180
        }
    }
}
*/

// list the client configurations by clientName
bsServer.list('node1');
/*
{
    '0': {
        serverURI: 'coap://leshan.eclipse.org:5683',
        lifetime: 600
    },
    '1':{
        serverURI: 'coap://192.168.1.109:5683',
        lifetime: 240
    }
}
*/



bsServer.configure(clientName, configs[, callback])

Add LwM2M Client Bootstrap configuration. When the LwM2M Client bootstrap, bsServer will configures the LwM2M Client with Bootstrap configuration.

Arguments:

  1. clientName (String): Client name.
  2. configs (Object | Array): A single configuration or an array of configurations information to enable the LwM2M Client to Register with one or more LwM2M Servers. The configuration options with possible properties given in the following table.
Property Type Mandatory Description
'serverURI' String Mandatory Uniquely identifies the LwM2M Server.
'securityMode' Number Optional Determines which UDP payload security mode is used.
'pubKeyId' Opaque Optional Stores the LwM2M Client’s Certificate, public key or PSK Identity.
'serverPubKeyId' Opaque Optional Stores the LwM2M Server’s or LwM2M Bootstrap-Server’s Certificate, public key.
'secretKey' Opaque Optional Stores the secret key or private key of the security mode.
'smsSecurityMode' Number Optional Determines which SMS security mode is used.
'smsBindingKeyParam' Opaque Optional Stores the KIc, KID, SPI and TAR.
'smsBindingSecretKey' Opaque Optional Stores the values of the key(s) for the SMS binding.
'lwm2mServerSmsNum' Number Optional MSISDN used by the LwM2M Client to send messages to the LwM2M Server via the SMS binding.
'lifetime' Number Optional Specify the lifetime of the registration in seconds.
'defaultMinPeriod' Number Optional The default value the LwM2M Client should use for the Minimum Period of an Observation in the absence of this parameter being included in an Observation.
'defaultMaxPeriod' Number Optional The default value the LwM2M Client should use for the Maximum Period of an Observation in the absence of this parameter being included in an Observation.
'disableTimeout' Number Optional A period to disable the Server.
'notificationStoring' Boolean Optional If true, the LwM2M Client stores “Notify” operations to the LwM2M Server while the LwM2M Server account is disabled or the LwM2M Client is offline. After the LwM2M Server account is enabled or the LwM2M Client is online, the LwM2M Client reports the stored “Notify” operations to the Server.
If false, the LwM2M Client discards all the “Notify” operations or temporarily disables the Observe function while the LwM2M Server is disabled or the LwM2M Client is offline.
The default value is true.
'binding' String Optional This Resource defines the transport binding configured for the LwM2M Client.
  1. callback (Function): function (err) { }. Get called after stopping procedure is done.

Returns:

  • (none)

Examples:

var config = {
    serverURI: 'coap://192.168.1.110:5683',
    lifetime: 600,
    defaultMinPeriod: 10,
    defaultMaxPeriod: 300
};

bsServer.configure('node1', config, function (err, data) {
    if (err)
        console.log(err);
    else 
        console.log(data + ' add a new config');
});



bsServer.remove([clientName[, configId[, callback]]])

Arguments:

  1. clientName (String): Client name.
  2. configId (Number): configId is the config id when finding for a config in Client configurations.
  3. callback (Function): function (err) { }. Get called after stopping procedure is done.

Returns:

  • (none)

Examples:

// remove all client configurations
bsServer.remove(function (err, data) {
    console.log('remove all of client configs');
});

// remove the client configurations by clientName
bsServer.remove('node1', function (err, data) {
    console.log('remove all configs of node1');
});

// remove the config by clientName
bsServer.remove('node2', 1, function (err, data) {
    console.log('remove node2 config 1');
});



Event: 'bootstrapped'

function (clientName) { } Fired when a client successfully bootstraps.



Event: 'error'

function (err) { } Fired when there is an error occurred.