Route to a ring group only if on specific analog trunk?

I’m trying to route inbound calls to ring group depending on the analog trunk dialed. Seems like such a simple thing to do.

But I can’t seem to figure out the physical port mapping to inbound routes from the Elastix web admin, which has access to the FreePBX UI, so I can go into FreePBX if need be.

Hardware used for analog trunks and extensions: Sangoma A200 4-port FXO and 4 Port FXS

Essentially, I’m having difficulty figuring out how to separate the analog trunk group (ZAP Channel g0 - Zap Identifier = g0) into individual trunk lines that I can then set specific inbound and outbound rules for.

In addition to the default ‘ZAP Channel g0’ (Zap Identifier = g0), I also added 4 ZAP Trunks
Trunk Name = trunk1
Zap Identifier = 1

Trunk Name = trunk2
Zap Identifier = 2

Trunk Name = trunk3
Zap Identifier = 3

Trunk Name = trunk4
Zap Identifier = 4

I’m not sure if the Zap Identifier maps to the physical port or not. I left the default ‘ZAP Channel g0’, so maybe that overrides these new trunks? Am I supposed to delete this default ZAP group?

Anyway, here’s what I’m trying to do:

Scenario 1: Door Buzzer pressed - generates ring-voltage to Sangoma FXO trunk port #1 (Zap Identifier 1)

  • Rings specific trunk port (trunk1) on Elastix
  • Elastix detects this as a call on trunk1 and routes to ring group x600 to ring all IP phones (The other trunks 2, 3, and 4 go to IVR)
  • All IP Phones ring. First person to answer talks then presses 8 or 9, which opens DoorKing

From the Elastix web UI I can’t seem to detect which trunk line the call comes in on, so I temporarily modified the default Incoming Route with no CallerID to route to x600 just as a test.
This test works - was able to open door gate by pressing ‘9’ after answering call. But now I need to restrict it so it ONLY routes to x600 on trunk1

Scenario 2: Employee dials the DoorKing connected to trunk1 from an IP phone extension
Employee presses a certain line (line 2) on IP phone which picks specific trunkport1, goes off-hook to get 2nd dialtone, and then they can type touch-tone/DTMF digits (i.e. *79) to communicate with DoorKing, which is connected “inline” between the central office dialtone signal and the Elastix PBX. (it acts as a relay mechanism).

Lastly, I need to be able to set number of rings on a specific trunk port (NOT GLOBALLY on all ports) to say 3 rings. How do I do this?

This is my first post, so thanks in advance for the help!

You need the FreePBX module, “DAHDI Channel DIDs” or “ZAP Channel DIDs” depending on which version of FreePBX you are running. It allows you to manually assign DIDs to each of your analog channels so that you can route via DID in inbound routes.

Thanks for the reply.

I do have those modules, however, I’m not using DIDs. I’m using plain old analog lines terminating to Sangoma FXO ports. Surely there must be a way of detecting an incoming call to a physical port number and not rely on DIDs.

Similarly, I need to be able to select a specific FXO physical port for outbound DTMP feature code calling (Scenario 2 in my first post). I was hoping either a specific SIP credentials mapped to say Line 2 could be pressed to initiate a call out a specific analog FXO port. Or perhaps a speed dial with a dialplan that routes it to this specific FXO port.

Is this not possible?

There may be a way to do things the way you describe, but the ‘right’ way is to do it the way I described. I can assure you that it works, the DAHDI Channel DIDs module exists expressly for this (and no other) purpose.

For selecting specific channels on outbound calls, create a DAHDI trunk for each channel, using only the channel number. Then create outbound rules to suit.

Ahhh. Thought ZAP Channel DIDs would only work on DID analog lines. Per your suggestion, I added a Zap Channel 8 (last FXO port) to Zap Channel DIDs as follows:

Channel: 8
Description: DoorKing
DID: 4000

Then went to Inbound Routes:
Description: DoorKing
DID Number: 4000
Caller ID Number:
CID Priority Route: unchecked
Set Destination: Ring Groups - Ring All Phones <600>

But when I dial Zap channel 8, the call goes to ivr-3 - my default “catchall” route when there is NO CallerID or DID assigned,
i.e.
Description: CatchAll
DID Number:
Caller ID Number:
CID Priority Route: unchecked
Set Destination: IVR - MainIVR

I know it’s ringing Zaptel 8-1, which is supposed to use my “DoorKing” route. - here’s a trace:
– Starting simple switch on ‘DAHDI/8-1’
– Executing [s@from-pstn:1] Set(“DAHDI/8-1”, “__FROM_DID=s”) in new stack
– Executing [s@from-pstn:2] Gosub(“DAHDI/8-1”, “app-blacklist-check,s,1”) in new stack
– Executing [s@app-blacklist-check:1] GotoIf(“DAHDI/8-1”, “0?blacklisted”) in new stack
– Executing [s@app-blacklist-check:2] Set(“DAHDI/8-1”, “CALLED_BLACKLIST=1”) in new stack
– Executing [s@app-blacklist-check:3] Return(“DAHDI/8-1”, “”) in new stack
– Executing [s@from-pstn:3] ExecIf(“DAHDI/8-1”, “0 ?Set(CALLERID(name)=5553000)”) in new stack
– Executing [s@from-pstn:4] Set(“DAHDI/8-1”, “__CALLINGPRES_SV=allowed_not_screened”) in new stack
– Executing [s@from-pstn:5] Set(“DAHDI/8-1”, “CALLERPRES()=allowed_not_screened”) in new stack
– Executing [s@from-pstn:6] Goto(“DAHDI/8-1”, “ivr-3,s,1”) in new stack
– Goto (ivr-3,s,1)
– Executing [s@ivr-3:1] Set(“DAHDI/8-1”, “MSG=custom/main-normal-4”) in new stack
– Executing [s@ivr-3:2] Set(“DAHDI/8-1”, “LOOPCOUNT=0”) in new stack
– Executing [s@ivr-3:3] Set(“DAHDI/8-1”, “__DIR-CONTEXT=”) in new stack
– Executing [s@ivr-3:4] Set(“DAHDI/8-1”, “_IVR_CONTEXT_ivr-3=”) in new stack
– Executing [s@ivr-3:5] Set(“DAHDI/8-1”, “_IVR_CONTEXT=ivr-3”) in new stack
– Executing [s@ivr-3:6] GotoIf(“DAHDI/8-1”, “0?begin”) in new stack
– Executing [s@ivr-3:7] Answer(“DAHDI/8-1”, “”) in new stack
– Executing [s@ivr-3:8] Wait(“DAHDI/8-1”, “1”) in new stack
– Executing [s@ivr-3:9] Set(“DAHDI/8-1”, “TIMEOUT(digit)=3”) in new stack
– Digit timeout set to 3.000
– Executing [s@ivr-3:10] Set(“DAHDI/8-1”, “TIMEOUT(response)=20”) in new stack
– Response timeout set to 20.000
– Executing [s@ivr-3:11] Set(“DAHDI/8-1”, “__IVR_RETVM=”) in new stack
– Executing [s@ivr-3:12] ExecIf(“DAHDI/8-1”, “1?Background(custom/main-normal-4)”) in new stack
– <DAHDI/8-1> Playing ‘custom/main-normal-4.slin’ (language ‘en’)
== Spawn extension (ivr-3, s, 12) exited non-zero on ‘DAHDI/8-1’
– Executing [h@ivr-3:1] Hangup(“DAHDI/8-1”, “”) in new stack
== Spawn extension (ivr-3, h, 1) exited non-zero on ‘DAHDI/8-1’
– Hanging up on ‘DAHDI/8-1’
– Hungup ‘DAHDI/8-1’

So why isn’t it DAHDI/8-1 going to my DoorKing Inbound Route rule set to channel 8?

Check the mousover help, the channel(s) must be in a specific context to work with that module.

I see that under Zap Channel DIDs:


"You MUST assign the channel’s context to from-zaptel for these settings to have effect. It will be a line that looks like:

context = from-zaptel

in your zapata.conf configuration effecting the specified channel(s). Once you have assigned DIDs you can use standard Inbound Routes with the specified DIDs to route your calls."


But where do I put “context = from-zaptel”.

I’m confused where this is done.

I do see in extensions_additional.conf it has:
[from-zaptel]
include => from-zaptel-custom
include => from-dahdi
exten => foo,1,Noop(bar)

And this file also has my DID route:
[ext-did-0002]
include => ext-did-0002-custom
exten => fax,1,Goto(${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)})
exten => 4000,1,Set(__FROM_DID=${EXTEN})
exten => 4000,n,Gosub(app-blacklist-check,s,1)
exten => 4000,n,ExecIf($[ “${CALLERID(name)}” = “” ] ?Set(CALLERID(name)=${CALLERID(num)}))
exten => 4000,n,Set(__CALLINGPRES_SV=${CALLERPRES()})
exten => 4000,n,Set(CALLERPRES()=allowed_not_screened)
exten => 4000,n(dest-ext),Goto(ext-group,600,1)

; end of [ext-did-0002]

What am I supposed to do in this file?

Thanks for all your help!

http://lmgtfy.com/?q=elastix+zap+channel+dids

First link should do it.

Thanks lgaetz. After reading the article that’s exactly the answer I was looking for.

I did try googling, searching this forum, searching asterisk forums, as well as pbx-in-a-flash & elastix, which both use FreePBX. Everything about analog routing involved DID or CallerId routing - nothing about physical ports.

I would think there would be tons of discussions on this, since using physical port routing has multiple applications including: multi-tenant, security system, door gate system, etc.

Surprisingly, I couldn’t find anything, but your link was the answer I needed. That article writer apparently struggle for a week, so I don’t feel so bad - “Getting this working with DAHDI in Elastix has been driving me up the wall!
This issue has been bugging me for over a week now and I have finally got it to work.”

Apparently my search criteria wasn’t the right one, so thanks for showing the way.