-
Notifications
You must be signed in to change notification settings - Fork 2
/
devices.js
27 lines (24 loc) · 1.27 KB
/
devices.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
module.exports={
handleDiscovery:function (request, context) {
var payload;
const request1 = require('request');
var header = request.directive.header;
header.name = "Discover.Response";
function log(message, message1, message2) {
console.log(message + message1 + message2);
}
// Make the call to your device cloud for control
const get_device_url = process.env.GET_DEVICE_URL;
var url_get_state = get_device_url;
// Make the call to your device cloud for control and check for success
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
request1(url_get_state, function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body), // Print the HTML for the Google homepage.
payload = JSON.parse(body),
log("DEBUG", "Discovery Response: ", JSON.stringify({ header: header, payload: payload })),
context.succeed({ event: { header: header, payload: payload } });
});
}
};