AsteriskThailand
February 08, 2012, 01:22:36 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: AGI: set_variable  (Read 1234 times)
Patrickz
Global Moderator
Sr. Member
*****
Posts: 274


View Profile WWW
« on: October 30, 2007, 10:59:20 AM »

สวัสดีครับ  ผมใช้ AGI เพื่อกำหนดค่าต่างๆ เอาไว้ และต้องการใช้งานเมื่อมีการวางหู ดังนี้ครับ

คำสั่งใน AGI  $agi->set_variable("MyVar","This is myVar");
คำสั่งใน DialPlans exten => s,1,system(echo MyVar:${MyVar}" >> /var/log/asterisk/incomming-calls)

คำสังใน AGI นั้นกำหนดค่าได้ครับ (return เป็น true และสามารถ get variable ออกมาได้)
ผมลองใช้ AccountCode ($agi->exec_setaccountcode("MyAccountID")) พบว่าทำงานได้ตามปกติ

ส่วน MyVar ถูกเรียกใน DialPlans  กลับไม่มีค่า หรือตัวแปรหายไป??

สาเหตุเกิดจากอะไรครับ? ผมใช้ผิดที่ผิดทางหรือเปล่า?



« Last Edit: October 30, 2007, 11:33:53 AM by Patrickz » Logged

Patrickz
Global Moderator
Sr. Member
*****
Posts: 274


View Profile WWW
« Reply #1 on: October 30, 2007, 11:30:20 AM »

ผมดูจาก irclog2html for #asterisk on 20051116
มีคำแนะนำว่า ให้ใช้ $AGI->exec('Set',"LCRSTRING$count=$dialstring"); แทน
(SetVar = 1.0, Set = 1.2)

ผมลองดูแล้วครับ ยังเหมือนเดิมครับ กำหนดค่าได้ แต่พอเอามาเรียกใช้ไม่ได้  หรือเพราะว่ามันอยู่คนล่ะ context กัน??
Logged

Patrickz
Global Moderator
Sr. Member
*****
Posts: 274


View Profile WWW
« Reply #2 on: October 30, 2007, 11:50:45 AM »

 Smiley  ได้แล้วครับ บังเอิญเห็นใน Application command ใน CLI

asterisk1*CLI> show application Set
asterisk1*CLI>
  -= Info about application 'Set' =-

[Synopsis]
Set channel variable(s) or function value(s)

[Description]
  Set(name1=value1|name2=value2|..[|options])
This function can be used to set the value of channel variables or dialplan
functions. It will accept up to 24 name/value pairs. When setting variables,
if the variable name is prefixed with _, the variable will be inherited into
channels created from the current channel. If the variable name is prefixed
with __, the variable will be inherited into channels created from the current
channel and all children channels.
  Options:
    g - Set variable globally instead of on the channel
        (applies only to variables, not functions)


ผมใช้
$agi->exec("Set","MyVar=MyVar|g"); ครับ

สาเหตุเพราะใช้คนล่ะ context จึงต้องกำหนดให้เป็นตัวแปรแบบ Global
« Last Edit: October 30, 2007, 12:58:35 PM by Patrickz » Logged

Patrickz
Global Moderator
Sr. Member
*****
Posts: 274


View Profile WWW
« Reply #3 on: November 06, 2007, 05:04:34 PM »

พอ update มาเป็น Asterisk 1.2.24 svn rev 79171 คำสั่ง $agi->exec("Set","MyVar=MyVar|g"); ก็ใช้ไม่ได้ครับ
ต้องเปลี่ยนมาใช้ SetGlobalVar() แทน  เช่น

$agi->exec("SetGlobalVar","MyVar=MyVar");

น่าปวดหัวชมัด  Huh
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
SEM | Asterisk | สถานที่ท่องเที่ยว | สัมมนา SEM