add better arduino error handling
Server won't just crash when no arduino is available.
This commit is contained in:
parent
3cea3bf323
commit
c3a37ff63f
1 changed files with 9 additions and 4 deletions
|
@ -1,17 +1,22 @@
|
|||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var sucess = true;
|
||||
var SerialPort = require("serialport").SerialPort
|
||||
var serialPort = new SerialPort("/dev/ttyACM0", {
|
||||
serialPort = new SerialPort("/dev/ttyACM0", {
|
||||
baudrate: 9600
|
||||
});
|
||||
}, false).open(function (error) {
|
||||
if ( error ) {
|
||||
sucess = false;
|
||||
}
|
||||
});
|
||||
|
||||
/* GET home page. */
|
||||
/* GET home page. */
|
||||
router.get('/', function(req, res, next) {
|
||||
res.render('index', { title: 'Express' });
|
||||
});
|
||||
|
||||
router.get('/toggleLight', function (req, res) {
|
||||
serialPort.write(new Buffer('~','ascii'));
|
||||
if(sucess) { serialPort.write(new Buffer('~','ascii')); } else {console.log("arduino not connected")}
|
||||
res.send('switch light');
|
||||
});
|
||||
|
||||
|
|
Reference in a new issue