From ff135aa3e0d796c0d8b5d74404dc9d39dfec933a Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Thu, 18 Feb 2016 17:42:34 +0100 Subject: [PATCH] add backend functionality --- nodejs/routes/index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nodejs/routes/index.js b/nodejs/routes/index.js index 42fc622..93afd2e 100644 --- a/nodejs/routes/index.js +++ b/nodejs/routes/index.js @@ -13,17 +13,21 @@ router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); }); -router.get('/getRCs', function (req, res) { +router.get('/getRCs', function (req, res, next) { rc_db.findAll(function (error, results, fields) { - if(error) console.log(error); - //rc.send(results[0].on_value); + 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')); + 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');