Set command not setting variables

Hello World,

I am using the set command in the dialplan to set the value of one of my channel variables. The code is as under:

exten => s,4,Set(pollid=1)

But the problem is that it isn’t setting its value. When i try to NoOp the pollid variable, it shows me a blank string “”. Do i need to declare my channel variable anywhere before setting its value? Or does the Set command declare and assign the value directly to a variable.

I am using this set up on asterisk 1.2.

Ashwini

I think this may be a NoOp issue, i have gotten the same thing.

instead of
NoOp(${pollid})
try
NoOp(Poll id is ${pollid})

and remember that variables are case sensitive!

Hi

NoOp is working upto 1.2.10 as described. Are you sure the the call is still in the same channel. try it with a _ or __ before the varible name.

Hi,
I tried using NoOP(Pollid is ${pollid}) but it gave me the same results. Also i tried making the variables inheritable by prefixing them with _ and __ but no success.

I thing the set command itself is not working. Do i have to declare a channel variable specifically somewhere and then set its value, or does the set command declare and set the value at the same time?

Ashwini

try NoOping it a bunch of times, starting with right after its set… that will show you where it is getting dropped…

Dial() may drop it, but Goto() should keep it I think…

Hi IronHelix,

Below is the code of my dialplan. Do you think anything is wrong with it.

[Poll-1] 
exten => s,1,Answer 
exten => s,2,DigitTimeout,5 
exten => s,3,ResponseTimeout,10 
exten => s,4,Set(pollid=1) 
exten => s,5,Background(/srv/www/htdocs/callmanager/audio/intro) 
exten => s,6,Goto(Poll1-1,s,1) 

[Poll1-1] 
exten => s,1,Background(/srv/www/htdocs/callmanager/audio/ques1) 
exten => 1,1,Set(ques1=1) 
exten => 1,2,Goto(Poll1-2,s,1) 
exten => 2,1,Set(ques1=2) 
exten => 2,2,Goto(Poll1-2,s,1) 
exten => #,1,Set(ques1=3) 
exten => #,2,Goto(Poll1-2,s,1) 
exten => *,1,Goto(Poll1-1,s,1) 

[Poll1-2] 
exten => s,1,Background(/srv/www/htdocs/callmanager/audio/ques2) 
exten => 1,1,Set(ques2=1) 
exten => 1,2,Goto(hangup1,s,1) 
exten => 2,1,Set(ques2=2) 
exten => 2,2,Goto(hangup1,s,1) 
exten => #,1,Set(ques2=3) 
exten => #,2,Goto(hangup1,s,1) 
exten => *,1,Goto(Poll1-2,s,1) 

[hangup1] 
exten => s,1,agi,store.php 
exten => s,2,Background(/srv/www/htdocs/callmanager/audio/outro) 
exten => s,3,Hangup 

I have not put NoOp in that as yet. But am i doing something wrong in the dialplan.

Ashwini

is the problem getting the variable into the store.php? Everything else looks fine…

Try a NoOp just before the AGI… if the variable isnt being correctly passed to the agi script you could always pass them as arguments… shrug

Hi IronHelix,
I also think that the problem is with store.php. I tried NoOp ing just before the call to store.php script and pollid variable was still holding its value. Below is the code of my store.php

#!/usr/bin/php -q
<?php
ob_implicit_flush(true);
set_time_limit(6);
$in = fopen("php://stdin","r");

$stdlog = fopen("/var/log/asterisk/my_agi.log", "w");
// toggle debugging output (more verbose)
 $debug = false;


// Do function definitions before we start the main loop
function read() {
  global $in, $debug;
  $input = str_replace("\n", "", fgets($in, 4096));
  if ($debug) fputs($stdlog, "read: $input\n");
  return $input;
}

function errlog($line) {
  global $err;
  echo "VERBOSE \"$line\"\n";
}

function write($line) {
  global $debug;
  if ($debug) fputs($stdlog, "write: $line\n");
  echo $line."\n";
}


// parse agi headers into array

while ($env=read()) {
  $env = str_replace("\"","",$env);
  $s = split(": ",$env);
  $agi[str_replace("agi_","",$s[0])] = trim($s[1]);
 if (($env == "") || ($env == "\n")) {
     break;
  }
}

$unique_id = $agi[uniqueid];
echo "VERBOSE \"$unique_id\"\n";
write("GET VARIABLE pollid");
$pollid = read();
echo "VERBOSE \"$pollid\"\n";

// clean up file handlers etc.
fclose($in);
fclose($stdlog);
exit;
?>

Am i doing something wrong in this script? I have also pasted a portion of my asterisk CLI output for your reference. You can see that the output shows clearly that the variable pollid is set “result=1” but doesnt give any value after it.

 -- Executing NoOp("SIP/teliax-08179d28", "Poll id is 1") in new stack
    -- Executing AGI("SIP/teliax-08179d28", "store.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/store.php
  store.php: 1157931340.4
  store.php: 200 result=1

Can you think of any possible problem here? If i have to shift to variable passing can you refer me to any url where i can get the info of passing multiple variables and retrieving them in the script.

You have been a great help. I appreciate it.

Ashwini

sadly this is where I become less helpful, I don’t know as much about PHP or agi…

what i can say is that if you do something like

Agi(store.php,${pollid},${question1answer},${question2answer}) etc
asterisk will append the answers as arguments to the php script on the command line…

dunno if that helps you at all tho :frowning:

Hi IronHelix,

I understand what you are trying to say. I will try passing variables as you said. Lets see. Thanks for your help.

Ashwini