-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotion_app.js
41 lines (38 loc) · 1.4 KB
/
motion_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
module.exports = function(RED) {
function MotionNode(config) {
var motion_api = require('./motion_api.js');
var motion_data = require('./motion_data.js');
RED.nodes.createNode(this,config);
// config before being triggered by input
motion_api.get_motion_config(function(data) {
if (data === 'Config does not exist') {
console.log("No config.");
}
if(data === null) {
console.log("Config read failed");
}
motion_api.configure_motion(function(configdata) {
console.log('config callback data: ', configdata);
});
});
var node = this;
node.on('input', function(msg) {
motion_data.get_motion_data(function(motiondata) {
console.log("=======================Motion Data:");
console.log(motiondata);
// msg.payload = JSON.stringify(motiondata);
msg.payload = motiondata;
node.send(msg);
});
// for websocket:
// gps_data.web_socket_gps_data(function(gpsdata) {
// console.log(gpsdata);
// msg.payload = JSON.stringify(gpsdata);
// node.send(msg);
// });
// });
// });
});
}
RED.nodes.registerType("Motion IOx connector",MotionNode);
}