1
0
This commit is contained in:
Lukas Bachschwell 2016-11-08 17:54:26 +01:00
commit 4ceed221f5
8 changed files with 291 additions and 14 deletions

8
app.js
View File

@ -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);

View File

@ -76,7 +76,7 @@ body {
location.reload();
});
iosocket.on('onconnection', function() {
iosocket.on('connect', function() {
@ -160,7 +160,12 @@ body {
<div id="debugOut"> </div>
</div>
</div>
<<<<<<< HEAD
<!-- <div id="footer">
=======
<!--
<div id="footer">
>>>>>>> 754c9a7bd9436bf6309b8a11822ff7b2e3014aee
<h2>Send an SMS with a message to <span class="number" style="color:#3399ff;"></span></h2>
</div>
-->

View File

@ -15,7 +15,7 @@
function initSocketIO()
{
iosocket = io.connect();
iosocket.on('onconnection', function() {
iosocket.on('connect', function() {
iosocket.on('debugMessage', function(message) {
alert(message);

220
demo.html Normal file
View File

@ -0,0 +1,220 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=320, initial-scale=1">
<title>Chat</title>
<script src="/js/jquery-1.12.1.min"></script>
<script src="/js/jquery-ui.js"></script>
<script src="/socket.io/socket.io.js"></script>
</head>
<script type="text/javascript">
var iosocket;
function initSocketIO()
{
iosocket = io.connect();
iosocket.on('connect', function() {
createSystemMessage('[Connected]');
console.log("connect");
iosocket.on('debugMessage', function(message) {
alert(message);
});
iosocket.on('disconnect', function() {
createSystemMessage('[Disconnected]');
});
});
}
window.onload = function() {
initSocketIO();
};
function createSystemMessage(message) {
var message = document.createTextNode(message);
var messageBox = document.createElement('p');
messageBox.className = 'system';
messageBox.appendChild(message);
var chat = document.getElementById('chat_box');
chat.appendChild(messageBox);
}
function createUserMessage(user, message) {
var user = document.createTextNode(user + ': ');
var userBox = document.createElement('span');
userBox.className = 'username';
userBox.appendChild(user);
var message = document.createTextNode(message);
var messageBox = document.createElement('p');
messageBox.appendChild(userBox);
messageBox.appendChild(message);
var chat = document.getElementById('chat_box');
chat.appendChild(messageBox);
}
function sendMessage() {
var user = document.getElementById('user');
var message = document.getElementById('message');
var number = document.getElementById('number');
var currentDate = new Date();
var time = currentDate.toLocaleTimeString();
var date = currentDate.getDate()+"/"+currentDate.getMonth()+"/"+currentDate.getFullYear();
iosocket.emit('demoMessage',number.value.toString(),date,time,message.value);
createUserMessage(time,message.value);
message.value = "";
};
// added a little wrapper for enter submit
function submitEnter(e){
if (( e.keyCode == 13 )&&(e.shiftKey === false)) {
sendMessage();
}
}
</script>
<body>
<div id="wrapper">
<div id="chat_box" class="content"></div>
<div id="footer">
<div class="content">
<input type="text" id="number" value="+4301234567890" />
<input type="text" id="message" onkeypress="return submitEnter(event)" placeholder="Enter a Test Message! (Or emoji!, google if if you don't know how)" />
<input type="button" id="send_btn" value="Send" onclick="sendMessage()">
</div>
</div>
</div>
</body>
</html>
<style type="text/css">
* {
font-family: "Arial";
font-size: 24px;
}
html, body, #wrapper {
margin: 0;
padding: 0;
height: 100%;
}
#wrapper {
background-color: #ecf0f1;
}
#chat_box {
box-sizing: border-box;
height: 100%;
overflow: auto;
padding-bottom: 50px;
}
#footer {
box-sizing: border-box;
position: fixed;
bottom: 0;
height: 50px;
width: 100%;
background-color: #2980b9;
}
#footer .content {
padding-top: 4px;
position: relative;
}
#user { width: 20%; }
#message { width: 68%; }
#send_btn {
width: 10%;
position: absolute;
right: 0;
bottom: 0;
margin: 0;
}
.content {
width: 70%;
margin: 0 auto;
}
input[type="text"],
input[type="button"] {
border: 0;
color: #fff;
}
input[type="text"] {
background-color: #146EA8;
padding: 3px 10px;
}
input[type="button"] {
background-color: #f39c12;
border-right: 2px solid #e67e22;
border-bottom: 2px solid #e67e22;
min-width: 70px;
display: inline-block;
}
input[type="button"]:hover {
background-color: #e67e22;
border-right: 2px solid #f39c12;
border-bottom: 2px solid #f39c12;
cursor: pointer;
}
.system,
.username {
color: #aaa;
font-style: italic;
font-family: monospace;
font-size: 16px;
}
@media(max-width: 1000px) {
.content { width: 90%; }
}
@media(max-width: 780px) {
#footer { height: 91px; }
#chat_box { padding-bottom: 91px; }
#user { width: 100%; }
#message { width: 80%; }
}
@media(max-width: 400px) {
#footer { height: 135px; }
#chat_box { padding-bottom: 135px; }
#message { width: 100%; }
#send_btn {
position: relative;
margin-top: 3px;
width: 100%;
}
}
</style>

View File

@ -4,10 +4,17 @@
"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",
<<<<<<< HEAD
"serialport": "^4.0.5",
"socket.io": "^1.4.5"
=======
"nan": "^2.3.5",
"serialport": "^2.0.6",
"socket.io": "^1.4.8"
>>>>>>> 754c9a7bd9436bf6309b8a11822ff7b2e3014aee
},
"devDependencies": {},
"scripts": {

View File

@ -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;

View File

@ -19,6 +19,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);
@ -115,6 +117,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;
});
});
}
@ -122,12 +144,27 @@ function initSocketIO(httpServer,debug)
function serialListener(debug)
{
var receivedData = "";
serialPort = new SerialPort(portName, {
baudrate: 19200,
<<<<<<< HEAD
parser: SerialPort.parsers.readline("\n")
});
=======
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 ! ##############');
}
>>>>>>> 754c9a7bd9436bf6309b8a11822ff7b2e3014aee
serialPort.on("open", function () {
console.log('opened serial communication');
serialPort.on('data', function(data) {
@ -145,7 +182,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;
@ -156,6 +193,7 @@ function serialListener(debug)
numberStringRecieved = null;
numberRecieved = null;
timeRecieved = null;
data=null;
}
else {
//console.log("nothing");
@ -165,6 +203,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...");

View File

@ -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)));