-
Notifications
You must be signed in to change notification settings - Fork 7
Home
lwm2m-id is a dictionary of identifiers defined by OMA LightweightM2M(v1.0), IPSO SmartObject Guideline(Smart Objects Starter Pack1.0 and Smart Objects Expansion Pack). Please visit their websites for more information.
$ npm install lwm2m-id --save
lwm2m-id provides you with two getters, i.e. getOid()
and getRid()
, to get the key-value pair of an Object and a Resource identifier. The getter returns an item which has properties of 'key'
and 'value'
, or returns undefined
if not found. In the returned item, item.key
is the idetifier in string and item.value
is the identifier in number.
Let me show you some examples.
var lwm2mid = require('lwm2m-id')
// get Object Id
var oidItem1 = lwm2mid.getOid('device'); // { key: 'device', value: 3 }
var oidItem2 = lwm2mid.getOid(3); // { key: 'device', value: 3 }
var oidItem3 = lwm2mid.getOid('3'); // { key: 'device', value: 3 }
var oidItem4 = lwm2mid.getOid(999); // undefined
var oidItem5 = lwm2mid.getOid('noSuchId'); // undefined
var oidKey = lwm2mid.getOid(3).key; // 'device'
var oidId = lwm2mid.getOid('device').value; // 3
// get Resource Id
// (1) The rid is specific to an Object
var ridItem1 = lwm2mid.getRid('lightCtrl', 'onOff'); // { key: 'onOff', value: 5850 }
var ridItem2 = lwm2mid.getRid(3311, 'onOff'); // { key: 'onOff', value: 5850 }
var ridItem3 = lwm2mid.getRid(3311, 5850); // { key: 'onOff', value: 5850 }
var ridItem4 = lwm2mid.getRid('3311', '5850'); // { key: 'onOff', value: 5850 }
var ridItem5 = lwm2mid.getOid('lightCtrl', 'noSuchId'); // undefined
var ridItem6 = lwm2mid.getOid('noSuchId', 5850); // undefined
var ridKey = lwm2mid.getRid('lightCtrl', 5850).key; // 'onOff'
var ridId = lwm2mid.getRid(3311, 'onOff').value; // 5850
// (2) The rid is an unique id
var ridItem7 = lwm2mid.getRid('sensorValue'); // { key: 'sensorValue', value: 5700 }
var ridItem8 = lwm2mid.getRid(5700); // { key: 'sensorValue', value: 5700 }
var ridItem8 = lwm2mid.getRid('5700'); // { key: 'sensorValue', value: 5700 }
var ridKey = lwm2mid.getRid(5700).key; // 'sensorValue'
var ridId = lwm2mid.getRid('sensorValue').value; // 5700
Returns an item of the Object identifier.
Arguments
- oid (String|Number):
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.
Returns:
- (Object | Undefined) Returns an item of
{ key: 'sampleId', value: 1234 }
, otherwise returnsundefined
if not found.
Example
lwm2mid.getOid('temperature'); // { key: 'temperature', value: 3303 }
lwm2mid.getOid(3303); // { key: 'temperature', value: 3303 }
lwm2mid.getOid('3303'); // { key: 'temperature', value: 3303 }
lwm2mid.getOid('xxxx'); // undefined
lwm2mid.getOid('9999'); // undefined
lwm2mid.getOid(9999); // undefined
Returns an item of the Resource identifier.
There are two kinds of Resource id, the unique Resource id and the Resource id specific to an Object. An Object can use both of these two kinds of Resource id to define its characteristic.
-
Unique Resource id
- Resouce id is a reusable one and its id number is always constant and unique across Objects.
- To query an unique Resource id, only the single argument
rid
is needed.
-
Resource id specific to an Object
- The meaning of a Resource is specific to an Object that holds it.
- To query a Resource id specific to an Object, both
oid
andrid
should be given.
Arguments
- oid (String|Number, optional):
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128. - rid (String|Number):
rid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.
Returns:
- (Object | Undefined) Returns an item of
{ key: 'sampleId', value: 1234 }
, otherwise returnsundefined
if not found.
Example
// get a Resource id specific to an Object
lwm2mid.getRid('location', 'lon'); // { key: 'lon', value: 1 }
lwm2mid.getRid(6, 1); // { key: 'lon', value: 1 }
lwm2mid.getRid('temperature', 'sensorValue'); // { key: 'sensorValue', value: 5700 }
lwm2mid.getRid(3303, 5700); // { key: 'sensorValue', value: 5700 }
lwm2mid.getRid('temperature', '5700'); // { key: 'sensorValue', value: 5700 }
// get an unqiue Resource id
lwm2mid.getRid('appType'); // { key: 'appType', value: 5750 }
lwm2mid.getRid(5750); // { key: 'appType', value: 5700 }
lwm2mid.getRid('5750'); // { key: 'appType', value: 5750 }
Returns the sepc. definitions of an Object.
Arguments
- oid (String|Number):
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.
Returns:
- (Object | Undefined) Returns the definition with an data object, otherwise returns
undefined
if not found. The definition object is of the form:{ multi: false, mand: true }
Property | Description | Possible Settings |
---|---|---|
multi | Allow multiple instances | true, false |
mand | Mandatory | true, false |
* Please refer to Appendix in OMA LightweightM2M(v1.0) specification for details.
Example
lwm2mid.getOdef('temperature');
// returns { "multi": true, "mand": false }
lwm2mid.getOdef('lightCtrl');
// returns { "multi": true, "mand": false }
lwm2mid.getOdef('device');
// returns { "multi": false, "mand": true }
lwm2mid.getOdef('xxxx'); // undefined
Returns the definitions of a Resource specific to an Object.
Arguments
- oid (String|Number, optional):
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128. - rid (String|Number):
rid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.
Returns:
- (Object | Undefined) Returns the definition with an data object, otherwise returns
undefined
if not found. The definition object is of the form:{ access: null, multi: false, mand: true, type: "boolean", range: null, init: false }
Property | Description | Possible Settings |
---|---|---|
access | Access control | 'R', 'W', 'RW', 'E', null (cannot access) |
multi | Allow multiple instances | true, false |
mand | Mandatory | true, false |
type* | Resource value data type | 'boolean', integer', 'float', string', 'time', execute', 'opaque' |
range | Limit of Resource value | A number, null if no limit. |
* Please refer to Appendix C. Data Types in OMA LightweightM2M(v1.0) specification for details.
Example
lwm2mid.getRdef('temperature', 'sensorValue');
// returns { "access": "R", "multi": false, "mand": true, "type": "float", "range": null }
lwm2mid.getRdef('lightCtrl', 5850);
// returns { "access": "RW", "multi": false, "mand": true, "type": "boolean", "range": null }
lwm2mid.getRdef('temperature'); // undefined. rid should be given
lwm2mid.getRdef('xxxx', 1234); // undefined