You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
830 B
39 lines
830 B
const express = require('express'); |
|
const app = express(); |
|
const SerialPort = require('serialport'); |
|
|
|
const server = app.listen(3000, function () { |
|
console.log('Example app listening on port 3000!'); |
|
}) |
|
|
|
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 => { |
|
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')) |
|
|
|
io.on('connection', socket => { |
|
socket.on('update', data => { |
|
update(data); |
|
}); |
|
}); |
|
|
|
|