-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectShareWoTGW.js
More file actions
126 lines (103 loc) · 4.18 KB
/
Copy pathselectShareWoTGW.js
File metadata and controls
126 lines (103 loc) · 4.18 KB
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
const Servient = require('@node-wot/core').Servient;
const HttpServer = require('@node-wot/binding-http').HttpServer;
const fetch = require('node-fetch');
//const fs = require('fs')
const servient = new Servient();
servient.addServer(new HttpServer());
servient.start().then((WoT) => {
//Produce the TD
WoT.produce({
"@context": "https://www.w3.org/2022/wot/td/v1.1",
title: "Plegma_Building01",
description: "Plegma's building 01",
properties: {
device: {
type: "object",
readOnly: true,
uriVariables: {
deviceID: {type: "integer"},
field: {type: "string"},
startTime: {type: "string"},
endTime: {type: "string"}
},
forms: [{
"href": "http://localhost:8080/plegma_building01/properties/device{?deviceID,field,startTime,endTime}",
"htv:methodName": 'GET'
}]
}
}
})
.then( function (thing) {
//console.log("Produced " + thing.getThingDescription().title);
thing.setPropertyReadHandler("device", async (options) => {
const uriVariables = options.uriVariables;
const deviceID = uriVariables.deviceID;
const field = uriVariables.field;
const startTime = uriVariables.startTime;
const endTime = uriVariables.endTime;
var options = {
'method': 'GET',
'url': 'http://localhost:9090/?deviceID='+deviceID+"&field="+field+"&startTime="+startTime+"&endTime="+endTime
};
url = 'http://localhost:9090/?deviceID='+deviceID+"&field="+field+"&startTime="+startTime+"&endTime="+endTime;
return await send_req();
async function send_req (){
const response = await fetch(url,options);
const data = await response.json();
//console.log(data);
return data;
}
})
thing.expose().then(() => {
console.info(thing.getThingDescription().title + " ready");
//write the TD to a file
//let data = JSON.stringify(thing.getThingDescription(), null, 2);
//fs.writeFileSync('plegmaTD.json', data);
});
})
WoT.produce({
"@context": "https://www.w3.org/2022/wot/td/v1.1",
title: "DomX",
description: "DomX's IoT devices",
properties: {
device: {
type: "object",
readOnly: true,
uriVariables: {
deviceID: {type: "string"},
field: {type: "string"},
startTime: {type: "string"},
endTime: {type: "string"}
},
forms: [{
"href": "http://localhost:8080/domx/properties/device{?deviceID,field,startTime,endTime}",
"htv:methodName": 'GET'
}]
}
}
})
.then( function (thing) {
thing.setPropertyReadHandler("device", async (options) => {
const uriVariables = options.uriVariables;
const deviceID = uriVariables.deviceID;
const field = uriVariables.field;
const startTime = uriVariables.startTime;
const endTime = uriVariables.endTime;
var options = {
'method': 'GET',
'url': 'http://localhost:9099/?deviceID='+deviceID+"&field="+field+"&startTime="+startTime+"&endTime="+endTime
};
url = 'http://localhost:9099/?deviceID='+deviceID+"&field="+field+"&startTime="+startTime+"&endTime="+endTime;
return await send_req();
async function send_req (){
const response = await fetch(url,options);
const data = await response.json();
//console.log(data);
return data;
}
})
thing.expose().then(() => {
console.info(thing.getThingDescription().title + " ready");
});
})
});