gtkc.net

Slimserver


Display incoming caller information on your squeezebox.

"borrowed" from here (site was down when I tried to access it so I got it from the web archive)

The goal of this small nerd activity is that my slimp3 networked mp3 players display displays the callerID of inbound calls so that I see who is calling even without looking at a phone. I have a networked slimp3 player in my living room as well as in my office.

Prerequisites:

asterisk server
slimserver
any kind of slimp3/squeezebox/transporter device from slimdevices
slimdisplay.pl script (see below, modified based on gwendesigns SlimServer announcement script)

Purpose: Display incoming caller information on your squeezebox.

Instructions:

Copy the script below to a useful location (e.g. /usr/local/bin/ on a Linux system) and make it executable
$ chmod a+x /usr/local/bin/slimdisplay.pl

Take a look at the script options

$ ./slimdisplay.pl
usage: slimdisplay.pl <parameters>


Mandatory parameter:
--name=<player name> i.e.: "my slimp3"

Optional parameters:
--server=<ip> default: 127.0.0.1
--port=<nr> default: 9090
--line1=<text> default: "Line1 text"
--line2=<text> default: "Line2 text"
--user=<text> default: ""
--passw=<text> default: ""
--time=<nr> default: 16


Test the script
slimdisplay.pl --server 192.168.20.100 --name=Wohnen --line1=Hallo --Line2="Du Da"

Add in your extension.conf for your internal number (here 2210) you would like to display the callerID info for the following line. Make sure you use the priority order (here 2).
exten => 2210,2,system(/usr/local/bin/slimdisplay.pl --name=Wohnen --line1=${CALLERIDNAME} --Line2=${CALLERIDNUM})

Call your number to test...
#!/usr/bin/perl
# ********************************************************************
# modified by Lothar Gramelspacher
# http://blog.gramels.info/blog
# strip down to just display text messages
# renamed to slimdisplay.pl to reflect the change
# ********************************************************************
# Simple announcement script for SlimServer using the CLI v0.6
#
# Copyright (c) 2003 Felix Mueller (felix.mueller(at)gwendesign.com)
#
# This file might be distributed under the same terms as the
# SlimServer (www.slimdevices.com)
#
# Description:
# Plays a sound and shows a message interupting the current song
# - Store current parameters
# - The sound is appended to the current playlist and played
# - After the duration of the sound the sound is removed
# - Resume playing the current song
# - Restore current parameters
#
# Plattform tested:
# - Linux
# - Mac OS X 10.4 (Lothar Gramelspacher)
#
# Known restrictions:
# - trancoded files (i.e. ogg) will restart at the beginning after
# the announcement
# - a shuffled playlist will be reshuffled
# - does not work with iTunes (maybe works only with real SLIMP3)
#
# History:
# 0.6 - Added parameters for user/password (thanks to Mario Wagner)
# 0.5 - Adapted and tested with SlimServer 5.1.1
# 0.4 - Added command line parameter: --name --server --ip --line1 --line2 --sound
# - Added player selection by name
# 0.3 - Added power and volume persistency
# ********************************************************************

use strict;

use Getopt::Long;
use IO::Socket;


# Parameter defaults overridden by command line
my $szServerIP = "127.0.0.1";
my $iServerCLIPort = 9090;
my $szPlayerName = "";
my $szLine1 = "Line1 text";
my $szLine2 = "Line2 text";
my $user = "";
my $passw = "";
my $iDuration = 16;

# Internal parameters
my $debug = 0; # 0 = off, 1 = on

GetOptions( "server:s" => \$szServerIP,
"port:i" => \$iServerCLIPort,
"name:s" => \$szPlayerName,
"line1:s" => \$szLine1,
"line2:s" => \$szLine2,
"user:s" => \$user,
"passw:s" => \$passw,
"time:s" => \$iDuration);

# Check for a player name
showUsage() if( $szPlayerName eq "");

# Prepare variables
$szPlayerName = encodeChars( $szPlayerName);
$szLine1 = encodeChars( $szLine1);
$szLine2 = encodeChars( $szLine2);


# Try to open a connection to the SLIMP3 CLI
my $socket = IO::Socket::INET->new( PeerAddr => $szServerIP,
PeerPort => $iServerCLIPort,
Proto => "tcp",
Type => SOCK_STREAM);
# Check if socket was opened successful
if( !defined( $socket))
{
print "Cannot connect to $szServerIP:$iServerCLIPort\n";
exit;
}

# Login
if ($user ne "")
{
my $login = sendAndReceive("login $user $passw");
print $login;
$debug && print "user: $user, passw: $passw\n";
}

# Get the # of players
my $iNumPlayer = sendAndReceive( "player count ?");
$debug && print "iNumPlayer: $iNumPlayer\n";

# Get the player ip and port from the name
my $szPlayerIPAndPort = "";
for( my $i = 0; $i < $iNumPlayer; $i++)
{
if( $szPlayerName eq sendAndReceive( "player name $i ?"))
{
$szPlayerIPAndPort = sendAndReceive( "player address $i ?");
last;
}
}
$debug && print "szPlayerName: $szPlayerName\n";

# Check if successful
if( $szPlayerIPAndPort eq "")
{
print "Player with name: $szPlayerName could not be found!\n";
close( $socket);
exit;
}
$debug && print "szPlayerIPAndPort: $szPlayerIPAndPort\n";

# Show the announcement message
sendAndReceive( "display $szLine1 $szLine2 $iDuration");

close( $socket);

# ---------------------------------------------
sub sendAndReceive
{
my $cmd = shift;

return if( $cmd eq "");

# $cmd = $szPlayerIP . encodeChars( ":") . $iPlayerPort . " " . $cmd;

if( $szPlayerIPAndPort ne "")
{
$cmd = $szPlayerIPAndPort . " " . $cmd;
}
print $socket "$cmd\n";
my $answer = <$socket>;
$answer =~ s/$cmd //i;
$answer =~ s/\n//;

return $answer;
}

# ---------------------------------------------
sub encodeChars
{
my $myChars = $_[0];

my $MetaChars = quotemeta(' ;,/?|=+)(*&^%$#@!~`:');

$myChars =~ s/([$MetaChars\"\'\x80-\xFF])/"%" . uc( sprintf( "%2.2x", ord($1)))/eg;

return $myChars;
}

# ---------------------------------------------
sub showUsage
{
print "usage: slimdisplay.pl \n";
print "\n";
print "Mandatory parameter:\n";
print "--name=\ti.e.: \"my slimp3\"\n";
print "\n";
print "Optional parameters:\n";
print "--server=\t\tdefault: 127.0.0.1\n";
print "--port=\t\tdefault: 9090\n";
print "--line1=\t\tdefault: \"Line1 text\"\n";
print "--line2=\t\tdefault: \"Line2 text\"\n";
print "--user=\t\tdefault: \"\"\n";
print "--passw=\t\tdefault: \"\"\n";
print "--time=\t\tdefault: 16\n";
exit;
}