-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
50 lines (38 loc) · 1.04 KB
/
app.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
var myPythonScriptPath = 'scripts/differential.0.py';
// - 0 = Channel 0 minus channel 1
// - 1 = Channel 0 minus channel 3
// - 2 = Channel 1 minus channel 3
// - 3 = Channel 2 minus channel 3
var timeLapse = 0;
var count = 0;
var PythonShell = require('python-shell');
const mqtt = require('mqtt')
const publisher = mqtt.connect('mqtt://localhost:1883')
var time = setInterval(() => {
timeLapse = timeLapse + 1;
}, 1000);
var pyshell;
function action(){
pyshell = new PythonShell(myPythonScriptPath);
pyshell.on('message', function (message) {
var toPublish = message +","+ timeLapse;
publisher.publish('movi/info',toPublish.toString());
console.log(toPublish);
});
}
publisher.subscribe('movi/action');
console.log('waiting...');
publisher.on('message', (topic, message) => {
if(topic === 'movi/action') {
console.log('action: '+ message)
if(message == 'stop'){
console.log("entrou");
pyshell.childProcess.kill();
console.log('waiting...');
timeLapse = 0;
}else{
timeLapse = 0;
action(message);
}
}
})