From deca94405b452b2a8accfad482035000e64db0bd Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Tue, 28 Jun 2016 20:10:33 +0200 Subject: [PATCH 1/6] Added demo gui for testing without gsm module --- demo.html | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ demo.js | 0 test.js | 7 -- 3 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 demo.html create mode 100644 demo.js delete mode 100644 test.js 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/demo.js b/demo.js new file mode 100644 index 0000000..e69de29 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))); From 191fd0a2315c7c2cc99c64f99d6b2b4494286e76 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Tue, 28 Jun 2016 20:14:35 +0200 Subject: [PATCH 2/6] Added serverside functions and routing for demomode --- app.js | 8 +++++++- clear.html | 2 +- server.js | 42 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 6 deletions(-) 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/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/server.js b/server.js index 55ea112..1ed408a 100644 --- a/server.js +++ b/server.js @@ -21,6 +21,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); @@ -106,7 +108,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(); @@ -117,6 +119,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; + }); + }); } @@ -124,12 +146,22 @@ function initSocketIO(httpServer,debug) function serialListener(debug) { var receivedData = ""; + serialPort = new SerialPort(portName, { baudrate: 19200, 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 ! ##############'); + } - serialPort.on("open", function () { console.log('opened serial communication'); serialPort.on('data', function(data) { @@ -147,7 +179,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; @@ -158,6 +190,7 @@ function serialListener(debug) numberStringRecieved = null; numberRecieved = null; timeRecieved = null; + data=null; } else { //console.log("nothing"); @@ -167,6 +200,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..."); From 92522aae022ade029ebdf878893f061044d4f96f Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Tue, 28 Jun 2016 20:15:22 +0200 Subject: [PATCH 3/6] cleanup --- demo.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 demo.js diff --git a/demo.js b/demo.js deleted file mode 100644 index e69de29..0000000 From e5a2a5888d3f186a5c1832728d25ab7e8ef6e35a Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Tue, 28 Jun 2016 20:15:57 +0200 Subject: [PATCH 4/6] more routingchanges --- requestHandlers.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; From c91434e233608e3aacef6ff058a81c22c7803f20 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Tue, 28 Jun 2016 20:16:56 +0200 Subject: [PATCH 5/6] Removing footer for better display --- board.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board.html b/board.html index c55840d..ef25df9 100644 --- a/board.html +++ b/board.html @@ -76,7 +76,7 @@ body { location.reload(); }); - iosocket.on('onconnection', function() { + iosocket.on('connect', function() { From 754c9a7bd9436bf6309b8a11822ff7b2e3014aee Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Tue, 28 Jun 2016 22:02:35 +0200 Subject: [PATCH 6/6] updated socket.io --- board.html | 2 ++ package.json | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/board.html b/board.html index ef25df9..26531c5 100644 --- a/board.html +++ b/board.html @@ -160,8 +160,10 @@ body {
+ diff --git a/package.json b/package.json index 00698c7..d53bc64 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,12 @@ "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", + "nan": "^2.3.5", "serialport": "^2.0.6", - "socket.io": "^1.4.5" + "socket.io": "^1.4.8" }, "devDependencies": {}, "scripts": {