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

35 lines
976 B
JavaScript
Raw Normal View History

2016-01-12 17:49:13 +01:00
var express = require('express');
var router = express.Router();
2016-02-17 14:14:04 +01:00
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);
2016-01-14 21:43:45 +01:00
arduino.setup();
/* GET home page. */
2016-01-12 17:49:13 +01:00
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
2016-02-18 17:42:34 +01:00
router.get('/getRCs', function (req, res, next) {
2016-02-17 23:18:54 +01:00
rc_db.findAll(function (error, results, fields) {
2016-02-18 17:42:34 +01:00
if(error){ console.log(error); return(next); }
2016-02-17 23:18:54 +01:00
res.json(results);
2016-02-17 14:14:04 +01:00
});
2016-02-17 23:18:54 +01:00
});
2016-02-18 17:42:34 +01:00
router.post('/register', function (req, res, next){
rc.send(req.body.code);
res.send(req.body);
});
2016-01-21 22:01:57 +01:00
router.get('/irTest', function (req, res) {
2016-02-18 17:42:34 +01:00
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'));
2016-01-21 22:01:57 +01:00
res.send('switch light');
});
2016-01-12 17:49:13 +01:00
module.exports = router;