views:

124

answers:

1

I am new to Asterisk (VoIP) and am rather new to UNIX/Perl. I'm taking this over from a co-worker that left the company, so I didn't set this up in the first place, I just need to make some changes.

I'm having a problem where I use get_data() to get the user's keypad entry, but the keys are just ignored and the get_data() function just times out. I've been trying to narrow down exactly when it happens, but every time I think I have narrowed it down to "it only happens when I...", I try it again and it works. The problem happens probably about 75% of the time, and with my lack of experience using Asterisk, I have no idea what could be causing it.

Below is an excerpt from my code that I've tested and reproduced the problem. The problem is noticed after the 'thankyouforcalling' file is streamed at $demoFlag = $AGI->get_data("demoFlag", 10000, 1);. Does anyone have any idea what could be causing this? Thanks!

basic.pl:

#!/usr/bin/perl
use Asterisk::AGI;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;

my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my $loop, $env, $demoFlag, $user_id, $password, $type, $mac;
@types = ("", "u", "s");
@environments = ("prod", "test");

($seconds, $minutes, $hours, $day, $month, $year) = localtime();
$year += 1900;
$month += 1;
$date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year, $month, $day, $hours,    $minutes, $seconds);
$AGI->verbose("Call Received from ". $input{'callerid'} ." ${date}");

$lrepeat = 1;
while ($lrepeat == 1)
{
    $env = 0;
    $AGI->stream_file('thankyouforcalling');

    do
    {
        $loop = 0;
        $demoFlag = $AGI->get_data("demoFlag", 10000, 1);   # 1 = yes, 2 = no

        if ($demoFlag != 1 && $demoFlag != 2)
        {
            $AGI->stream_file("invalidKey");
            $loop = 1;
        }
    } while ($loop);

    if ($demoFlag == 2)
    {
        do
        {
            $loop = 0;
            $user_id = $AGI->get_data("userid", 10000, 6);

            if (length($user_id) != 6)
            {
                $AGI->stream_file("invalidEntry");
                $loop = 1;
            }
        } while ($loop);

        do
        {
            $loop = 0;
            $password = $AGI->get_data("password", 10000, 6);

            if (length($password) != 6)
            {
                $AGI->stream_file("invalidEntry");
                $loop = 1;
            }
        } while ($loop);
    }

    do
    {
        $loop = 0;  
        $type = $AGI->get_data("type", 10000, 1);   # 1 = UNIQUE, 2 = SERIAL

        if ($type != 1 && $type != 2)
        {
            $AGI->stream_file("invalidKey");
            $loop = 1;
        }
    } while ($loop);

    do
    {
        $loop = 0;
        my $file;

        if ($type == 1) { $file = "uniqueID"; }
        else { $file = "serial" }

        $mac = $AGI->get_data($file, 10000, 6);

        if (length($mac) != 6)
        {
            $AGI->stream_file("invalidEntry");
            $loop = 1;
        }
    } while ($loop);

    $lrepeat = 0;
}

$AGI->stream_file('greatAgreatday');
$AGI->hangup();
exit(0);
A: 

More than likely it's an issue with DTMF settings between Asterisk and a sub-set of your callers.

If the script always works for you and always fails for someone else then it's almost certainly a DTMF settings issue. If you are receiving the calls using the SIP channel then the DTMF settings are set in sip.conf (I think there's sip_users.conf or something now as well).

If the script sporadically fails for all callers then it's going to be trickier. If the SIP caller is using inband DTMF, i.e. the key presses are being sent within the call audio, then Asterisk will extract them by attempting to identify signals within the stream. A number of things can throw a spanner in the works for this but the first thing I would be looking for is any dropped RTP packets, perhaps your network gets particulalry busy around the same time as the script failures.

If your calls are coming in over ISDN then you can discount the above.

sipwiz
Thanks for the response. I use my office phone to call our 1-800 number that connects to the Perl script. Using the same phone, it works sometimes and fails sometimes. The same exact behavior is seen when calling from my cell phone. So I don't think it's the DTMF settings, based on your description. Not sure how to check for dropped RTP packets, and I don't know if the calls are coming in over ISDN or not (I'm a noob). One thing to note is, if the first key works, all keys will work. If the first doesn't work, none of the subsequent keys will work, and you need to hang up and retry.
Travesty3
The type of DTMF inconsistency you are describing is typical of VoIP call legs (such as SIP or IAX). You do need to find out how your calls are being reeceived by your Asterisk server. The easy way to check is to find out if there are any extra PCI cards installed in it. To use ISDN a special PCI card would have to be installed in the server.
sipwiz