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