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-02-22 13:22:18 +01:00

34 lines
976 B
JavaScript

var express = require('express');
var router = express.Router();
var arcom = new require('../ar-com');
var RCDB = new require('../models/rc_db');
var rc_db = new RCDB();
var arduino = new arcom.Arduino();
var rc = new arcom.RC(arduino);
arduino.setup();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.get('/getRCs', function (req, res, next) {
rc_db.findAll(function (error, results, fields) {
if(error){ console.log(error); return(next); }
res.json(results);
});
});
router.post('/register', function (req, res, next){
rc.send(req.body.code);
res.send(req.body);
});
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'));
res.send('switch light');
});
module.exports = router;