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
2016-01-28 19:00:17 +01:00

28 lines
955 B
JavaScript

var express = require('express');
var router = express.Router();
var Arduino = new require('../ar-com/arduino');
var arduino = new Arduino();
arduino.setup();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.get('/toggleLight', function (req, res) {
var s = "0FFF0FFF000F";
var str = "";
for(i = 0; i < s.length; i+=2) { str += String.fromCharCode(parseInt(s.substr(i,2), 16)); }
arduino.write(new Buffer('Wl' + str,'ascii'));
res.send('switch light');
});
router.get('/irTest', function (req, res) {
//arduino.write(new Buffer('X0' + String.fromCharCode(4) + String.fromCharCode(12) + String.fromCharCode(0)+String.fromCharCode(0)+String.fromCharCode(2689 / 256) + String.fromCharCode(2689 % 256),'ascii'));
arduino.write(new Buffer('Uo000000'), 'ascii');
arduino.write(new Buffer('Up000000'), 'ascii');
res.send('switch light');
});
module.exports = router;