forked from lbsadmin/nodeMessageBoard
created config and added its functionality
This commit is contained in:
parent
01d9b85bcf
commit
ebfdeed96e
20
board.html
20
board.html
@ -45,6 +45,7 @@ body {
|
|||||||
var iosocket;
|
var iosocket;
|
||||||
var currentMessageCount = 0;
|
var currentMessageCount = 0;
|
||||||
var newDiv;
|
var newDiv;
|
||||||
|
var mynumber;
|
||||||
|
|
||||||
function getColor(num){
|
function getColor(num){
|
||||||
switch(num){
|
switch(num){
|
||||||
@ -76,9 +77,14 @@ body {
|
|||||||
iosocket.on('debugMessage', function(message) {
|
iosocket.on('debugMessage', function(message) {
|
||||||
alert(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) {
|
iosocket.on('newMessage', function(time,number,message,color) {
|
||||||
|
|
||||||
|
|
||||||
var censoredNumber = number.substring(0,3) + "********" +number.substring(number.length - 3, number.length);
|
var censoredNumber = number.substring(0,3) + "********" +number.substring(number.length - 3, number.length);
|
||||||
var messages = document.getElementById('messagesBody');
|
var messages = document.getElementById('messagesBody');
|
||||||
newDiv = document.createElement('div');
|
newDiv = document.createElement('div');
|
||||||
@ -90,7 +96,6 @@ body {
|
|||||||
newDiv.className="jumbotron";
|
newDiv.className="jumbotron";
|
||||||
newDiv.appendChild(newH1);
|
newDiv.appendChild(newH1);
|
||||||
newDiv.appendChild(newP);
|
newDiv.appendChild(newP);
|
||||||
//messages.appendChild(newDiv);
|
|
||||||
|
|
||||||
currentMessageCount++;
|
currentMessageCount++;
|
||||||
if(currentMessageCount > toDisplay)
|
if(currentMessageCount > toDisplay)
|
||||||
@ -100,8 +105,6 @@ body {
|
|||||||
$(this).remove();
|
$(this).remove();
|
||||||
document.getElementById('messagesBody').appendChild(newDiv);
|
document.getElementById('messagesBody').appendChild(newDiv);
|
||||||
});
|
});
|
||||||
//$('#messagesBody').find('div').first().remove();
|
|
||||||
//messages.removeChild(messages.firstChild);
|
|
||||||
currentMessageCount--;
|
currentMessageCount--;
|
||||||
}else{
|
}else{
|
||||||
document.getElementById('messagesBody').appendChild(newDiv);
|
document.getElementById('messagesBody').appendChild(newDiv);
|
||||||
@ -120,6 +123,7 @@ body {
|
|||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
initSocketIO();
|
initSocketIO();
|
||||||
iosocket.emit('getLastMessages',toDisplay);
|
iosocket.emit('getLastMessages',toDisplay);
|
||||||
|
iosocket.emit('getConfig');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -127,7 +131,6 @@ body {
|
|||||||
$('#check').click(function() {
|
$('#check').click(function() {
|
||||||
iosocket.emit('sendAT',toggleVal);
|
iosocket.emit('sendAT',toggleVal);
|
||||||
});
|
});
|
||||||
//$('#debugOut').html(String.fromCharCode(parseInt(s, 16),parseInt("DE03",16)));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -136,9 +139,8 @@ body {
|
|||||||
</head>
|
</head>
|
||||||
<body style="/*background-color: #D4D4D4;*/">
|
<body style="/*background-color: #D4D4D4;*/">
|
||||||
<div style="text-align:center;" >
|
<div style="text-align:center;" >
|
||||||
<!--<h1 style="color:#000066;">SMS Message Board</h1>-->
|
|
||||||
|
|
||||||
<h2>Send an SMS with a message to <span style="color:#3399ff;">+43 681 2033 4015</span></h2>
|
<h2>Send an SMS with a message to <span class="number" style="color:#3399ff;"></span></h2>
|
||||||
<div id="wrap">
|
<div id="wrap">
|
||||||
<div id="messagesBody">
|
<div id="messagesBody">
|
||||||
</div>
|
</div>
|
||||||
@ -152,7 +154,7 @@ body {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
<h2>Send an SMS with a message to <span style="color:#3399ff;">+43 681 2033 4015</span></h2>
|
<h2>Send an SMS with a message to <span class="number" style="color:#3399ff;"></span></h2>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
20
sample.config.json
Normal file
20
sample.config.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"mainConfig": [
|
||||||
|
{
|
||||||
|
"param": "serialport",
|
||||||
|
"value": "/dev/tty.usbmodemFD121"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"param": "pincode",
|
||||||
|
"value": "0000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"param": "port",
|
||||||
|
"value": "3000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"param": "mynumber",
|
||||||
|
"value": "+43************"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
15
server.js
15
server.js
@ -6,12 +6,12 @@ serialport = require("serialport");
|
|||||||
low = require('lowdb'),
|
low = require('lowdb'),
|
||||||
storage = require('lowdb/file-async'),
|
storage = require('lowdb/file-async'),
|
||||||
db = low('db.json', { storage });
|
db = low('db.json', { storage });
|
||||||
const port = 3000;
|
|
||||||
var SerialPort = serialport.SerialPort;
|
var SerialPort = serialport.SerialPort;
|
||||||
|
var config = low('config.json', { storage });
|
||||||
var socketServer;
|
var socketServer;
|
||||||
|
var port = config('mainConfig').chain().find({ param: 'port' }).value()['value'];
|
||||||
var serialPort;
|
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 numberStringRecieved = "";
|
||||||
var numberRecieved = "";
|
var numberRecieved = "";
|
||||||
@ -64,6 +64,11 @@ function initSocketIO(httpServer,debug)
|
|||||||
console.log("user connected");
|
console.log("user connected");
|
||||||
socket.emit('onconnection');
|
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) {
|
socket.on('sendAT', function(data) {
|
||||||
serialPort.write('AT\r');
|
serialPort.write('AT\r');
|
||||||
console.log('sending AT...');
|
console.log('sending AT...');
|
||||||
@ -131,8 +136,8 @@ function serialListener(debug)
|
|||||||
//socketServer.emit('debugMessage', data);
|
//socketServer.emit('debugMessage', data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
var pincode = config('mainConfig').chain().find({ param: 'pincode' }).value()['value'];
|
||||||
serialPort.write('AT+CPIN=3797\r');
|
serialPort.write('AT+CPIN='+pincode+'\r');
|
||||||
console.log("Sent Pincode...");
|
console.log("Sent Pincode...");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user