-
Notifications
You must be signed in to change notification settings - Fork 8
/
node_helper.js
42 lines (36 loc) · 1.14 KB
/
node_helper.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
/* Magic Mirror
*
* Module: MMM-PilotWX
*
* By Mykle1
*
*/
const NodeHelper = require('node_helper');
const request = require('request');
const parser = require('xml2js').parseString;
module.exports = NodeHelper.create({
start: function() {
console.log("Starting module: " + this.name);
},
getWISP: function(url) {
request({
url: url,
method: 'GET'
}, (error, response, body) => {
if (!error && response.statusCode === 200) {
parser(body, (err, result)=> {
var result = JSON.parse(JSON.stringify(result.response.data));
// console.log(result); // for checking
// console.log(response.statusCode); // for checking
this.sendSocketNotification("WISP_RESULT", result);
});
}
});
},
//Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_WISP') {
this.getWISP(payload);
}
}
});