diff --git a/nodejs/routes/index.js b/nodejs/routes/index.js index fc06abe..bc08198 100644 --- a/nodejs/routes/index.js +++ b/nodejs/routes/index.js @@ -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'); });