23 lines
643 B
JavaScript
23 lines
643 B
JavaScript
var express = require('express');
|
|
var router = express.Router();
|
|
var sucess = true;
|
|
var SerialPort = require("serialport").SerialPort
|
|
serialPort = new SerialPort("/dev/ttyACM0", {
|
|
baudrate: 9600
|
|
}, false).open(function (error) {
|
|
if ( error ) {
|
|
sucess = false;
|
|
}
|
|
});
|
|
|
|
/* GET home page. */
|
|
router.get('/', function(req, res, next) {
|
|
res.render('index', { title: 'Express' });
|
|
});
|
|
|
|
router.get('/toggleLight', function (req, res) {
|
|
if(sucess) { serialPort.write(new Buffer('~','ascii')); } else {console.log("arduino not connected")}
|
|
res.send('switch light');
|
|
});
|
|
|
|
module.exports = router;
|