login | register
Sat 19 of Jul, 2008 [23:26 UTC]

voip-info.org

Discuss [8] History

Asterisk tips 911

Created by: oej,Last modification on Fri 27 of Jun, 2008 [00:14 UTC] by birdwes

Priority for emergency calls

This extension for 911 tries to dial out. If no channel is available on the Zap interface, one call is terminated, we wait one second and then dial out on the line.

exten => 911,1,ChanIsAvail(Zap/1)
exten => 911,2,Dial(Zap/1/911)
exten => 911,3,Hangup()
exten => 911,102,SoftHangup(Zap/1-1)
exten => 911,103,Wait(1)
exten => 911,104,Goto(1)


However, you don't want to hang up a call that is an emergency call! Thus the only thing I would add is a variable to set for emergency call already on the channel. That way before you do the disconnect you can check to see if it is already an emergency call.

Try this variation (untested):
[globals]
EMERGENCY=0
LINEOUT=Zap/1
exten => 911,1,ChanIsAvail(${LINEOUT})
exten => 911,2,SetGlobalVar(EMERGENCY=1)
exten => 911,3,Dial(${LINEOUT}/911)
exten => 911,4,SetGlobalVar(EMERGENCY=0)
exten => 911,5,Hangup
exten => 911,102,GotoIf($[${EMERGENCY} = 1]?999)
exten => 911,103,SoftHangup(${LINEOUT}-1)
exten => 911,104,Wait(1)
exten => 911,105,Goto(1)
exten => 911,999,Congestion()

  • If you want to give the user a chance to hangup, play a message and wait for a couple of seconds before connecting to the 911 emergency service.
  • For most of Europe, replace 911 with 112. Also in the UK, 999 is usually dialed (911 does not work). Australia uses 000, Mexico 080 and Pakistan 15.

Contributed by Brian Schrok

Another variation:



The untested example above has several problems.

  1. The EMERGENCY variable is never set to zero (the context ends after the call is completed; priority 911,4 is never reached) Which means it can only grab a line once!
  2. The Dial command might jump to 105 if (a) the 911 callcenter is busy, or (b) the outbound trunk has become busy again, which may not be what you want
  3. There are race conditions which cannot be solved without writing a "smash and grab" application within Asterisk (the example below does not solve that)
  4. The Wait(1) should be long enough for a digital trunk (and in fact should be unnecessary with a digital trunk) ... but with an analog trunk it may not be long enough. In my situation I found that nothing under 12 seconds worked. The only way to know is to test.
  5. Never, *EVER* set up an emergency calling context that you haven't tested with every possible scenario.

Here is a context that I tested and debugged quite a bit. It is ugly, even more complicated and even more difficult to understand. In general I prefer the KISS principle (Keep it Simple, Stupid!) and I think that's particulary important for emergency calls... But anyway, here it is. Be sure to test it (not with a real 911 callcenter!) before you use it.

[globals]
EMERGENCY=0
EMERGENCY_TRUNK=Zap/17
; Change this for production use:
EMERGENCY_NUM=some_test_phone_number

[nineoneone]
exten => s,1,SetVar(SET_EMERG_FLAG=0)
exten => s,n(checkavail),ChanIsAvail(${EMERGENCY_TRUNK})
exten => s,n,SetGlobalVar(EMERGENCY=1)
exten => s,n,SetVar(SET_EMERG_FLAG=1)
exten => s,n(dial),Dial(${EMERGENCY_TRUNK}/${EMERGENCY_NUM})
exten => s,s+2(trunkbusy),GotoIf($[${EMERGENCY} = 1]?inprogress)
exten => s,n,SoftHangup(${EMERGENCY_TRUNK}-1)
exten => s,n,Wait(12)
exten => s,n,Goto(checkavail)
exten => s,s+2(inprogress),Congestion
exten => s,checkavail+101(notavail),Goto(trunkbusy)
exten => h,1,GotoIf($[${SET_EMERG_FLAG} = 1]?3)
exten => h,3,SetGlobalVar(EMERGENCY=0)


[your_main_context]
exten => 911,1,Goto(nineoneone,s,1)
...etc...

-- Added by Bicster, 27 October 2004



Edited by Christian Hoffmeyer 14January2004

See Also


Asterisk | Asterisk Configuration | The Dialplan - extensions.conf

Comments

Comments Filter
222

333Without priority jumps

by pmrtvcom, Monday 02 of July, 2007 [19:24:32 UTC]
A version of this last routine rewritten to avoid priority jumps:<p>
[globals]
;Set this to the appropriate port for your setup
EMERGENCY_TRUNK=Zap/4
EMERGENCY=0
;Set this appropriately - this works fine in UK but don't use it when testing
EMERGENCY_NUM=112

[emergency]
exten => s,1,ExecIf($[${EMERGENCY}=1],Congestion)
exten => s,n,Set(EMERGENCY=1,g)
exten => s,n,Set(SET_EMERG_FLAG=1)
exten => s,n(dial),Dial(${EMERGENCY_TRUNK}/${EMERGENCY_NUM})
exten => s,n,GotoIf($["${DIALSTATUS}"="CHANUNAVAIL"]?hangup)
exten => s,n+1(hangup),SoftHangup(${EMERGENCY_TRUNK}-1)
exten => s,n,Wait(12)
exten => s,n,Goto(dial)
exten => h,1,ExecIf($[${SET_EMERG_FLAG}=1],Set,EMERGENCY=0,g)

[allow-emergency]
;include this context in that of all phones that are allowed to make emergency calls
;remember, these numbers are for UK - please adjust accordingly
exten => _112!,1,Goto(emergency,s,1)
exten => _999!,1,Goto(emergency,s,1)

222

333Without priority jumps

by pmrtvcom, Monday 02 of July, 2007 [19:21:55 UTC]
A version of this last routine rewritten to avoid priority jumps:<p>
globals<br>
;Set this to the appropriate port for your setup<br>
EMERGENCY_TRUNK=Zap/4<br>
EMERGENCY=0<br>
;Set this appropriately - this works fine in UK but don't use it when testing<br>
EMERGENCY_NUM=112<p>
emergency<br>
exten => s,1,ExecIf($${EMERGENCY}=1,Congestion)<br>
exten => s,n,Set(EMERGENCY=1,g)<br>
exten => s,n,Set(SET_EMERG_FLAG=1)<br>
exten => s,n(dial),Dial(${EMERGENCY_TRUNK}/${EMERGENCY_NUM})<br>
exten => s,n,GotoIf($"${DIALSTATUS}"="CHANUNAVAIL"?hangup)<br>
exten => s,n+1(hangup),SoftHangup(${EMERGENCY_TRUNK}-1)<br>
exten => s,n,Wait(12)<br>
exten => s,n,Goto(dial)<br>
exten => h,1,ExecIf($${SET_EMERG_FLAG}=1,Set,EMERGENCY=0,g)<p>
allow-emergency<br>
;include this context in that of all phones that are allowed to make emergency calls<br>
;remember, these numbers are for UK - please adjust accordingly<br>
exten => _112!,1,Goto(emergency,s,1)<br>
exten => _999!,1,Goto(emergency,s,1)<br>

222

333Re: Re: Re: What is n(checkavail)?

by dwarf, Wednesday 12 of April, 2006 [14:13:07 UTC]
What is the advantage of using the priority "s+2" which corresponds to "n+1" instead of just using "n" in the lines:
: exten => s,s+2(trunkbusy),GotoIf($${EMERGENCY} = 1?inprogress)
: exten => s,s+2(inprogress),Congestion

Any real reason to do so apart from possibly making it clearer from the script-maker point of view?
222

333Blocking 911 from Extenal Extensions

by mullinix, Friday 16 of December, 2005 [23:31:57 UTC]
I run Asterisk@Home with about 4, off-premises SIP extensions. I needed a way to prohibit these extensions from dialing 911, and courteously remind the caller to use their PSTN phone. I created a context in the extensions.conf file called "from-wan" as follows:

from-wan
;deny access to 911 for extensions outside of the house
;added by John Mullinix
exten => 911,1,answer
exten => 911,2,Playback(no-911-2)
exten => 911,3,AGI(festival-script.pl|Please use your land based phone to call 9 1 1.)
exten => 911,4,Congestion
exten => 911,5,Hangup
include => from-internal

This short section of code intercepts the 911 call and informs the caller to use their land based phone to call. It allows all other calls to be handled by the "from-internal" context.
222

333Re: Re: Re: What is n(checkavail)?

by peletiah, Monday 07 of November, 2005 [16:56:49 UTC]
nope, this is the "n"-priority, see http://www.voip-info.org/wiki/index.php?page=Asterisk+priorities
222

333Re: Re: What is n(checkavail)?

by wt, Monday 16 of May, 2005 [05:28:03 UTC]
I am guessing that the n needs to be replaced with a number for the priority?
222

333Re: What is n(checkavail)?

by DynamicBits, Wednesday 16 of March, 2005 [20:33:59 UTC]
The word in parentheses is a label that can be referred to in a GoTo statement. In the third example, this line:
: exten => s,n,Goto(checkavail)
will jump to this line:
: exten => s,n(checkavail),ChanIsAvail(${EMERGENCY_TRUNK})
222

333What is n(checkavail)?

by , Tuesday 21 of December, 2004 [09:25:29 UTC]
Hi,

Can you please explain what is n(checkavail) or s+2(inprogress).
I couldn't find any info on that.

Regards