[Freeswitch-users] Fwd: execute function in ESL.pm module is not working

velusamy velu velu.technical at gmail.com
Thu Aug 6 22:06:21 PDT 2009


Dear Expert,
   Thanks for you reply....

My Perl Script is,
use strict;
use warnings;

#---------------------------------------------------------------------------
# Event socket library.
# Socket programming
# printing the data structures
# Using posix parametered functions.
#---------------------------------------------------------------------------
use lib('/root/freeswitch-1.0.3/libs/esl/perl/');
require ESL;
use IO::Socket::INET;
use Data::Dumper qw(Dumper);
use POSIX;
use Config::IniFiles;


# Global variables to store the socket connection and eneterd DTM digits.
my ($conn,$digit);
$digit='';

#Registering the ALARM signal.
$SIG{ALRM}=\&sub_alr;

# When alarm signal occurs call the play_digit function
sub sub_alr {
        print "IN Sigalarm---\n";
        &play_digit;
        return ;
}       # ----------  end of subroutine sub_alr  ----------



# Play the voice files for menu.
sub play(){
                $conn->execute("playback","ivr/ivr-please.wav");
                $conn->execute("playback","ivr/ivr-enter_ext.wav");
}


sub play_digit {
        print "In Play Digit....\n";
        my      ( $par1 )       = $digit; #$digit is global variable

        print "Eneterd Digits=",$digit,"\n";
        ################################################################
        # Here what is my problem the execute function is not working  #
        ################################################################
        $conn->execute("phrase", "spell,$par1");
        return ;
}       # ----------  end of subroutine play_digit  ----------


#---------------------------------------------------------------------------
# IP address and port of the server.
# Sound path file.
#---------------------------------------------------------------------------
my $ip = "192.168.1.222"; my $port = '5057';
my $sound_path = "/usr/local/freeswitch/sounds/en/us/callie/";


# Creating a socket
my $sock = new IO::Socket::INET (
        LocalHost => $ip,
        LocalPort => $port,
        Proto     => 'tcp',
        Listen    => 1,
        Reuse     => 1
);
# Checking the error.
die "Cannot create a socket:$!\n" unless $sock;


for(;;){

        my $new_socket = $sock->accept();
        print "Current Process Id:".POSIX::getpid()."\n";
        my $pid = fork();

        if($pid){
                close($new_socket);
                next;
        }

        print "Child Process Id:".POSIX::getpid()."\n";

        my $fd = fileno($new_socket);
        print "File Number:$fd\n";

        # Create a conenction with Event socket library.
        $conn = new ESL::ESLconnection($fd);

        # Getting the connection informations and values of the variables.
        my $info = $conn->getInfo();

        # Getting the caller id and print the statement.
        my $caller_id =$info->getHeader("caller-caller-id-number");
        printf  "Connected from %s\n", $caller_id;

        # Receive the events from only in this switch.
        $conn->sendRecv("myevents");

        # Answer the call.
        $conn->execute("answer");

        # playback the welcome message.
        $conn->setEventLock("true");

$conn->execute("playback",$sound_path."ivr/ivr-welcome_to_freeswitch.wav");
        $conn->execute("sleep", "1000");

        &play;


        alarm(10);
        while($conn->connected()){

                # Receive the event
                my $event = $conn->recvEvent();

                # Check the event is received
                if($event){
                        # Get the event name  and print it.
                        my $name = $event->getHeader("event-name");
                        print "EVENT:[$name]\n";

                        # If the event name is DTMF then print the  enterted
digit.
                        if($name eq 'DTMF'){
                                my $digi = $event->getHeader("dtmf-digit");
                                # Here concatenate the eneterd digits
                                $digit.=$digi;
                        }
                }
        }
        # Kill the child process.
        print "Disconnected:$caller_id\n"; kill 9,POSIX::getpid();
}


My dial plan is,
<!-- Testing IVR -->
    <extension name="Test">
      <condition field="destination_number" expression="^(200)$">
            <action application="socket" data="192.168.1.222:5057 async
full"/>
      </condition>
    </extension>

The output of the Script is,

Current Process Id:2906
Child Process Id:2908
File Number:4
Connected from 1000
EVENT:[CHANNEL_EXECUTE]
EVENT:[CHANNEL_ANSWER]
EVENT:[CHANNEL_EXECUTE_COMPLETE]
EVENT:[CHANNEL_EXECUTE]
EVENT:[CHANNEL_EXECUTE_COMPLETE]
EVENT:[CHANNEL_EXECUTE]
EVENT:[CHANNEL_EXECUTE_COMPLETE]
EVENT:[CHANNEL_EXECUTE]
EVENT:[CHANNEL_EXECUTE_COMPLETE]
EVENT:[CHANNEL_EXECUTE]
EVENT:[CHANNEL_EXECUTE_COMPLETE]
EVENT:[DTMF]
EVENT:[DTMF]
EVENT:[DTMF]
EVENT:[DTMF]
IN Sigalarm---
In Play Digit....
Eneterd Digits=7485
Disconnected:1000

When alarm signal generated, it prints digits but it won't execute the
"execute" function..

Please  any one give suggestions where I made wrong...

Thanks...

Regards,
Velusamy.


On Thu, Aug 6, 2009 at 11:24 AM, Michael Collins <msc at freeswitch.org> wrote:

>
>
> On Wed, Aug 5, 2009 at 11:38 PM, velusamy velu <velu.technical at gmail.com>wrote:
>
>> Please any one help for this problem..
>>
>>
> Sorry for the delay but many of the FreeSWITCH experts are at ClueCon right
> now so we'll ask for your patience... in the meantime could you pastebin
> your script and your dialplan entry so that we can take a look at them?
>
> Thanks,
> MC
>
> _______________________________________________
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20090807/7d62b5d3/attachment.html 


More information about the FreeSWITCH-users mailing list