-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadn2.js
123 lines (116 loc) · 3.26 KB
/
adn2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* Copyright (c) 2017, Sejong University. All rights reserved
oneM2M ADN Profile 2
This document contains the implementation code of oneM2M ADN profile 2. oneM2M is open standard for IoT. The purpose of this ADN pofile is Testing.
Author : Abdullah Aziz
Email : mister.abdullah.aziz@gmail.com
*/
var request = require('request');
var cseName = "/Mobius"; // to concatenate with url in any request
var aeNameForUpdate = "/ae_test";
var cnt_test = "/cnt_test";
var cinLatest = "/latest";
var cinOldest = "/oldest";
var cinName = "/my_ressource";
///////////////////////=================ADN 2 =======================////////////////////
//=========== Fundamental features ==========//
//### Create <AE> with mandatory attributes ### AE/REG/00002/00001
exports.createAE = function (origin,url,api_value,rr_value){
console.log("Creating <AE> with mandatory attributes AE/REG/00002/00001");
var headers={
'X-M2M-Origin': origin,
'X-M2M-RI' :12345,
'Content-Type': 'application/json;ty=2'
};
request({
headers: headers,
url:url+cseName,
method:'POST',
body:
JSON.stringify({
"m2m:ae":{
"api" : api_value,
"rr" : rr_value
}
})
},function(error, response, body)
{
if(!error)
{
var obj = JSON.parse(body);
console.log("Response=",obj)
}
else
{
console.log("error is: "+ error);
}
});
}
// ### Create <AE> with pointOfAccess ### AE/REG/0002/0006
exports.createAEpoa =function (origin,url,api_value,rr_value,poa_value){
console.log("Creating <AE> with pointOfAccess attributes AE/REG/0002/0006");
var headers={
'X-M2M-Origin': origin,
'X-M2M-RI' :12345,
'Content-Type': 'application/json;ty=2'
};
request({
headers: headers,
url:url+cseName,
method:'POST',
body:
JSON.stringify({
"m2m:ae":{
"api" : api_value,
"rr" : rr_value,
"poa" : poa_value
}
})
},function(error, response, body)
{
if(!error)
{
var obj = JSON.parse(body);
console.log("Response=",obj)
}
else
{
console.log("error is: "+ error);
}
});
}
//### Create <Subscription> with mandatory attributes ###
exports.createSubscription = function(origin,url,rn_value,nu_value,nct_value,net_value){
console.log("Creating <Subscription> with mandatory attributes");
var headers={
'X-M2M-Origin': origin,
'X-M2M-RI' :12345,
'Content-Type': 'application/json;ty=23'
};
request({
headers: headers,
url:url+cseName,
method:'POST',
body:
JSON.stringify({
"m2m:sub":{
"rn" : rn_value,
"enc" : {
"net" : net_value
},
"nu" : nu_value,
"nct" : nct_value
}
})
},function(error, response, body)
{
if(!error)
{
var obj = JSON.parse(body);
console.log("Response=",obj)
}
else
{
console.log("error is: "+ error);
}
});
}