From 90240c7c39a5773e7b5dc4ea3e93c1a17accaa09 Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Tue, 12 Jan 2016 20:22:26 +0100 Subject: [PATCH] add basic node to arduino communication --- arduino/src/sketch.ino | 2 ++ nodejs/routes/index.js | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/arduino/src/sketch.ino b/arduino/src/sketch.ino index 79b4e48..bc4c4d3 100644 --- a/arduino/src/sketch.ino +++ b/arduino/src/sketch.ino @@ -21,9 +21,11 @@ void loop() case 126: if(on) { controlRCOutlets("0FFF0FFF0000"); + Serial.println("Light is off."); on = false; } else { controlRCOutlets("0FFF0FFF000F"); + Serial.println("Light is on."); on = true; } } diff --git a/nodejs/routes/index.js b/nodejs/routes/index.js index ecca96a..7daa819 100644 --- a/nodejs/routes/index.js +++ b/nodejs/routes/index.js @@ -1,9 +1,19 @@ var express = require('express'); var router = express.Router(); +var SerialPort = require("serialport").SerialPort +var serialPort = new SerialPort("/dev/ttyACM0", { + baudrate: 9600 +}); /* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); }); +app.get('/toggleLight', function (req, res) { + res.send('switch light'); + serialport.write(new Buffer(0x7E)); +}); + + module.exports = router;