Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Socket-IO-Server/addressbook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
obj = {};
obj["phonenumber"] = "Randomname 1";
obj["phonenumber"] = "Randomname 2";
124 changes: 124 additions & 0 deletions Socket-IO-Server/callmonitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//https://github.com/tbasse/fritzbox-callmonitor
//(MIT License)
//
//Copyright (c) 2013 Thorsten Basse himself@tagedieb.com
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

/*
# Respsonse Format

Outbound:
Date;CALL;ConnectionId;Extension;CallerId;CalledPhoneNumber;

Inbound:
Date;RING;ConnectionId;CallerId;CalledPhoneNumber;

Connected:
Date;CONNECT;ConnectionId;Extension;Number;

Disconnected:
Date;DISCONNECT;ConnectionID;DurationInSeconds;
*/

var net = require('net');
var events = require('events');

var CallMonitor = function (host, port) {
var self = this;
this.call = {};

port = port || 1012;

function fritzboxDateToUnix(string) {
var d = string.match(/[0-9]{2}/g);
var result = '';
result += '20' + d[2] + '-' + d[1] + '-' + d[0];
result += ' ' + d[3] + ':' + d[4] + ':' + d[5];
return Math.floor(new Date(result).getTime() / 1000);
}

function parseMessage(buffer) {
var message = buffer.toString()
.toLowerCase()
.replace(/[\n\r]$/, '')
.replace(/;$/, '')
.split(';');
message[0] = fritzboxDateToUnix(message[0]);
return message;
}

var client = net.createConnection(port, host);

client.addListener('data', function (chunk) {
var data = parseMessage(chunk);

if (data[1] === 'ring') {
self.call[data[2]] = {
type: 'inbound',
start: data[0],
caller: data[3],
called: data[4]
};
self.emit('inbound', {
time: data[0],
caller: data[3],
called: data[4]
});
return;
}

if (data[1] === 'call') {
self.call[data[2]] = {
type: 'outbound',
start: data[0],
extension: data[3],
caller: data[4],
called: data[5]
};
self.emit('outbound', {
time: data[0],
extension: data[3],
caller: data[4],
called: data[5]
});
return;
}

if (data[1] === 'connect') {
self.call[data[2]]['connect'] = data[0];
self.emit('connected', {
time: data[0],
extension: self.call[data[2]]['extension'],
caller: self.call[data[2]]['caller'],
called: self.call[data[2]]['called']
});
return;
}

if (data[1] === 'disconnect') {
self.call[data[2]].disconnect = data[0];
self.call[data[2]].duration = parseInt(data[3], 10);

var call = self.call[data[2]];
delete(self.call[data[2]]);
self.emit('disconnected', call);
return;
}

});

client.addListener('end', function () {
client.end();
});
};

CallMonitor.prototype = new events.EventEmitter();

module.exports = CallMonitor;
28 changes: 28 additions & 0 deletions Socket-IO-Server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
var io = require('socket.io').listen(1234);

//Callmonitor
//Setup
require('./addressbook.js');
var CallMonitor = require('./callmonitor.js');
var fritzbox = {
address: '192.168.178.1',
port: '1012'
};
var monitor = new CallMonitor(fritzbox.address, fritzbox.port);

//Logic
monitor.on('inbound', function (call) {
if (call.caller != "") {
if (obj[call.caller]) {
io.sockets.emit('calling', obj[call.caller]);
}
if (!obj[call.caller]) {
io.sockets.emit('calling', call.caller);
}
};
});

monitor.on('disconnected', function (call) {
io.sockets.emit('calling', 'clear');
});
10 changes: 8 additions & 2 deletions calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ function get_url($url)
'header'=>"Accept-Language: en-US,en;q=0.8rn" .
"Accept-Encoding: gzip,deflate,sdchrn" .
"Accept-Charset:UTF-8,*;q=0.5rn" .
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.4rn"
)
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.4rn",
"ignore_errors" => true //Fix problems getting data
),
//Fixes problems in ssl
"ssl" => array(
"verify_peer"=>false,
"verify_peer_name"=>false
)
);

$context = stream_context_create($opts);
Expand Down
40 changes: 40 additions & 0 deletions css/callmonitor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#call {
background-color: white;
color: black;
margin: 0 165px;
font-size: 60px;
width: auto;
border-radius: 20px;
display: none;
}

#call h2{
font-size: 70px!important;
-webkit-margin-before: 10px!important;
-webkit-margin-after: -25px!important;
-webkit-margin-start: 0px!important;
-webkit-margin-end: 0px!important;
font-weight: bold;
letter-spacing: 2px;
}

#caller{
font-size: 50px;
padding-bottom: 6px;
letter-spacing: 2px;
}

#call img{
padding-top: 20px;
-webkit-margin-before: 10px!important;
}

#door img{
position: relative;
width: 200px;
}
#door{
position: relative;
top: 15px;
display: none;
}
Binary file added img/door.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/phone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<title>Magic Mirror</title>
<style type="text/css">
<?php include('css/main.css') ?>
<?php include('css/callmonitor.css') ?>
</style>
<link rel="stylesheet" type="text/css" href="css/weather-icons.css">
<script type="text/javascript">
Expand All @@ -14,8 +15,9 @@
<body>

<div class="top left"><div class="date small dimmed"></div><div class="time"></div><div class="calendar xxsmall"></div></div>
<div class="top right"><div class="windsun small dimmed"></div><div class="temp"></div><div class="forecast small dimmed"></div></div>
<div class="center-ver center-hor"><div class="dishwasher light">Vaatwasser is klaar!</div></div>
<div class="top right"><div class="windsun small dimmed"></div><div class="temp"></div><div class="forecast small dimmed"></div><div id="door"><img src="img/door.png"></div></div>
<div class="center-ver center-hor"><!--<div class="dishwasher light">Vaatwasser is klaar!</div></div>-->
<div class="center-ver center-hor"><div id="call" class="light"><img src="img/phone.png" height="80px"><h2>Incoming Call</h2><div id="caller"></div></div></div>
<div class="lower-third center-hor"><div class="compliment light"></div></div>
<div class="bottom center-hor"><div class="news medium"></div></div>

Expand All @@ -28,7 +30,8 @@
<script src="js/config.js"></script>
<script src="js/rrule.js"></script>
<script src="js/main.js?nocache=<?php echo md5(microtime()) ?>"></script>
<script src="js/socket.io.min.js"></script>
<script src="js/socket.io_1.3.2.js"></script>
<script src="js/callmonitor.js"></script>

</body>
</html>
20 changes: 20 additions & 0 deletions js/callmonitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//connect do Call monitor
var socket = io.connect('http://localhost:1234');
socket.on('calling', function (data){
if (data != 'clear'){
if (data=="door"){
$('#door').fadeIn(700);
$('.lower-third').fadeOut(700);
}
else {
$('#call').fadeIn(700);
$('.lower-third').fadeOut(700);
$('#caller').text(data);
}
}
if (data == 'clear'){
$('#call').fadeOut(700);
$('#door').fadeOut(700);
$('.lower-third').fadeIn(700);
}
});
20 changes: 10 additions & 10 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ jQuery(document).ready(function($) {
moment.lang(lang);

//connect do Xbee monitor
var socket = io.connect('http://rpi-alarm.local:8082');
socket.on('dishwasher', function (dishwasherReady) {
if (dishwasherReady) {
$('.dishwasher').fadeIn(2000);
$('.lower-third').fadeOut(2000);
} else {
$('.dishwasher').fadeOut(2000);
$('.lower-third').fadeIn(2000);
}
});
// var socket = io.connect('http://rpi-alarm.local:8082');
// socket.on('dishwasher', function (dishwasherReady) {
// if (dishwasherReady) {
// $('.dishwasher').fadeIn(2000);
// $('.lower-third').fadeOut(2000);
// } else {
// $('.dishwasher').fadeOut(2000);
// $('.lower-third').fadeIn(2000);
// }
// });


(function checkVersion()
Expand Down
Loading