Skip to content

Instantly share code, notes, and snippets.

@ihatecsv
Created August 28, 2015 18:32
Show Gist options
  • Save ihatecsv/4708bffe1d8d2f7f9473 to your computer and use it in GitHub Desktop.
Save ihatecsv/4708bffe1d8d2f7f9473 to your computer and use it in GitHub Desktop.
//This app requires the express and serialport libraries for node. You can get them on NPM with:
//npm install express
//npm install serialport
var app = require('express')();
var http = require('http').Server(app);
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort("COM3", { //change port to your Arduinos port
baudrate: 9600,
databits: 8, // this is the default for Arduino serial communication
parity: 'none', // this is the default for Arduino serial communication
stopbits: 1 // this is the default for Arduino serial communication
});
serialPort.on('data', function(data) {
console.log('data received: ' + data);
});
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.get('/sendmsg', function(req, res){
var message = req.query.m.replace(/~/g, " ");
console.log("Recieved song: " + message);
res.send("Recieved song: " + message);
serialPort.write(message, function(err, results) {
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment