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
web: node app.js |
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
sudo npm install foreman -g | |
npm install foreman -g |
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
/** | |
* Server Code | |
*/ | |
var server = http.createServer(app).listen(app.get('port'), function(){ | |
console.log("Express server listening on port " + app.get('port')); | |
}); | |
var io = require('socket.io').listen(server); |
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
io.sockets.on('connection', function(socket){ | |
console.log("Socket connected"); | |
socket.emit('connected', 123); |
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
/* | |
* GET home page. | |
*/ | |
var fs = require('fs') | |
exports.index = function(req, res){ | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
var contents = fs.readFileSync("./public/index.html", "UTF-8"); | |
res.end(contents); | |
// res.render('index'); |
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
socket.on('sendSerial', function(data) { | |
console.log("Client sent us: " + data + "to send to serial"); | |
sp.write(mbBuffer, function (err, bytesWritten) { | |
console.log('bytes written:', bytesWritten); | |
}); |
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
sp.on('data', function (data) { | |
console.log(data); | |
data = data.toString(); | |
socket.emit('receiveSerial', data); | |
}); |
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
/** | |
* Serial Port Setup. | |
*/ | |
var portName = '/dev/ttyAMA0'; //This is the standard Raspberry Pi Serial port | |
var readData = ''; //Array to hold the values read in from the port | |
var sp = new serialport(portName, { | |
baudRate: 9600, |
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
serialport = require("serialport").SerialPort; |
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
io.sockets.on('connection', function(socket){ | |
console.log("Socket connected"); | |
socket.emit('connected', 123);</pre> |
OlderNewer