2
1
mirror of https://github.com/s00500/nodeMessageBoard.git synced 2024-11-21 13:10:55 +00:00

added gsm timestamp to db and display

This commit is contained in:
Lukas Bachschwell 2016-03-08 12:27:22 +01:00
parent 5c3d9216c6
commit 5f58d8834c
3 changed files with 31 additions and 52 deletions

View File

@ -35,35 +35,41 @@
<script src="/socket.io/socket.io.js"></script>
<script>
const toDisplay = 5; //define the number of messages to show
var iosocket;
var pollOneH = 0;
var poll1;
var text;
var potValue;
var prevPotValue;
var currentMessageCount = 0;
//var onOff = false;
var toggleVal = 0;
function initSocketIO()
{
iosocket = io.connect();
iosocket.on('onconnection', function(value) {
iosocket.on('onconnection', function() {
initButton();
iosocket.on('debugMessage', function(message) {
alert(message);
});
iosocket.on('newMessage', function(number,message) {
iosocket.on('newMessage', function(time,number,message) {
var mainTable = document.getElementById("mainTable");
var newRow = mainTable.insertRow(mainTable.rows.length);
var dateCell = newRow.insertCell(0);
var numberCell = newRow.insertCell(1);
var textCell = newRow.insertCell(2);
dateCell.innerHTML = "Insert serverdate";
dateCell.innerHTML = time;
numberCell.innerHTML = number;
textCell.innerHTML = message;
currentMessageCount++;
if(currentMessageCount > toDisplay)
{
//Remove the top row
mainTable.deleteRow(1);
currentMessageCount--;
}
});
});
}
@ -76,7 +82,7 @@
window.onload = function() {
initSocketIO();
iosocket.emit('getLastMessages',10);
iosocket.emit('getLastMessages',toDisplay);
};
$(document).ready(function() {

40
db.json
View File

@ -1,44 +1,16 @@
{
"messages": [
{
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,11:47:24+04\"\r",
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,12:21:34+04\"\r",
"number": "+4369910088886",
"message": "123\r"
"time": "12:21:34",
"message": "Test6\r"
},
{
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,11:47:27+04\"\r",
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,12:22:09+04\"\r",
"number": "+4369910088886",
"message": "456\r"
},
{
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,11:47:32+04\"\r",
"number": "+4369910088886",
"message": "789\r"
},
{
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,11:47:36+04\"\r",
"number": "+4369910088886",
"message": "Abc\r"
},
{
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,12:04:10+04\"\r",
"number": "+4369910088886",
"message": "Test 3\r"
},
{
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,12:04:12+04\"\r",
"number": "+4369910088886",
"message": "Idndidn\r"
},
{
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,12:05:40+04\"\r",
"number": "+4369910088886",
"message": "Kfjj\r"
},
{
"numberString": "+CMT: \"+4369910088886\",\"\",\"16/03/08,12:06:33+04\"\r",
"number": "+4369910088886",
"message": "Oljvv\r"
"time": "12:22:09",
"message": "Lol\r"
}
]
}

View File

@ -12,9 +12,10 @@ var SerialPort = serialport.SerialPort;
var socketServer;
var serialPort;
var portName = '/dev/tty.usbmodemFD121'; //change this to your Arduino port
var sendData = "";
var numberStringRecieved = "";
var numberRecieved = "";
var timeRecieved = ""
// handle contains locations to browse to (vote and poll); pathnames.
function startServer(route,handle,debug)
@ -45,10 +46,7 @@ function initSocketIO(httpServer,debug)
}
socketServer.on('connection', function (socket) {
console.log("user connected");
socket.emit('onconnection', {pollOneValue:sendData});
socketServer.on('update', function(data) {
socket.emit('updateData',{pollOneValue:data});
});
socket.emit('onconnection');
socket.on('sendAT', function(data) {
serialPort.write('AT\r');
@ -57,11 +55,12 @@ function initSocketIO(httpServer,debug)
socket.on('getLastMessages', function(number) {
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();
for(var i = 0; i < messages.length; i++){
socket.emit('newMessage',numbers[i],messages[i]);
socket.emit('newMessage',times[i],numbers[i],messages[i]);
}
});
@ -88,15 +87,17 @@ function serialListener(debug)
if(data.startsWith("+CMT:")){ // if message ok
numberStringRecieved = data;
numberRecieved = data.substring(data.indexOf('+CMT: "') + 7, data.indexOf('",'));
timeRecieved = data.substring(data.indexOf('","","') + 15, data.indexOf('+04'));
} else if (data.length > 1) {
if(numberRecieved){
//console.log("emit");
db('messages').push({ numberString: numberStringRecieved,number: numberRecieved, message: data });
db('messages').push({ numberString: numberStringRecieved,number: numberRecieved, time: timeRecieved, message: data });
//add a new message to the board directly
socketServer.emit('newMessage', numberRecieved,data);
socketServer.emit('newMessage', timeRecieved, numberRecieved, data);
numberStringRecieved = null;
numberRecieved = null;
timeRecieved = null;
}
else {
//console.log("nothing");