-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_server.js
More file actions
40 lines (34 loc) · 799 Bytes
/
node_server.js
File metadata and controls
40 lines (34 loc) · 799 Bytes
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
var net = require('net');
var serial = require('serialport');
var tempSerial, err;
var red = true;
try {
tempSerial = new serial.SerialPort('/dev/tty.usbmodemfa141', {
baudrate: 115200,
parser: serial.parsers.readline("\n")
});
} catch (e) {
err = e;
}
if (!err) {
found = tempSerial;
console.log('info', 'Connected to arduino!');
tempSerial.write('00000000');
tempSerial.on("data", function (data) {
console.log("got from arduino: "+data);
});
}
else {
console.log(err);
}
var tropoServer = net.createServer();
tropoServer.on('connection', function(client) {
client.on('data', function(data) {
if(data > 0 || data == 'end'){
if(data == 'end') data = 0;
console.log("got from tropo: "+data);
tempSerial.write('!' + data + '.');
}
});
});
tropoServer.listen(7777);