Re: [asterisk-users] Non-global variable that follows channel?

2016-11-27 Thread Jonathan H
Thanks. I did a while ago, but I couldn't make it "fit" what I wanted to do.

Maybe with my increase Asterisk knowledge now I'll take another look. Thanks!

On 27 November 2016 at 18:27, Richard Mudgett  wrote:

> Have you looked into ARI [1]?  I think it would be a closer fit to what you
> want to do.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Non-global variable that follows channel?

2016-11-27 Thread Richard Mudgett
On Sun, Nov 27, 2016 at 11:13 AM, Jonathan H  wrote:

> Thanks, Richard - your code does indeed work reliably 100% of the
> time, and thank you for that explanation.
>
> I do think the docs at
> https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Function_SHARED
> could do with more clarification.
>
> BTW, there were a couple of typos in your code, so for anyone who
> wants to copy/paste, here's Richard's code WITH the curly braces  (
> Set(SHARED(sharedVar,MY_CALLER) should be
> Set(SHARED(sharedVar,${MY_CALLER}) )
>
> [svtest1]
> exten => s,1,Answer()
> same => n,Verbose(1,Answered channel:${CHANNEL})
> same => n,Set(__MY_CALLER=${CHANNEL(name)})
> same => n,Dial(Local/s@svtest2,,g)
> same => n,Verbose(1,***In channel:${CHANNEL}
> sharedVar:${SHARED(sharedVar)})
> same => n,Hangup()
>
> [svtest2]
> exten => s,1,NoOp()
> same => n,Set(SHARED(sharedVar,${MY_CALLER})="I have been set in
> svtest2 by ${CHANNEL(name)}")
> same => n,Verbose(1,***In channel:${CHANNEL} sharedVar:
> ${SHARED(sharedVar,Local/s@svtest2)})
> same => n,Answer()
> same => n,Hangup()
>
> Thanks again.
>
> (BTW, looking forward to the day when Asterisk gets some kind of
> asynchronous dialplan application - all this "dialling a local
> channel" is just to get via music on hold so there's not silence while
> a long operation happening, as per
> http://lists.digium.com/pipermail/asterisk-users/2016-November/290384.html
> :) )
>

Have you looked into ARI [1]?  I think it would be a closer fit to what you
want
to do.

Richard

[1] https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=29395573
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Non-global variable that follows channel?

2016-11-27 Thread Jonathan H
Thanks, Richard - your code does indeed work reliably 100% of the
time, and thank you for that explanation.

I do think the docs at
https://wiki.asterisk.org/wiki/display/AST/Asterisk+14+Function_SHARED
could do with more clarification.

BTW, there were a couple of typos in your code, so for anyone who
wants to copy/paste, here's Richard's code WITH the curly braces  (
Set(SHARED(sharedVar,MY_CALLER) should be
Set(SHARED(sharedVar,${MY_CALLER}) )

[svtest1]
exten => s,1,Answer()
same => n,Verbose(1,Answered channel:${CHANNEL})
same => n,Set(__MY_CALLER=${CHANNEL(name)})
same => n,Dial(Local/s@svtest2,,g)
same => n,Verbose(1,***In channel:${CHANNEL} sharedVar:${SHARED(sharedVar)})
same => n,Hangup()

[svtest2]
exten => s,1,NoOp()
same => n,Set(SHARED(sharedVar,${MY_CALLER})="I have been set in
svtest2 by ${CHANNEL(name)}")
same => n,Verbose(1,***In channel:${CHANNEL} sharedVar:
${SHARED(sharedVar,Local/s@svtest2)})
same => n,Answer()
same => n,Hangup()

Thanks again.

(BTW, looking forward to the day when Asterisk gets some kind of
asynchronous dialplan application - all this "dialling a local
channel" is just to get via music on hold so there's not silence while
a long operation happening, as per
http://lists.digium.com/pipermail/asterisk-users/2016-November/290384.html
:) )

On 27 November 2016 at 16:16, Richard Mudgett  wrote:

> [svtest1]
> exten = s,1,NoOp()
> same = n,Answer()
> same = n,Set(__MY_CALLER=${CHANNEL(name)})
> same = n,Dial(Local/s@svtest2,,g)
> same = n,NoOp(Returned SHARED(sharedVar) = '${SHARED(sharedVar)'}
> same = n,Hangup()
>
> [svtest2]
> exten = s,1,NoOp()
> exten = n,Set(SHARED(sharedVar,MY_CALLER)="I have been set in svtest2 by
> ${CHANNEL(name)}")
> exten = n,Answer()
> exten = n,Hangup()

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Non-global variable that follows channel?

2016-11-27 Thread Richard Mudgett
On Sun, Nov 27, 2016 at 8:07 AM, Jonathan H  wrote:

> Thanks, Max.
>
> Yes, of course, you are right, and I am an idiot because I was tired
> and putting underscores before the variable name when I read it back!
> Then I forgot to post the followup email to say I had figured it out.
>
> Now, this SHARED was not something I was aware of, but looked like an
> ideal solution to passing variables BACK from to the parent channel.
>
> However, it does not seem to be very reliable.
>
> Code:
>
> [svtest1]
> exten => s,1,Answer()
> same => n,Verbose(1,Answered channel:${CHANNEL})
> same => n,Dial(Local/s@svtest2,,g)
> same => n,Verbose(1,***In channel:${CHANNEL} sharedVar:
> ${SHARED(sharedVar,Local/s@svtest2)} )
> same => n,Hangup()
>
> [svtest2]
> exten => s,1,NoOp()
> same => n,Set(SHARED(sharedVar,Local/s@svtest2)="I have been set
> in svtest2")
> same => n,Verbose(1,***In channel:${CHANNEL} sharedVar:
> ${SHARED(sharedVar,Local/s@svtest2)})
> same => n,Answer()
> same => n,Hangup()
>

There are a few problems with the way you are trying to use SHARED
here.
1)  Dial with the g option continues in the dialplan when the called channel
hangs up and you are accessing a SHARED variable on the called channel
while it is being destroyed.  Thus it may or may not still exist when you
attempt to access it.
2) You are using local channels.  Remember local channels always come
in pairs.  The local channel name you are using to reference the SHARED
variable is ambiguous.  Not only do you not know which half of a local
channel pair you will get, you may not even get one of the local channels
the Dial created for this call if you have more than one of these calls
happening in parallel.

Executing this CLI command:
CLI> originate local/s@svtest1 application echo

Your dialplan creates this channel chain when Local/s@svtest2 executes
the Answer:

Echo() -- Local/s@svtest1-;1 -- Local/s@svtest1-;2 --
Local/s@svtest2-0001;1 -- Local/s@svtest2-0001;2 -- Answer()

These problems can be avoided if we make a couple of changes.
1) Change which channel maintains the SHARED variables to the calling
channel.
2) Pass the calling channel name to the called channel using variable
inheritance.

[svtest1]
exten = s,1,NoOp()
same = n,Answer()
same = n,Set(__MY_CALLER=${CHANNEL(name)})
same = n,Dial(Local/s@svtest2,,g)
same = n,NoOp(Returned SHARED(sharedVar) = '${SHARED(sharedVar)'}
same = n,Hangup()

[svtest2]
exten = s,1,NoOp()
exten = n,Set(SHARED(sharedVar,MY_CALLER)="I have been set in svtest2 by
${CHANNEL(name)}")
exten = n,Answer()
exten = n,Hangup()

Richard
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Non-global variable that follows channel?

2016-11-27 Thread Jonathan H
Thanks, Max.

Yes, of course, you are right, and I am an idiot because I was tired
and putting underscores before the variable name when I read it back!
Then I forgot to post the followup email to say I had figured it out.

Now, this SHARED was not something I was aware of, but looked like an
ideal solution to passing variables BACK from to the parent channel.

However, it does not seem to be very reliable.

Code:

[svtest1]
exten => s,1,Answer()
same => n,Verbose(1,Answered channel:${CHANNEL})
same => n,Dial(Local/s@svtest2,,g)
same => n,Verbose(1,***In channel:${CHANNEL} sharedVar:
${SHARED(sharedVar,Local/s@svtest2)} )
same => n,Hangup()

[svtest2]
exten => s,1,NoOp()
same => n,Set(SHARED(sharedVar,Local/s@svtest2)="I have been set
in svtest2")
same => n,Verbose(1,***In channel:${CHANNEL} sharedVar:
${SHARED(sharedVar,Local/s@svtest2)})
same => n,Answer()
same => n,Hangup()


Output, 4 times from console, 4 times from a normal PJSIP dialin:

Of the 8 attempts. in only 3 instances the variable survives the
journey back to the parent channel, and seemingly randomly, too.
Am I using it incorrectly?

CLI> originate local/s@svtest1 application echo
 Answered channel:Local/s@svtest1-0027;2
 ***In channel:Local/s@svtest2-0028;2 sharedVar: "I have been set
in svtest2"
 ***In channel:Local/s@svtest1-0027;2 sharedVar:
CLI> originate local/s@svtest1 application echo
 Answered channel:Local/s@svtest1-0029;2
 ***In channel:Local/s@svtest2-002a;2 sharedVar: "I have been set
in svtest2"
 ***In channel:Local/s@svtest1-0029;2 sharedVar:
CLI> originate local/s@svtest1 application echo
 Answered channel:Local/s@svtest1-002b;2
 ***In channel:Local/s@svtest2-002c;2 sharedVar: "I have been set
in svtest2"
 ***In channel:Local/s@svtest1-002b;2 sharedVar: "I have been set
in svtest2"
CLI> originate local/s@svtest1 application echo
 Answered channel:Local/s@svtest1-002d;2
 ***In channel:Local/s@svtest2-002e;2 sharedVar: "I have been set
in svtest2"
 ***In channel:Local/s@svtest1-002d;2 sharedVar:
 Answered channel:PJSIP/6001-0007
 ***In channel:Local/s@svtest2-002f;2 sharedVar: "I have been set
in svtest2"
 ***In channel:PJSIP/6001-0007 sharedVar: "I have been set in svtest2"
 Answered channel:PJSIP/6001-0008
 ***In channel:Local/s@svtest2-0030;2 sharedVar: "I have been set
in svtest2"
 ***In channel:PJSIP/6001-0008 sharedVar:
 Answered channel:PJSIP/6001-0009
 ***In channel:Local/s@svtest2-0031;2 sharedVar: "I have been set
in svtest2"
 ***In channel:PJSIP/6001-0009 sharedVar:
 Answered channel:PJSIP/6001-000a
 ***In channel:Local/s@svtest2-0032;2 sharedVar: "I have been set
in svtest2"
 ***In channel:PJSIP/6001-000a sharedVar: "I have been set in svtest2"

On 27 November 2016 at 11:39, Max Grobecker
 wrote:
> Hi,
>
> is channel variable inheritance working for your setup?
> Passing variables to other channels can normally simply be done by naming the 
> variable with one or two prefixed undersorces
> to make it available to the channel that is created from that one defining 
> the variable.
> But I have no idea if it's getting inherited to Gosub called from a Dial 
> command...
>  -> https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Application_Set
>
> If that is not working for you, you might use the SHARED() variables which 
> are kind of global accessible by the channel ID.
> So you might call your Gosub with only the (unique) reference name of the 
> variables you wish to pass and then call it from your Gosub.
>  -> https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_SHARED
>
>
> Greetings,
>  Max
>
>
> Am 23.11.2016 um 13:06 schrieb Jonathan H:
>> Related to 
>> http://lists.digium.com/pipermail/asterisk-users/2016-November/290384.html,
>> at the moment I'm passing one variable via DIAL.
>>
>> Now I'd like to pass a whole bunch, and my idea was to rather than
>> having a great string of
>>
>> b(synctest3b^setVar^1(something)^2(more things)^3(etc))
>>
>> and then get them with ARG1..ARGn etc, I could bundle the whole lot
>> into a HASH and then unbundle them at the called channel.
>>
>> Passing the HASH as a var isn't working (I wasn't expecting it to!)
>> but is there any other way of doing this, or is it setVar for each
>> one?
>>
>
>
> --
> _
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Check out the new Asterisk community forum at: https://community.asterisk.org/
>
> New to Asterisk? Start here:
>   https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>http://lists.digium.com/mailman/listinfo/asterisk-users

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check 

Re: [asterisk-users] Non-global variable that follows channel?

2016-11-27 Thread Max Grobecker
Hi,

is channel variable inheritance working for your setup?
Passing variables to other channels can normally simply be done by naming the 
variable with one or two prefixed undersorces
to make it available to the channel that is created from that one defining the 
variable.
But I have no idea if it's getting inherited to Gosub called from a Dial 
command...
 -> https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Application_Set

If that is not working for you, you might use the SHARED() variables which are 
kind of global accessible by the channel ID.
So you might call your Gosub with only the (unique) reference name of the 
variables you wish to pass and then call it from your Gosub.
 -> https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_SHARED


Greetings,
 Max


Am 23.11.2016 um 13:06 schrieb Jonathan H:
> Related to 
> http://lists.digium.com/pipermail/asterisk-users/2016-November/290384.html,
> at the moment I'm passing one variable via DIAL.
> 
> Now I'd like to pass a whole bunch, and my idea was to rather than
> having a great string of
> 
> b(synctest3b^setVar^1(something)^2(more things)^3(etc))
> 
> and then get them with ARG1..ARGn etc, I could bundle the whole lot
> into a HASH and then unbundle them at the called channel.
> 
> Passing the HASH as a var isn't working (I wasn't expecting it to!)
> but is there any other way of doing this, or is it setVar for each
> one?
> 



signature.asc
Description: OpenPGP digital signature
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users