https://github.com/petereb/lwm2m-codec
A codec for lightweight M2M (LWM2M) data formats.
https://github.com/petereb/lwm2m-codec
codec lwm2m
Last synced: about 1 year ago
JSON representation
A codec for lightweight M2M (LWM2M) data formats.
- Host: GitHub
- URL: https://github.com/petereb/lwm2m-codec
- Owner: PeterEB
- License: mit
- Created: 2017-04-13T08:56:36.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-16T03:50:04.000Z (about 8 years ago)
- Last Synced: 2025-04-14T02:35:08.062Z (about 1 year ago)
- Topics: codec, lwm2m
- Language: JavaScript
- Homepage:
- Size: 25.4 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lwm2m-codec
A codec for lightweight M2M (LWM2M) data formats.
[](https://nodei.co/npm/lwm2m-codec/)
[](https://travis-ci.org/PeterEB/lwm2m-codec)
[](https://www.npmjs.com/package/lwm2m-codec)
[](https://www.npmjs.com/package/lwm2m-codec)
## Documentation
Please visit the [Wiki](https://github.com/PeterEB/lwm2m-codec/wiki).
## Overview
A codec for lightweight M2M (LWM2M) data formats.
## Installation
> $ npm install lwm2m-codec --save
## Usage
TLV:
```js
var lwCodec = require(lwm2m-codec);
lwCodec.encode('tlv', '/3303/0', { 5700: 31, 5701: 'c' });
lwCodec.encode('tlv', '/temperature/0', { 5700: 31, 5701: 'c' });
lwCodec.encode('tlv', '/temperature/0', { sensorValue: 31, units: 'c' });
// Buffer <0x08, 0x00, 0x0b, 0xe4, 0x16, 0x44, 0x41, 0xf8, 0x00, 0x00, 0xe1, 0x16, 0x45, 0x63>;
lwCodec.decode('tlv', '/3303/0', new Buffer ([0x08, 0x00, 0x0b, 0xe4, 0x16, 0x44, 0x41, 0xf8, 0x00, 0x00, 0xe1, 0x16, 0x45, 0x63]));
// { sensorValue: 31, units: 'c' }
```
JSON:
```js
var lwCodec = require(lwm2m-codec);
lwCodec.encode('json', '/3303/0', { 5700: 31, 5701: 'c' });
lwCodec.encode('json', '/temperature/0', { 5700: 31, 5701: 'c' });
lwCodec.encode('json', '/temperature/0', { sensorValue: 31, units: 'c' });
// Buffer <7b 22 62 6e 22 3a 22 2f 33 33 30 33 2f 30 22 2c 22 65 22 3a 5b 7b 22 6e 22 3a 22 35 37 30 30 22 2c 22 76 22 3a 33 31 7d 2c 7b 22 6e 22 3a 22 35 37 30 31 22 2c 22 73 76 22 3a 22 63 22 7d 5d 7d 0d>;
// String {"bn":"/3303/0","e":[{"n":"5700","v":31},{"n":"5701","sv":"c"}]}
lwCodec.decode('json', '/3303/0', new Buffer ([0x7b ,0x22 ,0x62 ,0x6e ,0x22 ,0x3a ,0x22 ,0x2f ,0x33 ,0x33 ,0x30 ,0x33 ,0x2f ,0x30 ,0x22 ,0x2c ,0x22 ,0x65 ,0x22 ,0x3a ,0x5b ,0x7b ,0x22 ,0x6e ,0x22 ,0x3a ,0x22 ,0x35 ,0x37 ,0x30 ,0x30 ,0x22 ,0x2c ,0x22 ,0x76 ,0x22 ,0x3a ,0x33 ,0x31 ,0x7d ,0x2c ,0x7b ,0x22 ,0x6e ,0x22 ,0x3a ,0x22 ,0x35 ,0x37 ,0x30 ,0x31 ,0x22 ,0x2c ,0x22 ,0x73 ,0x76 ,0x22 ,0x3a ,0x22 ,0x63 ,0x22 ,0x7d ,0x5d ,0x7d
]));
// { sensorValue: 31, units: 'c' }
```
## License
Licensed under [MIT](https://github.com/PeterEB/lwm2m-codec/blob/master/LICENSE).