I m trying to Send serial data to Arduino using Node.js and Socket.io and my code.
and the html page have only one button. its work node and html side .but this is not send serial data.
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var port = process.env.PORT || 3000;
server.listen(port, function () {
// console.log('Server listening at port %d', port);
});
// Routing
app.use(express.static(__dirname + '/public'));
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/ttyACM3", {
baudrate:9600
}, false); // this is the openImmediately flag [default is true]
io.on('connection', function (socket) {
socket.on('my other event', function (data) {
console.log(data);
serialPort.open(function () {
console.log('open');
serialPort.on('data', function (data) {
console.log('data received: ' + data);
});
serialPort.write(data, function (err, results) {
console.log('err ' + err);
console.log('results ' + results);
});
});
});
});
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});