From ebfdeed96ede501f18d9afa51f17d5a78e21e920 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Thu, 10 Mar 2016 15:08:22 +0100 Subject: [PATCH] created config and added its functionality --- board.html | 28 +++++++++++++++------------- sample.config.json | 20 ++++++++++++++++++++ server.js | 15 ++++++++++----- 3 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 sample.config.json diff --git a/board.html b/board.html index 2dae9cc..e2793dd 100644 --- a/board.html +++ b/board.html @@ -45,6 +45,7 @@ body { var iosocket; var currentMessageCount = 0; var newDiv; + var mynumber; function getColor(num){ switch(num){ @@ -73,12 +74,17 @@ body { iosocket.on('onconnection', function() { initButton(); - iosocket.on('debugMessage', function(message) { - alert(message); - }); + iosocket.on('debugMessage', function(message) { + alert(message); + }); + + iosocket.on('config', function(phonenumber) { + mynumber = phonenumber; + $( "span.number" ).html(mynumber); + console.log(mynumber); + }); + iosocket.on('newMessage', function(time,number,message,color) { - - var censoredNumber = number.substring(0,3) + "********" +number.substring(number.length - 3, number.length); var messages = document.getElementById('messagesBody'); newDiv = document.createElement('div'); @@ -90,7 +96,6 @@ body { newDiv.className="jumbotron"; newDiv.appendChild(newH1); newDiv.appendChild(newP); - //messages.appendChild(newDiv); currentMessageCount++; if(currentMessageCount > toDisplay) @@ -100,8 +105,6 @@ body { $(this).remove(); document.getElementById('messagesBody').appendChild(newDiv); }); - //$('#messagesBody').find('div').first().remove(); - //messages.removeChild(messages.firstChild); currentMessageCount--; }else{ document.getElementById('messagesBody').appendChild(newDiv); @@ -120,6 +123,7 @@ body { window.onload = function() { initSocketIO(); iosocket.emit('getLastMessages',toDisplay); + iosocket.emit('getConfig'); }; @@ -127,7 +131,6 @@ body { $('#check').click(function() { iosocket.emit('sendAT',toggleVal); }); - //$('#debugOut').html(String.fromCharCode(parseInt(s, 16),parseInt("DE03",16))); }); @@ -136,9 +139,8 @@ body {
- - -

Send an SMS with a message to +43 681 2033 4015

+ +

Send an SMS with a message to

@@ -152,7 +154,7 @@ body {
diff --git a/sample.config.json b/sample.config.json new file mode 100644 index 0000000..d3b20cd --- /dev/null +++ b/sample.config.json @@ -0,0 +1,20 @@ +{ + "mainConfig": [ + { + "param": "serialport", + "value": "/dev/tty.usbmodemFD121" + }, + { + "param": "pincode", + "value": "0000" + }, + { + "param": "port", + "value": "3000" + }, + { + "param": "mynumber", + "value": "+43************" + } + ] +} diff --git a/server.js b/server.js index 64c258d..ae0651b 100644 --- a/server.js +++ b/server.js @@ -6,12 +6,12 @@ serialport = require("serialport"); low = require('lowdb'), storage = require('lowdb/file-async'), db = low('db.json', { storage }); -const port = 3000; var SerialPort = serialport.SerialPort; - +var config = low('config.json', { storage }); var socketServer; +var port = config('mainConfig').chain().find({ param: 'port' }).value()['value']; var serialPort; -var portName = '/dev/tty.usbmodemFD121'; //change this to your Arduino port +var portName = config('mainConfig').chain().find({ param: 'serialport' }).value()['value']; var numberStringRecieved = ""; var numberRecieved = ""; @@ -64,6 +64,11 @@ function initSocketIO(httpServer,debug) console.log("user connected"); socket.emit('onconnection'); + socket.on('getConfig', function(data) { + var number = config('mainConfig').chain().find({ param: 'mynumber' }).value()['value']; + socket.emit('config',number); + }); + socket.on('sendAT', function(data) { serialPort.write('AT\r'); console.log('sending AT...'); @@ -131,8 +136,8 @@ function serialListener(debug) //socketServer.emit('debugMessage', data); } }); - - serialPort.write('AT+CPIN=3797\r'); + var pincode = config('mainConfig').chain().find({ param: 'pincode' }).value()['value']; + serialPort.write('AT+CPIN='+pincode+'\r'); console.log("Sent Pincode..."); }); }