-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
51 lines (45 loc) · 1.5 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
43
44
45
46
47
48
49
50
51
var NodeHelper = require('node_helper');
const PythonShell = require('python-shell');
var pythonStarted = false;
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node helper: " + this.name);
},
python_start: function () {
var options = {
mode: 'text',
};
const self = this;
const pyshell = new PythonShell('/modules/MMM-Feuerwehr-Alarm-FME/scripts/alarmsniffer.py', {"mode": "json"});
pyshell.on('message', function (message) {
console.log("Message " + message);
if (message.hasOwnProperty('alarm')){
console.log("[" + self.name + "] Alarm: " + message.alarm);
if(message.alarm == "EIN") {
console.log("jetztAlarmieren(ALARMIERUNG_EIN)");
self.jetztAlarmieren("ALARMIERUNG_EIN", message.zeit);
} else{
console.log("jetztAlarmieren(ALARMIERUNG_AUS)");
self.jetztAlarmieren("ALARMIERUNG_AUS", message.zeit);
}
}
});
pyshell.end(function (err) {
if (err) throw err;
console.log("[" + self.name + "] " + 'finished running...');
});
},
socketNotificationReceived: function(notification, payload) {
var self = this;
console.log(this.name + " node_helper.js socketNotificationReceived: " + notification);
if(notification == "START_SNIFFER") {
if(!pythonStarted) {
pythonStarted = true;
this.python_start();
};
}
},
jetztAlarmieren: function(socketNotificationName, zeit) {
this.sendSocketNotification(socketNotificationName, zeit);
}
});