Question

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);
Was it helpful?

Solution

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.

OTHER TIPS

put following line before any get_data. It should work. $AGI->get_data("silence/1",5,1);

-Kaustubh

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top