Asterisk tips 911

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):

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
~np~exten => 911,102,GotoIf($[${EMERGENCY} = 1]?999)~/np~
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.

; Change this for production use:

exten => s,1,SetVar(SET_EMERG_FLAG=0)
exten => s,n(checkavail),ChanIsAvail(${EMERGENCY_TRUNK})~/np~
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)
~np~exten => h,1,GotoIf($[${SET_EMERG_FLAG} = 1]?3)~/np~
exten => h,3,SetGlobalVar(EMERGENCY=0)

exten => 911,1,Goto(nineoneone,s,1)

-- Added by Bicster, 27 October 2004

Edited by Christian Hoffmeyer 14January2004

I just wanted to update this code. To work with asterisk 1.6, the Set vars has changed (note the Set, instead of setVars and the ,g added instead of setGlobalVar). Here is the code from above modified to work with this.

~np~; Change this for production use:~/np~

exten => s,1,Set(SET_EMERG_FLAG=0)
~np~exten => s,n(checkavail),ChanIsAvail(${EMERGENCY_TRUNK})~/np~
exten => s,n,Set(EMERGENCY=1,g)
exten => s,n,Set(SET_EMERG_FLAG=1)
~np~exten => s,n(dial),Dial(${EMERGENCY_TRUNK}/${EMERGENCY_NUM})~/np~
~np~exten => s,s+2(trunkbusy),GotoIf($[${EMERGENCY} = 1]?inprogress)~/np~
~np~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,Set(EMERGENCY=0,g)

exten => 911,1,Goto(nineoneone,s,1)

Edited by Wesley Render Nov 21/2009

See Also

Asterisk | Asterisk Configuration | The Dialplan - extensions.conf
Created by: oej, Last modification: Thu 04 of Nov, 2010 (03:49 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+