var express = require('express');
var app = express();
var http = require('http').createServer(app);
var SerialPort = require('serialport');
var port = new SerialPort('COM6',{baudRate: 115200});
var socketio = require('socket.io');
var Readline = require('@serialport/parser-readline');
var parser = new Readline();
var arduino_string;
var server_ID = "a";
var server_PSW = "a";
var client_id_psw;
var io = socketio.listen(http);
io.on('connection', function(socket){
console.log('connection');
socket.on('client_ID+PSW',function(data){
client_id_psw = data;
if(client_id_psw == (server_ID+server_PSW))
{
//socket.emit('server_login',"로그인 성공");
port.pipe(parser);
parser.on('data',function(data2){
arduino_string = data2;
socket.emit('server_login', data2);
if(data2 < 20){
socket.emit('server_login', "\n Danger!! ");
}
});
}
else{
socket.emit('server_login',"로그인 실패");
}
});
});
app.get('/', function(req,res){
res.sendfile(__dirname + '/test1.html');
});
http.listen(4000, function(){
console.log('Example app listening on port 4000');
});