Created
August 28, 2015 18:32
-
-
Save ihatecsv/4708bffe1d8d2f7f9473 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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