Skip to content
peter edited this page Jan 23, 2018 · 2 revisions



1. Overview

oneM2M REST api.



2. Features

  • Eclipse oneM2M



3. Installation

$ npm install om2m-rest --save



4. Usage

var Om2m = require('om2m-rest');

// initialize om2m configuration 
var om2m = new Om2m('192.168.1.112', 8282, 'mn-ces', 'my-mn', 'admin', 'admin');

// create your application 
om2m.createApp('MY_SENSOR', 'my_sensor', 'Type/sensor', false, function (err, msg) {
    console.log(msg);
});

// create your container 
om2m.createCont('MY_SENSOR', 'DATA', 10, function (err, msg) {
    console.log(msg);
});

// create your content instance 
om2m.createApp('MY_SENSOR', 'DATA', temperature, { sensorValue: 25.6 }, function (err, msg) {
    console.log(msg);
});



5. Om2mClass

Exposed by require('coap-node').

  • An instance of this class is denoted as om2m in this document.



new Om2m(host, port, type, name, username, password)

Create a new instance of Om2m class.

Arguments:

  1. host (String): Target host address.
  2. port (String): Target port.
  3. type (String): Type of the target.
  4. name (String): Name of the target.
  5. username (String): Usernameof the target.
  6. password (String | Number): Password of the target.

Returns:

  • (Object): om2m.

Examples:

var Om2m = require('om2m-rest');

// initialize om2m configuration 
var om2m = new Om2m('192.168.1.112', 8282, 'mn-ces', 'my-mn', 'admin', 'admin');



getResc([callback])

Arguments:

  1. callback (Function): function (err, msg) { }, where msg is the response to tell whether this request is successful.

Returns:

  • (none)

Examples:

om2m.getResc(function (err, msg) {
    console.log(msg);
});



createApp(appName, api, lbl, rr[, poa[, callback]])

Arguments:

  1. appName (String): .
  2. api (String): .
  3. lbl (String): .
  4. rr (Boolean): .
  5. poa (String): .
  6. callback (Function): function (err, msg) { }, where msg is the response to tell whether this request is successful.

Returns:

  • (none)

Examples:

// `rr` is false
om2m.createApp('MY_SENSOR', 'my_sensor', 'Type/sensor', false, function (err, msg) {
    console.log(msg);
});

// `rr` is trun
om2m.createApp('MY_SENSOR', 'my_sensor', 'Type/sensor', trun, 'http://192.168.1.110:1400', function (err, msg) {
    console.log(msg);
});



createCont(appName, contName, mbs[, callback])

Arguments:

  1. appName (String): .
  2. contName (String): .
  3. mbs (String | Number): .
  4. callback (Function): function (err, msg) { }, where msg is the response to tell whether this request is successful.

Returns:

  • (none)

Examples:

om2m.createCont('MY_SENSOR', 'DATA', 10, function (err, msg) {
    console.log(msg);
});



createDataInst(appName, contName, category, value[, callback])

Arguments:

  1. appName (String): .
  2. contName (String): .
  3. category (String): .
  4. value (Object): .
  5. callback (Function): function (err, msg) { }, where msg is the response to tell whether this request is successful.

Returns:

  • (none)

Examples:

om2m.createDataInst('MY_SENSOR', 'DATA', temperature, { sensorValue: 25.6 }, function (err, msg) {
    console.log(msg);
});



createDescInst(appName, contName, category, value[, callback])

Arguments:

  1. appName (String): .
  2. contName (String): .
  3. category (String): .
  4. value (Array): .
  5. callback (Function): function (err, msg) { }, where msg is the response to tell whether this request is successful.

Returns:

  • (none)

Examples:

om2m.createDescInst('MY_SENSOR', 'DATA', temperature, [ 'getValue' ], function (err, msg) {
    console.log(msg);
});