UNPKG

onem2m_client

Version:

Synctechno's Library for communicating with Mobius on KETI through oneM2M platform

89 lines (81 loc) 2.31 kB
# oneM2M_Client This is created by Synctechno inc for communication with Mobius on KETI through oneM2M Standard <br/> [![NPM](https://nodei.co/npm/onem2m_client.png?downloads=true)](https://nodei.co/npm/onem2m_client/) [![npm](https://img.shields.io/npm/v/onem2m_client.svg?maxAge=2592000)](https://www.npmjs.com/package/onem2m_client) [![npm](https://img.shields.io/npm/l/onem2m_client.svg?maxAge=2592000)](https://www.npmjs.com/package/onem2m_client) <br/> ## Installation > $ npm install onem2m_client --save <br/> ## Usage #### Get Resource ```js var onem2mClient = require('onem2m_client')(); onem2mClient.Http.getResource(ResourceURL, origin) .then(function(result){ resource = result[`m2m:{type}`]; /** * if resource is CB then have to be result['m2m:cb'] * if resource is AE then have to be result['m2m:ae'] * if resource is CNT then have to be result['m2m:cnt'] * if resource is CIN then have to be result['m2m:cin'] * if resource is SUB then have to be result['m2m:sub'] * etc... **/ }) ``` #### Create Resource ```js var onem2mClient = require('onem2m_client')(); var obj = { 'm2m:cin' : { con : /* Content */, lib : /* any lib */ } } onem2mClient.Http.createResource(ResourceURL, obj, origin) .then(function(result){ console.log(result); }); ``` #### Discover Resource ```js var onem2mClient = require('onem2m_client')(); onem2mClient.Http.discoverResource(ResourceURL, origin, type, limit, offset) .then(function(result){ /** * { * "m2m:urli" : { * "parentNode URL", * "First Child URL", * "Second Child URL", * ... * } * } **/ }) ``` ## Mqtt Notification ```js var onem2mClient = require('onem2m_client')(); var targetUri = onem2mClient.Model.getAccessPointInfo(TARGET_RESOURCE_URL); var mqttAddress = `mqtt://${targetUri}`; var mqttClilent = onem2mClient.MQTT.getClilent(mqttAddress, target); mqttClient.on('notification', function(mqttServerAddress, topicTo, topicParams, notiEventType, data) { var eventResource = data.resouce; /* ex) eventResource : { "m2m:cin" : { rn : ..., ri : ..., cr : ..., con : "Content" } } }); ``` ## Question if you have any questions then, send mail to rnd@synctechno.com thank you.