-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhdm_data.js
53 lines (47 loc) · 1.31 KB
/
hdm_data.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
module.exports = function(cmd, callback){
var oauth = require('./oauth.js');
var https = require('https');
var nbi_label = "nbi";
var nbi_host = process.env[nbi_label+"_IP_ADDRESS"];
var nbi_port = process.env[nbi_label+"_TCP_9999_PORT"];
var product_id = process.env.CAF_SYSTEM_PRODUCT_ID;
var serial_id = process.env.CAF_SYSTEM_SERIAL_ID;
var device_id = product_id+":"+serial_id;
oauth.get_oauth(function(oauth_token) {
console.log('oauth in getdata:');
console.log(oauth_token);
var hdm_data_type = cmd;
if(hdm_data_type) {
var payload = hdm_data_type;
var header = {
"Content-Type": "text/plain",
"Authorization": "Bearer "+oauth_token,
'Content-Length': Buffer.byteLength(payload)
};
var options = {
host: nbi_host,
port: nbi_port,
path: '/api/v1/mw/hdmrpc/showcmd',
method: 'POST',
rejectUnauthorized: false,
headers: header
};
var req = https.request(options, (res) => {
console.log('Get data statusCode:', res.statusCode);
var body = '';
res.on('data', (d) => {
body += d.toString('utf8');
});
res.on('end', () => {
console.log('No more data in postdata-api response.');
callback(JSON.parse(body));
});
});
req.on('error', (e) => {
console.error(e);
});
req.write(payload);
req.end();
}
});
}