-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadn3.js
160 lines (143 loc) · 4.01 KB
/
adn3.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Copyright (c) 2017, Sejong University. All rights reserved
oneM2M ADN Profile 3
This document contains the implementation code of oneM2M ADN profile 3. 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 3 =======================////////////////////
//=========== Fundamental features ==========//
// ### Create a <ContentInstance> with mandatory attributes ### AE/DMR/00002/00001
exports.createContentInstance = function(origin,url,con_value){
console.log("Creating <ContentInstance> with mandatory attributes AE/DMR/00002/00001");
var headers={
'X-M2M-Origin': origin,
'X-M2M-RI' :12345,
'Content-Type': 'application/json;ty=4'
};
request({
headers: headers,
url:url+cseName+aeNameForUpdate+cnt_test,
method:'POST',
body:
JSON.stringify({
"m2m:cin": {
"con":con_value
}
})
},function(error, response, body)
{
if(!error)
{
var obj = JSON.parse(body);
console.log("Response=",obj)
}
else
{
console.log("error is: "+ error);
}
});
}
//=========== Extendable features ==========//
// -------------- AE -------------//
//### 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);
}
});
}
// -------------- Container -------------//
// ### Create a <Container> with no attribute set ### AE/DMR/00001/00001
exports.createContainer = function(origin,url){
console.log("Creating <Container> with no attribute set AE/DMR/00001/00001");
var headers={
'X-M2M-Origin': origin,
'X-M2M-RI' :12345,
'Content-Type': 'application/json;ty=3'
};
request({
headers: headers,
url:url+cseName+aeNameForUpdate,
method:'POST',
body:
JSON.stringify({
"m2m:cnt":{
}
})
},function(error, response, body)
{
if(!error)
{
var obj = JSON.parse(body);
console.log("Response=",obj)
}
else
{
console.log("error is: "+ error);
}
});
}
// -------------- ContentInstance -------------//
// ### Create a <ContentInstance> with mandatory attributes ### AE/DMR/00002/00001
exports.createContentInstance = function(origin,url,con_value){
console.log("Creating <ContentInstance> with mandatory attributes AE/DMR/00002/00001");
var headers={
'X-M2M-Origin': origin,
'X-M2M-RI' :12345,
'Content-Type': 'application/json;ty=4'
};
request({
headers: headers,
url:url+cseName+aeNameForUpdate+cnt_test,
method:'POST',
body:
JSON.stringify({
"m2m:cin": {
"con":con_value
}
})
},function(error, response, body)
{
if(!error)
{
var obj = JSON.parse(body);
console.log("Response=",obj)
}
else
{
console.log("error is: "+ error);
}
});
}