|
|
@ -1,5 +1,6 @@ |
|
|
|
const express = require('express'); |
|
|
|
const express = require('express'); |
|
|
|
const app = express(); |
|
|
|
const app = express(); |
|
|
|
|
|
|
|
const SerialPort = require('serialport'); |
|
|
|
|
|
|
|
|
|
|
|
const server = app.listen(3000, function () { |
|
|
|
const server = app.listen(3000, function () { |
|
|
|
console.log('Example app listening on port 3000!'); |
|
|
|
console.log('Example app listening on port 3000!'); |
|
|
@ -7,8 +8,25 @@ const server = app.listen(3000, function () { |
|
|
|
|
|
|
|
|
|
|
|
const io = require('socket.io').listen(server); |
|
|
|
const io = require('socket.io').listen(server); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const port = new SerialPort('/dev/rfcomm0'); |
|
|
|
|
|
|
|
port.on('error', function(err) { |
|
|
|
|
|
|
|
console.log('Error: ', err.message); |
|
|
|
|
|
|
|
port.close(); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
port.on('close', function(err) { |
|
|
|
|
|
|
|
setTimeout(function() { |
|
|
|
|
|
|
|
port.open(); |
|
|
|
|
|
|
|
}, 2000); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const update = data => { |
|
|
|
const update = data => { |
|
|
|
console.log('recieved ' + data); |
|
|
|
console.log('recieved ' + data); |
|
|
|
|
|
|
|
port.write(data, function(err) { |
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
|
|
return console.log('Error on write: ', err.message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
console.log('message written'); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
app.use('/', express.static('dist')) |
|
|
|
app.use('/', express.static('dist')) |
|
|
@ -18,3 +36,4 @@ io.on('connection', socket => { |
|
|
|
update(data); |
|
|
|
update(data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|