User input sometimes doesn't work

I’m new to both Asterisk and UNIX. I have taken this project over from a co-worker that left our company, so it was already set up before I got to it and we know very little about it, but I need to make some changes to it. The purpose of our Asterisk setup is to have our customers call in, provide some information, and we give them an unlock code. To do this, we use a Perl script.

I’ve been searching around for a solution for about 2 days with no luck, although I would be shocked if I were the first to experience this problem. The problem is, about 75% of the time, when you call, the keys you press don’t work and you have to hang up and retry. If it works, the entire call is fine and all key presses work fine. If it doesn’t work, all key presses do nothing and you have to hang up and try again.

We never experienced this problem before I made changes to the Perl script (or at least none of our customers told us if they did see this problem), so I assume that the problem rests with some changes I made, but it seems nearly impossible for me (not knowing much about Asterisk as it is) to figure it out since it does work sometimes. Nothing unusual shows up in the verbose CLI.

We are running Asterisk 1.4.21.2~dfsg-3ubuntu2 on Ubuntu Server 9.04 (Jaunty). I can post my sip.conf, iax.conf, and extension.conf if necessary, but I don’t want to clog up the post with a ton of stuff if it’s not necessary. That’s the only information I know how to get, so if you need any other info, please tell me how to get it. I think it is from source, but I could easily be wrong about that.

Here is the script:
Before (no problems at all):

[code]#!/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();

($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 ${date}”);

$lrepeat = 1;
while ($lrepeat == 1)
{
$AGI->stream_file(‘thankyouforcalling’);

my $user_id = $AGI->get_data("userid", 10000, 6);
my $password = $AGI->get_data("password", 10000, 6);
my $mac = $AGI->get_data("uniqueID", 10000, 6);

my $url = <url removed>;
$AGI->verbose("url = ${url}");
$result = get $url;
@code = split(/ /, $result);
$AGI->verbose("result = ${result}");

if (@code[0] eq "No")
{
	$ll = 0;
	foreach $inty(@code)
	{
		if ($inty eq "No")
		{
			$ll++;
			next;
		}

		$base36 = "";
		
		for ($i=0; $i<7; $i++)
		{
			$digit = $inty % 36;

			if ($digit >= 10)
			{
				$digit += 87;
				$digit = pack("c", $digit); 
			}

			$base36 = $digit . $base36 ;
			$inty /= 36;
		}
		
		@code[$ll] = $base36;
		$ll++;
	}
	
	open(StatsFile, '>>/tmp/stats.txt');
	print StatsFile " $user_id \n";
	close (StatsFile);
	
	$AGI->verbose(@code[1] ."-". @code[2]);
	if (@code[3] > 0)
	{
		$AGI->verbose("-". @code[3] ."-". @code[4]);
	}
	
	$AGI->stream_file('unlockcode');
	$AGI->exec('SayPhonetic',@code[1]);
	$AGI->stream_file('dash');

	$AGI->exec('SayPhonetic',@code[2]);
	if (@code[3] > 0)
	{
		$AGI->stream_file('dash');
		$AGI->exec('SayPhonetic',@code[3]);
		$AGI->stream_file('dash');
		$AGI->exec('SayPhonetic',@code[4]);
	}

	$again = 1;
	while ($again)
	{
		$again = $AGI->get_data("again",10000,1);
		if ($again == 1)
		{
			$AGI->stream_file('unlockcode');
			$AGI->exec('SayPhonetic',@code[1]);
			$AGI->stream_file('dash');
			$AGI->exec('SayPhonetic',@code[2]);
			
			if (@code[3] > 0)
			{
				$AGI->stream_file('dash');
				$AGI->exec('SayPhonetic',@code[3]);
				$AGI->stream_file('dash');
				$AGI->exec('SayPhonetic',@code[4]);
			}
		}
	}
	$lrepeat = 0;
}
elsif (@code[0] eq "Error:")
{
	if ((@code[1] ==1) && (@code[2] == 0))
	{
		$AGI->stream_file('userandpassdontmatch')
	}
	else
	{
		$AGI->stream_file('callsupport');
		$lrepeat = 0;
	}
}

}

$AGI->stream_file(‘greatAgreatday’);
$AGI->hangup();
exit(0);[/code]

After:

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

$| = 1;

my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my $loop, $env, $demoFlag, $user_id, $password, $type, $mac, $url;
@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 from “. $input{‘callerid’} .” Received ${date}”);

$lrepeat = 1;
while ($lrepeat == 1)
{
$env = $AGI->get_data(‘thankyouforcalling’, 4000, 1); # press 7 during this message to switch to test environment

if ($env != 7)
{
	$env = 6;
}
$env -= 6;

if ($env == 1)	# test environment
{
	while (1)
	{
		$demoFlag = $AGI->get_data("demoFlag", 10000, 1);	# 1 = yes, 2 = no
		
		if ($demoFlag == 1 || $demoFlag == 2)
		{
			if ($demoFlag == 2)
			{
				$demoFlag = 0;
			}
			last;
		}
		
		$AGI->stream_file("invalidKey");
	}
}

if ($demoFlag == 0 || $env == 0)
{
	while (1)
	{
		$user_id = $AGI->get_data("userid", 10000, 6);
		
		if (length($user_id) == 6)
		{
			last;
		}
		
		$AGI->stream_file("invalidEntry");
	}
	
	while (1)
	{
		$password = $AGI->get_data("password", 10000, 6);
		
		if (length($password) == 6)
		{
			last;
		}
		
		$AGI->stream_file("invalidEntry");
	}
}

if ($env == 1)
{
	while (1)
	{
		$type = $AGI->get_data("type", 10000, 1);	# 1 = UNIQUE, 2 = SERIAL
		
		if ($type == 1 || $type == 2)
		{
			last;
		}
		
		$AGI->stream_file("invalidKey");
	}
}
else
{
	$type = 1;
}

while (1)
{
	my $file;
	
	if ($type == 1)
	{
		$mac = $AGI->get_data("uniqueID", 10000, 6);
	}
	else
	{
		$mac = $AGI->get_data("serial", 10000, 8);
	}
		
		
	if ((length($mac) == 6 && $type == 1) || (length($mac) == 8 && $type == 2))
	{
		last;
	}
	
	$AGI->stream_file("invalidEntry");
}

if ($env == 0)
{
	$url = <url removed>;
}
else
{
	$url = <url removed>;
}
$AGI->verbose("url = ${url}");
$result = get $url;
@code = split(/ /, $result);
$AGI->verbose("result = ${result}");

if (@code[0] eq "No")
{
	$ll = 0;
	foreach $inty(@code)
	{
		if ($inty eq "No")
		{
			$ll++;
			next;
		}

		$base36 = "";
		
		for ($i=0; $i<7; $i++)
		{
			$digit = $inty % 34;

			if ($digit == 0)
			{
				$digit += 35;
			}
			elsif ($digit == 24)
			{
				$digit += 10;
			}

			if ($digit >= 10)
			{
				$digit += 87;
				$digit = pack("c", $digit); 
			}

			$base36 = $digit . $base36;
			$inty /= 34;
		}
		
		@code[$ll] = $base36;
		$ll++;
	}
	
	open(StatsFile, '>>/tmp/stats.txt');
	print StatsFile " $user_id \n";
	close (StatsFile);
	
	my $message = @code[1] ."-". @code[2];
	if (@code[3] > 0)
	{
		$message .= "-". @code[3] ."-". @code[4];
	}
	$AGI->verbose($message);
	
	do
	{
		$AGI->stream_file('unlockcode');
		$AGI->exec('SayPhonetic', @code[1]);
		$AGI->stream_file('dash');
		$AGI->exec('SayPhonetic', @code[2]);
		
		if (@code[3] > 0)
		{
			$AGI->stream_file('dash');
			$AGI->exec('SayPhonetic', @code[3]);
			$AGI->stream_file('dash');
			$AGI->exec('SayPhonetic', @code[4]);
		}
		
		$again = $AGI->get_data("again", 10000, 1);
	} while ($again);
	$lrepeat = 0;
}
elsif (@code[0] eq "Error:")
{
	if (@code[1] == 1 && @code[2] == 0)
	{
		$AGI->stream_file('userandpassdontmatch');
	}
	elsif (@code[1] == 2 && @code[2] == 0)
	{
		$AGI->stream_file('licenseAlreadyActivated');
		$lrepeat = 0;
	}
	elsif (@code[1] == 3 && @code[2] == 0)
	{
		$AGI->stream_file('generationsDontMatch');
		$lrepeat = 0;
	}
	elsif (@code[1] == 4 && @code[2] == 0)
	{
		if ($type == 1)
		{
			$AGI->stream_file('30DayLicenseAlreadyActivatedForUniqueID');
		}
		else
		{
			$AGI->stream_file('30DayLicenseAlreadyActivatedForSerial');
		}
		$lrepeat = 0;
	}
	elsif (@code[1] == 5 && @code[2] == 0)
	{
		$AGI->stream_file('invalidSerial');
		$lrepeat = 0;
	}
	else
	{
		$AGI->stream_file('callsupport');
		$lrepeat = 0;
	}
}

}

$AGI->stream_file(‘greatAgreatday’);
$AGI->hangup();
exit(0);[/code]

I know it’s always a pain to read through someone else’s code, but I would GREATLY appreciate any help or suggestions you could offer. Remember, I’m brand-spankin’ new to Asterisk, so please be as descriptive as possible. Thanks!

-Travis

are you using a SIP provider?

This sounds like a DTMF issue…

are you guys using any codecs?

-Jake
www.voipcitadel.com

You can’t use Asterisk, for voice or video, without using codecs. What did you really mean?

let me rephrase… are you using anything outside of ulaw. I.E. G729?

-Jake
voipcitadel.com