Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var SerialPort = require("serialport").SerialPort;
- var serialPort = new SerialPort('.COM4', {baudrate: 9600}, true);
- var http = require('http');
- var fs = require('fs');
- // Chargement du fichier index.html affiché au client
- var server = http.createServer(function(req, res) {
- fs.readFile('./index.html', 'utf-8', function(error, content) {
- res.writeHead(200, {"Content-Type": "text/html"});
- res.end(content);
- });
- });
- serialPort.on ('open', function () {
- serialPort.write(0x05);
- serialPort.on ('data', function( data ) {
- mess = "P = " + data.toString()+" W";
- });
- });
- // Chargement de socket.io
- var io = require('socket.io').listen(server);
- // Quand un client se connecte, on le note dans la console
- io.sockets.on('connection', function (socket) {
- socket.emit('message',mess);
- });
- server.listen(8080);
Advertisement
Add Comment
Please, Sign In to add comment