Skip to content

Commit

Permalink
broker policy update
Browse files Browse the repository at this point in the history
  • Loading branch information
ThingPlug committed Nov 22, 2016
1 parent f2628c8 commit a194479
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 101 deletions.
12 changes: 1 addition & 11 deletions README.md
Expand Up @@ -124,8 +124,6 @@ module.exports = {

containerName:'LoRa', // starter kit에서 생성하고 사용할 container 이름 (임의지정)
DevReset : 'DevReset', // starter kit에서 생성하고 사용할 제어 명령 DevReset
RepPerChange : 'RepPerChange', // starter kit에서 생성하고 사용할 제어 명령 RepPerChange
RepImmediate : 'RepImmediate', // starter kit에서 생성하고 사용할 제어 명령 RepImmediate
extDevMgmt : 'extDevMgmt', // starter kit에서 생성하고 사용할 제어 명령 extDevMgmt

UPDATE_CONTENT_INTERVAL : 1000, //contentInstance 생성주기
Expand Down Expand Up @@ -296,9 +294,7 @@ module.exports = {
| 1. Content Instance 조회 | 가장 최근의 content Instance를 조회합니다. | HTTP GET |
| 2. mgmtCmd 요청 | Device로 보낼 제어 명령을 ThingPlug에게 보냅니다. | HTTP POST |
| 2-1. DevReset | LoRa 디바이스 리셋을 위한 mgmtCmd | HTTP PUT |
| 2-2. RepPerChange | LoRa 디바이스의 Uplink(주기 보고) 주기 변경을 위한 mgmtCmd | HTTP PUT |
| 2-3. RepImmediate | LoRa 디바이스의 Uplink(주기 보고) 즉시 보고를 위한 mgmtCmd | HTTP PUT |
| 2-4. extDevMgmt | 사용자 지정 mgmtCmd (설정 방법은 API 문서 참조) | HTTP PUT |
| 2-2. extDevMgmt | 사용자 지정 mgmtCmd (설정 방법은 API 문서 참조) | HTTP PUT |
| 3. mgmtCmd execInstance 조회 | Device로 보낸 제어 명령의 상태를 조회 합니다. | HTTP GET |
| 4. Sensor Display | Sensor값(현재 온도, 습도, 조도) 그래프형태로 표시 | d3 API |
| 5. Google 지도 API | LoRa Device 위치 표시 | Google API |
Expand Down Expand Up @@ -359,12 +355,6 @@ client.on('message', function(topic, message){
if(cmt=='RepImmediate'){//즉시보고
...
}
else if(cmt=='RepPerChange'){//주기변경
...
}
else if(cmt=='DevReset'){//디바이스 초기화
...
}
else if(cmt=='extDevMgmt'){//사용자 지정 명령어
...
}
Expand Down
11 changes: 6 additions & 5 deletions config_1.js_sample
Expand Up @@ -20,23 +20,24 @@ module.exports = {
AppEUI : 'starterkittest', // Application EUI
DevEUI : 'DevEUI', // Device EUI
version : 'v1_0', // Application의 version
TPhost : 'thingplugtest.sktiot.com', // ThingPlug의 HOST Addresss
TPhost : 'onem2m.sktiot.com', // ThingPlug의 HOST Addresss
TPport : '9000', // ThingPlug의 HTTP PORT 번호

responseAddress : 'http://0.0.0.0', // HTTP버전에서 디바이스 제어를 위한 디바이스의 물리적 주소 mga
responseAddress : 'http://0.0.0.0:0000', // HTTP버전에서 디바이스 제어를 위한 디바이스의 물리적 주소 mga
responsePORT : '0000', // HTTP버전에서 디바이스제어를 위한 디바이스의 물리적 주소의 로컬 포트

userID : 'userID', // MQTT버전에서 Broker 접속을 위한 ID, 포털 ID 사용
mqttClientId : 'Please Make Ramdom Value_1', // MQTT버전에서 Broker 접속을 위한 client ID
mqttClientId : function(){ // MQTT버전에서 Broker 접속을 위한 client ID(ex : ThingPlugID_0001)
var POST_FIX = '0001';
return this.userID+'_'+POST_FIX;
},

nodeID : 'Please Type Your Own LTID', // Device 구분을 위한 LTID, 디바이스 고유 ID 사용
passCode : '000101', // ThingPlug에 Device등록 시 사용할 Device의 비밀번호
uKey : 'USER KEY FROM PORTAL', // Thingplug로그인 후, `마이페이지`에 있는 사용자 인증키

containerName:'LoRa', // starter kit에서 생성하고 사용할 container 이름 (임의지정)
DevReset : 'DevReset', // starter kit에서 생성하고 사용할 제어 명령 DevReset
RepPerChange : 'RepPerChange', // starter kit에서 생성하고 사용할 제어 명령 RepPerChange
RepImmediate : 'RepImmediate', // starter kit에서 생성하고 사용할 제어 명령 RepImmediate
extDevMgmt : 'extDevMgmt', // starter kit에서 생성하고 사용할 제어 명령 extDevMgmt

UPDATE_CONTENT_INTERVAL : 1000, //contentInstance 생성주기
Expand Down
11 changes: 6 additions & 5 deletions config_2.js_sample
Expand Up @@ -20,23 +20,24 @@ module.exports = {
AppEUI : 'starterkittest', // Application EUI
DevEUI : 'DevEUI', // Device EUI
version : 'v1_0', // Application의 version
TPhost : 'thingplugtest.sktiot.com', // ThingPlug의 HOST Addresss
TPhost : 'onem2m.sktiot.com', // ThingPlug의 HOST Addresss
TPport : '9000', // ThingPlug의 HTTP PORT 번호

responseAddress : 'http://0.0.0.0', // HTTP버전에서 디바이스 제어를 위한 디바이스의 물리적 주소 mga
responseAddress : 'http://0.0.0.0:0000', // HTTP버전에서 디바이스 제어를 위한 디바이스의 물리적 주소 mga
responsePORT : '0000', // HTTP버전에서 디바이스제어를 위한 디바이스의 물리적 주소의 로컬 포트

userID : 'userID', // MQTT버전에서 Broker 접속을 위한 ID, 포털 ID 사용
mqttClientId : 'Please Make Ramdom Value_2', // MQTT버전에서 Broker 접속을 위한 client ID
mqttClientId : function(){ // MQTT버전에서 Broker 접속을 위한 client ID(ex : ThingPlugID_0002)
var Seq_NUM = '0002';
return this.userID+'_'+Seq_NUM;
},

nodeID : 'Please Type Your Own LTID', // Device 구분을 위한 LTID, 디바이스 고유 ID 사용
passCode : '000101', // ThingPlug에 Device등록 시 사용할 Device의 비밀번호
uKey : 'USER KEY FROM PORTAL', // Thingplug로그인 후, `마이페이지`에 있는 사용자 인증키

containerName:'LoRa', // starter kit에서 생성하고 사용할 container 이름 (임의지정)
DevReset : 'DevReset', // starter kit에서 생성하고 사용할 제어 명령 DevReset
RepPerChange : 'RepPerChange', // starter kit에서 생성하고 사용할 제어 명령 RepPerChange
RepImmediate : 'RepImmediate', // starter kit에서 생성하고 사용할 제어 명령 RepImmediate
extDevMgmt : 'extDevMgmt', // starter kit에서 생성하고 사용할 제어 명령 extDevMgmt

UPDATE_CONTENT_INTERVAL : 1000, //contentInstance 생성주기
Expand Down
29 changes: 14 additions & 15 deletions device_mqtt_1.js
Expand Up @@ -46,7 +46,6 @@ function randomInt (low, high) {
}
//=============================================================================================================================//


var self = this;

var isRunning = 1;
Expand All @@ -55,14 +54,14 @@ var reqHeader = "<m2m:req xmlns:m2m=\"http://www.onem2m.org/xml/protocols\" xmln
var client = mqtt.connect('mqtt://'+config.TPhost, {
username:config.userID, //user ID to connect with MQTT broker
password:config.uKey, //password to connect with MQTT broker(uKey of portal)
clientId:config.mqttClientId, //Client ID to connect with MQTT broker
clientId:config.mqttClientId(), //Client ID to connect with MQTT broker
clean:true //clean session
});
client.on('connect', function () {
console.log('### mqtt connected ###');
//---------------------------------------------------Subscribe Declaration-----------------------------------------------------//
client.subscribe("/oneM2M/req/+/"+ config.nodeID);
client.subscribe("/oneM2M/resp/"+ config.nodeID +"/+");
client.subscribe("/oneM2M/req/+/"+ config.mqttClientId());
client.subscribe("/oneM2M/resp/"+ config.mqttClientId() +"/+");
//=============================================================================================================================//

nodeCreationReq (); //1. Request node Creation
Expand All @@ -73,8 +72,8 @@ client.on('close', function(){
});

client.on('error', function(error){
console.log(error);
self.emit('error', error);
console.log(colors.red(error));
self.emit('error', error);
});

client.on('message', function(topic, message){
Expand Down Expand Up @@ -141,7 +140,7 @@ client.on('message', function(topic, message){
// cnf : uploaded content's type info (cnf = contentInfo)
// con : uploaded contents (con == content)
var createContentInstance = reqHeader+op+to+fr+ty+ri+cty+dKey+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createContentInstance, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createContentInstance, {qos : 1}, function(){

});
}
Expand Down Expand Up @@ -185,7 +184,7 @@ function nodeCreationReq (){
// ni : LTID
// mga : mgmtCmd Address to get mgmtCmd
var createNode = reqHeader+op+to+fr+ty+ri+cty+nm+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createNode, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createNode, {qos : 1}, function(){
console.log(colors.yellow('1. Request node Creation'));
isRunning = "node";

Expand Down Expand Up @@ -215,15 +214,15 @@ function remoteCSECreationReq (){
var ri = "<ri>"+config.nodeID+'_'+randomInt(100000, 999999)+"</ri>"; // ri header shall be mapped to the Request Identifier parameter
var passCode = "<passCode>"+config.passCode+"</passCode>"; // password to use for reqistering device at portal
var cty = "<cty>application/vnd.onem2m-prsp+xml</cty>"; // containing Req message-body shall include the Content-type header set to one (ty == 14 is node)
var nm = "<nm>"+config.nodeID+"</nm>"; // nm header shall be mapped to the Name parameter
var nm = "<nm>"+config.nodeID+"</nm>"; // nm header shall be mapped to the Name parameter // nm header shall be mapped to the Name parameter
var reqBody = "<pc><csr><cst>3</cst><csi>"+config.nodeID+"</csi><rr>false</rr><nl>"+config.nodeRI+"</nl></csr></pc></m2m:req>";
// cst : CSE Type (IN-CSE = 1, MN-CSE = 2, ASN-CSE = 3) (cseType == cst)
// csi : CSE-ID
// rr : Request Reachability, set true when poa has static IP
// nl : <node> Resource ID (nl == nodelink)

var createRemoteCSE = reqHeader+op+to+fr+ty+ri+passCode+cty+nm+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID + "/"+config.AppEUI, createRemoteCSE, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() + "/"+config.AppEUI, createRemoteCSE, {qos : 1}, function(){
console.log(' ');
console.log(colors.yellow('2. Request remoteCSE Creation '));
isRunning = "remoteCSE";
Expand Down Expand Up @@ -257,7 +256,7 @@ function containerCreationReq (){
var reqBody = "<pc><cnt><lbl>con</lbl></cnt></pc></m2m:req>";

var createContainer = reqHeader+op+to+fr+ty+ri+nm+dKey+cty+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createContainer, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createContainer, {qos : 1}, function(){
console.log(' ');
console.log(colors.yellow('3. Request container Creation'));
isRunning = "container";
Expand Down Expand Up @@ -290,7 +289,7 @@ function DevResetCreationReq (){
// exe : Trigger Attribute (true/false) (exe == execEnable)
// ext : execute Target means node's Resource ID (ext == exeTarget)
var createDevReset = reqHeader+op+to+fr+ty+ri+nm+dKey+cty+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createDevReset, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createDevReset, {qos : 1}, function(){
console.log(' ');
console.log(colors.yellow('4. Request DevReset(mgmtCmd) Creation'));
isRunning = "DevReset";
Expand Down Expand Up @@ -323,7 +322,7 @@ function extDevMgmtCreationReq (){
// exe : Trigger Attribute (true/false) (exe == execEnable)
// ext : execute Target means node's Resource ID (ext == exeTarget)
var createRepPerChange = reqHeader+op+to+fr+ty+ri+nm+dKey+cty+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createRepPerChange, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createRepPerChange, {qos : 1}, function(){
console.log(' ');
console.log(colors.yellow('4. Request extDevMgmt(mgmtCmd) Creation'));
isRunning = "extDevMgmt";
Expand Down Expand Up @@ -370,9 +369,9 @@ function updateExecInstanceReq (xmlObj){
var reqBody = "<pc><exin><exs>3</exs><exr>0</exr></exin></pc></m2m:req>";
// exs : execStatus after update mgmtCmd
var updateExecInstance = reqHeader+op+to+fr+ri+dKey+cty+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, updateExecInstance, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, updateExecInstance, {qos : 1}, function(){
console.log(colors.red('#####################################'));
isRunning = "updateExecInstance";
});
}
//=============================================================================================================================//
//=============================================================================================================================//
27 changes: 13 additions & 14 deletions device_mqtt_2.js
Expand Up @@ -46,7 +46,6 @@ function randomInt (low, high) {
}
//=============================================================================================================================//


var self = this;

var isRunning = 1;
Expand All @@ -55,14 +54,14 @@ var reqHeader = "<m2m:req xmlns:m2m=\"http://www.onem2m.org/xml/protocols\" xmln
var client = mqtt.connect('mqtt://'+config.TPhost, {
username:config.userID, //user ID to connect with MQTT broker
password:config.uKey, //password to connect with MQTT broker(uKey of portal)
clientId:config.mqttClientId, //Client ID to connect with MQTT broker
clientId:config.mqttClientId(), //Client ID to connect with MQTT broker
clean:true //clean session
});
client.on('connect', function () {
console.log('### mqtt connected ###');
//---------------------------------------------------Subscribe Declaration-----------------------------------------------------//
client.subscribe("/oneM2M/req/+/"+ config.nodeID);
client.subscribe("/oneM2M/resp/"+ config.nodeID +"/+");
client.subscribe("/oneM2M/req/+/"+ config.mqttClientId());
client.subscribe("/oneM2M/resp/"+ config.mqttClientId() +"/+");
//=============================================================================================================================//

nodeCreationReq (); //1. Request node Creation
Expand All @@ -73,8 +72,8 @@ client.on('close', function(){
});

client.on('error', function(error){
console.log(error);
self.emit('error', error);
console.log(colors.red(error));
self.emit('error', error);
});

client.on('message', function(topic, message){
Expand Down Expand Up @@ -141,7 +140,7 @@ client.on('message', function(topic, message){
// cnf : uploaded content's type info (cnf = contentInfo)
// con : uploaded contents (con == content)
var createContentInstance = reqHeader+op+to+fr+ty+ri+cty+dKey+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createContentInstance, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createContentInstance, {qos : 1}, function(){

});
}
Expand Down Expand Up @@ -185,7 +184,7 @@ function nodeCreationReq (){
// ni : LTID
// mga : mgmtCmd Address to get mgmtCmd
var createNode = reqHeader+op+to+fr+ty+ri+cty+nm+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createNode, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createNode, {qos : 1}, function(){
console.log(colors.yellow('1. Request node Creation'));
isRunning = "node";

Expand Down Expand Up @@ -223,7 +222,7 @@ function remoteCSECreationReq (){
// nl : <node> Resource ID (nl == nodelink)

var createRemoteCSE = reqHeader+op+to+fr+ty+ri+passCode+cty+nm+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID + "/"+config.AppEUI, createRemoteCSE, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() + "/"+config.AppEUI, createRemoteCSE, {qos : 1}, function(){
console.log(' ');
console.log(colors.yellow('2. Request remoteCSE Creation '));
isRunning = "remoteCSE";
Expand Down Expand Up @@ -257,7 +256,7 @@ function containerCreationReq (){
var reqBody = "<pc><cnt><lbl>con</lbl></cnt></pc></m2m:req>";

var createContainer = reqHeader+op+to+fr+ty+ri+nm+dKey+cty+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createContainer, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createContainer, {qos : 1}, function(){
console.log(' ');
console.log(colors.yellow('3. Request container Creation'));
isRunning = "container";
Expand Down Expand Up @@ -290,7 +289,7 @@ function DevResetCreationReq (){
// exe : Trigger Attribute (true/false) (exe == execEnable)
// ext : execute Target means node's Resource ID (ext == exeTarget)
var createDevReset = reqHeader+op+to+fr+ty+ri+nm+dKey+cty+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createDevReset, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createDevReset, {qos : 1}, function(){
console.log(' ');
console.log(colors.yellow('4. Request DevReset(mgmtCmd) Creation'));
isRunning = "DevReset";
Expand Down Expand Up @@ -323,7 +322,7 @@ function extDevMgmtCreationReq (){
// exe : Trigger Attribute (true/false) (exe == execEnable)
// ext : execute Target means node's Resource ID (ext == exeTarget)
var createRepPerChange = reqHeader+op+to+fr+ty+ri+nm+dKey+cty+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, createRepPerChange, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, createRepPerChange, {qos : 1}, function(){
console.log(' ');
console.log(colors.yellow('4. Request extDevMgmt(mgmtCmd) Creation'));
isRunning = "extDevMgmt";
Expand Down Expand Up @@ -370,9 +369,9 @@ function updateExecInstanceReq (xmlObj){
var reqBody = "<pc><exin><exs>3</exs><exr>0</exr></exin></pc></m2m:req>";
// exs : execStatus after update mgmtCmd
var updateExecInstance = reqHeader+op+to+fr+ri+dKey+cty+reqBody;
client.publish("/oneM2M/req/"+ config.nodeID +"/"+config.AppEUI, updateExecInstance, {qos : 1}, function(){
client.publish("/oneM2M/req/"+ config.mqttClientId() +"/"+config.AppEUI, updateExecInstance, {qos : 1}, function(){
console.log(colors.red('#####################################'));
isRunning = "updateExecInstance";
});
}
//=============================================================================================================================//
//=============================================================================================================================//

0 comments on commit a194479

Please sign in to comment.