This repository has been archived on 2024-01-30. You can view files and clone it, but cannot push or open issues or pull requests.
trev/nodejs/routes/index.js

26 lines
617 B
JavaScript
Raw Normal View History

2016-01-12 17:49:13 +01:00
var express = require('express');
var router = express.Router();
var sucess = true;
var SerialPort = require("serialport").SerialPort
serialPort = new SerialPort("/dev/ttyACM0", {
baudrate: 9600
2016-01-13 23:58:55 +01:00
}, false);
serialPort.open(function (error) {
if ( error ) {
sucess = false;
}
});
2016-01-12 17:49:13 +01:00
/* GET home page. */
2016-01-12 17:49:13 +01:00
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');
});
2016-01-12 17:49:13 +01:00
module.exports = router;