-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
103 lines (88 loc) · 2.43 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var express = require('express');
var app = express();
var readline = require('readline');
var mysql = require('mysql')
var spawn = require('child_process').spawn;
var serial = spawn('python',['../read.py']);
serial.stdin.setDefaultEncoding('utf-8');
readline.createInterface({
input: serial.stdout,
terminal: false
}).on('line',function(line){
console.log("Line: "+line);
processRequest(line);
serial.stdin.write("\n");
});
var socket = require('socket.io');
var tab;
app.use(express.static('css'));
app.use(express.static('assets'));
app.use(express.static('js'));
app.set("view engine","ejs");
var con = mysql.createConnection({
host: "localhost",
user: "aravindh",
password: "aravindh",
database: "kalpana"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected to MYSQL!");
});
app.get('/',function(req,res){
res.redirect('/registration')
});
app.get('/registration',function(req,res){
tab = "check_in";
console.log("Registeration" + tab);
res.render("registration");
});
app.get('/dinner',function(req,res){
tab = "dinner";
res.render("dinner");
});
app.get('/latenightsnacks',function(req,res){
tab = "latesnack";
res.render("latenightsnacks");
});
app.get('/breakfast',function(req,res){
tab = "breakfast";
res.render("breakfast");
});
app.get('/lunch',function(req,res){
tab = "lunch";
res.render("lunch");
});
// app.get('/food',function(req,res){
// res.render("food");
// });
var server = app.listen(5000,function(){
console.log("Server Has Started");
});
var io = socket(server);
io.on('connection',function(socket){
console.log("Client Connected: "+socket);
});
function processRequest(barcode){
console.log("Processing: "+barcode);
io.sockets.emit('processing',"Please Wait...");
var query = "SELECT code,Name FROM member WHERE code='"+barcode+"'";
con.query(query,function(err,result){
if(err){
console.log(err);
}
else{
// console.log(result);
io.sockets.emit('userdata',result[0]);
var update = "UPDATE member set "+tab+"= 1 WHERE code='"+barcode+"'";
con.query(update,function(err,result){
if(err){
console.log(err);
}
else{
io.sockets.emit('done',{text: "Success",image: "register_success"});
}
});
}
});
}