diff --git a/app.js b/app.js
index 399555b..8c93f47 100644
--- a/app.js
+++ b/app.js
@@ -2,7 +2,7 @@ var server = require("./server");
var router = require("./route");
var requestHandlers = require("./requestHandlers");
-var debug = false;
+var debug = false; // todo move this to configfile
var handle = {}
handle["/"] = requestHandlers.sendInterface;
@@ -14,5 +14,11 @@ handle["/js/jquery-ui.js"] = requestHandlers.sendJqueryUI;
handle["/css/bootstrap.min.css"] = requestHandlers.sendBootstrap;
handle["/clear"] = requestHandlers.sendClear;
+if(server.demoMode==1){
+handle["/demo"] = requestHandlers.sendDemo;
+}else{
+ console.log("ERROR: Demo mode not active");
+}
+
server.start(router.route,handle,debug);
diff --git a/board.html b/board.html
index 619f62f..8b5152b 100644
--- a/board.html
+++ b/board.html
@@ -76,7 +76,7 @@ body {
location.reload();
});
- iosocket.on('onconnection', function() {
+ iosocket.on('connect', function() {
@@ -160,7 +160,12 @@ body {
+<<<<<<< HEAD
diff --git a/clear.html b/clear.html
index fea7823..6e59cd1 100644
--- a/clear.html
+++ b/clear.html
@@ -15,7 +15,7 @@
function initSocketIO()
{
iosocket = io.connect();
- iosocket.on('onconnection', function() {
+ iosocket.on('connect', function() {
iosocket.on('debugMessage', function(message) {
alert(message);
diff --git a/demo.html b/demo.html
new file mode 100644
index 0000000..929bee9
--- /dev/null
+++ b/demo.html
@@ -0,0 +1,220 @@
+
+
+
+
+
+ Chat
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/package.json b/package.json
index 67ebf8e..0c421be 100644
--- a/package.json
+++ b/package.json
@@ -4,10 +4,17 @@
"description": "A SMS Messageboard built using node and express",
"main": "app.js",
"dependencies": {
+ "async": "^2.0.0-rc.6",
"emojize": "^0.2.0",
"lowdb": "^0.12.5",
+<<<<<<< HEAD
"serialport": "^4.0.5",
"socket.io": "^1.4.5"
+=======
+ "nan": "^2.3.5",
+ "serialport": "^2.0.6",
+ "socket.io": "^1.4.8"
+>>>>>>> 754c9a7bd9436bf6309b8a11822ff7b2e3014aee
},
"devDependencies": {},
"scripts": {
diff --git a/requestHandlers.js b/requestHandlers.js
index b702778..db5622a 100644
--- a/requestHandlers.js
+++ b/requestHandlers.js
@@ -50,12 +50,19 @@ function sendJqueryUI(response) {
function sendClear(response) {
console.log("Request handler 'clear' was called.");
response.writeHead(200, {"Content-Type": "text/html"});
- var html = fs.readFileSync(__dirname + "/clear.html")
+ var html = fs.readFileSync(__dirname + "/clear.html");
response.end(html);
}
+function sendDemo(response) {
+ console.log("Request handler 'demo' was called.");
+ response.writeHead(200, {"Content-Type": "text/html"});
+ var html = fs.readFileSync(__dirname + "/demo.html");
+ response.end(html);
+}
exports.sendClear = sendClear;
+exports.sendDemo = sendDemo;
exports.sendBootstrap = sendBootstrap;
diff --git a/server.js b/server.js
index db0d97f..e3b00a9 100644
--- a/server.js
+++ b/server.js
@@ -19,6 +19,8 @@ var numberRecieved = "";
var timeRecieved = "";
var color = 0;
+module.exports.demoMode = 1;
+
// utility function for ucs2 decode
function ucs2Parse(ucs2){
codeArray = ucs2.match(/.{1,4}/g);
@@ -104,7 +106,7 @@ function initSocketIO(httpServer,debug)
});
socket.on('getLastMessages', function(number) {
- console.log('retrieving messages');
+ console.log('retrieving messages');
var times = db('messages').chain().takeRight(number).map('time').value();
var numbers = db('messages').chain().takeRight(number).map('number').value();
var messages = db('messages').chain().takeRight(number).map('message').value();
@@ -115,6 +117,26 @@ function initSocketIO(httpServer,debug)
}
});
+ socket.on('demoMessage', function(number,date,time,message) {
+ numberStringRecieved = "Date: "+date+" demo#demo#demo#demo";
+ numberRecieved = number;
+ console.log(numberRecieved);
+ timeRecieved = time;
+ var color = db('messages').chain().takeRight(1).map('color').value();
+ if (color == null)color = 0;//no messages yet
+ color++;
+ if(color > 4) color = 0;
+ console.log(message);
+ var messageRecieved = escapeHtml(message);
+ db('messages').push({ numberString: numberStringRecieved,number: numberRecieved, time: timeRecieved, message: messageRecieved,color: color });
+ //add a new message to the board directly
+ socketServer.emit('newMessage', timeRecieved, numberRecieved, convert(messageRecieved),color);
+ numberStringRecieved = null;
+ numberRecieved = null;
+ timeRecieved = null;
+ data=null;
+ });
+
});
}
@@ -122,12 +144,27 @@ function initSocketIO(httpServer,debug)
function serialListener(debug)
{
var receivedData = "";
+
serialPort = new SerialPort(portName, {
baudrate: 19200,
+<<<<<<< HEAD
parser: SerialPort.parsers.readline("\n")
});
+=======
+ parser: serialport.parsers.readline("\n")
+ },false); //don't open imedeatly
+
+ serialPort.open(function (err) {
+ if (err) {
+
+ return console.log('Error opening port: ', err.message,'### ENABELED DEMOMODE under /demo ! ##############');
+ }
+ if (err) {
+ module.exports.demoMode = 1;
+ return console.log('Error opening port: ', err.message,'### ENABELED DEMOMODE under /demo ! ##############');
+ }
+>>>>>>> 754c9a7bd9436bf6309b8a11822ff7b2e3014aee
- serialPort.on("open", function () {
console.log('opened serial communication');
serialPort.on('data', function(data) {
@@ -145,7 +182,7 @@ function serialListener(debug)
if(numberRecieved){
//console.log("emit");
var color = db('messages').chain().takeRight(1).map('color').value();
- console.log(JSON.stringify(color));
+ //console.log(JSON.stringify(color));
if (color == null)color = 0;//no messages yet
color++;
if(color > 4) color = 0;
@@ -156,6 +193,7 @@ function serialListener(debug)
numberStringRecieved = null;
numberRecieved = null;
timeRecieved = null;
+ data=null;
}
else {
//console.log("nothing");
@@ -165,6 +203,7 @@ function serialListener(debug)
//socketServer.emit('debugMessage', data);
}
});
+
var pincode = config('mainConfig').chain().find({ param: 'pincode' }).value()['value'];
serialPort.write('AT+CPIN='+pincode+'\r');
console.log("Sent Pincode...");
diff --git a/test.js b/test.js
deleted file mode 100644
index db09025..0000000
--- a/test.js
+++ /dev/null
@@ -1,7 +0,0 @@
-var utfx = require("utfx");
-//console.log(utfx.assertCharCode(0xD83DDE03));
-
-//var bytes = ["f09f9883"];
-
-var charcode = "0031";
-console.log(String.fromCharCode(parseInt(charcode, 16)));