diff --git a/app.js b/app.js index e0073d9..61df93b 100644 --- a/app.js +++ b/app.js @@ -9,43 +9,3 @@ handle["/"] = requestHandlers.sendInterface; handle["/interface"] = requestHandlers.sendInterface; server.start(router.route,handle,debug); - - - - -// old app.js -/* -console.log("hello world\r"); -var port = 3000; -var express = require('express') -var app = express() - -app.get('/', function (req, res) { - res.send('Hello World') -}); - -app.listen(port, function () { - console.log('Example app listening on port '+port+'!'); -}); - -var serialport = require("serialport"); -var SerialPort = serialport.SerialPort; -var serialPort = new SerialPort("/dev/tty.usbmodemFD121", { - baudrate: 19200, - parser: serialport.parsers.readline("\n") -}); - - -serialPort.on("open", function () { - console.log('open'); -serialPort.on("data", function (data) { - console.log("here: "+data); - - app.get('/', function (req, res) { - res.send(data) - }) -}); - -serialPort.write("AT+CPIN?\r"); -}); -*/ diff --git a/board.html b/board.html index 8dda5cd..6bb1b6e 100644 --- a/board.html +++ b/board.html @@ -49,23 +49,20 @@ { iosocket = io.connect(); iosocket.on('onconnection', function(value) { - pollOneH = value.pollOneValue/2; // recieve start poll value from server initButton(); - // recieve changed values by other client from server - iosocket.on('updateData', function(recievedData) { - pollOneH = recievedData.pollOneValue/2; // recieve start poll value from server + iosocket.on('debugMessage', function(message) { + alert(message); }); - iosocket.on('newMessage', function(message) { - var date = new Date(); - + iosocket.on('newMessage', function(number,message) { var mainTable = document.getElementById("mainTable"); var newRow = mainTable.insertRow(mainTable.rows.length); - var dateCell = newRow.insertCell(0); - var textCell = newRow.insertCell(1); - dateCell.innerHTML = date.toLocaleString(); + var numberCell = newRow.insertCell(1); + var textCell = newRow.insertCell(2); + dateCell.innerHTML = "Insert serverdate"; + numberCell.innerHTML = number; textCell.innerHTML = message; }); }); @@ -74,14 +71,17 @@ function initButton() { - $( "#check" ).button(); + $("#check").button(); } window.onload = function() { initSocketIO(); + iosocket.emit('getLastMessages',10); }; $(document).ready(function() { + //request last messages from server + $('#check').click(function() { toggleVal += 1; toggleVal %= 2; @@ -91,23 +91,19 @@ -
+

Data from Sim900

- +
- +
UhrzeitNachrichtUhrzeitNummerNachricht
- -
-
+
+

Debug functions

- +
-

LED Dimmer

-
-
diff --git a/server.js b/server.js index 42835fc..b68eb99 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,9 @@ http = require('http'), socketio = require('socket.io'), url = require("url"), serialport = require("serialport"); +low = require('lowdb'), +storage = require('lowdb/file-async'), +db = low('db.json', { storage }); var SerialPort = serialport.SerialPort; @@ -10,6 +13,7 @@ var socketServer; var serialPort; var portName = '/dev/tty.usbmodemFD121'; //change this to your Arduino port var sendData = ""; +var numberStringRecieved = ""; var numberRecieved = ""; // handle contains locations to browse to (vote and poll); pathnames. @@ -45,10 +49,22 @@ function initSocketIO(httpServer,debug) socketServer.on('update', function(data) { socket.emit('updateData',{pollOneValue:data}); }); + socket.on('sendAT', function(data) { serialPort.write('AT\r'); console.log('sending AT...'); }); + + socket.on('getLastMessages', function(number) { + console.log('retrieving messages'); + 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]); + } + }); + }); } @@ -70,16 +86,20 @@ function serialListener(debug) console.log("\r"); //+data.length // send the incoming data to clients using the socket. if(data.startsWith("+CMT:")){ // if message ok - numberRecieved = data; + numberStringRecieved = data; + numberRecieved = data.substring(data.indexOf('+CMT: "') + 7, data.indexOf('",')); } else if (data.length > 1) { - //add a new message to the board directly + if(numberRecieved){ - console.log("emit"); - socketServer.emit('newMessage', numberRecieved+" "+data); + //console.log("emit"); + db('messages').push({ numberString: numberStringRecieved,number: numberRecieved, message: data }); + //add a new message to the board directly + socketServer.emit('newMessage', numberRecieved,data); + numberStringRecieved = null; numberRecieved = null; } else { - console.log("nothing"); + //console.log("nothing"); } } else { //debugMessages trigger an alert on the clients