How to Connect FreePBX to Yeastar TG Gateway

1. Introduction

The guide provides step-by-step configuration instructions of how to connect TG gateway and FreePBX. The GSM trunk on TG gateway will be extended on FreePBX phone system. With the connection you can achieve:

  1. Make outbound calls from FreePBX via the GSM trunks of TG gateway directly.
  2. Receive calls through GSM trunks of TG gateway at FreePBX.

 

Integration Modes

FreePBX and TG gateway use the Service provider mode to connect with each other.

Firmware version:

In the guide, we tested TG800 and FreePBX.

TG800: 55.18.0.46

FreePBX: 10.13.66

Description:

IP address of FreePBX: 192.168.9.91

IP address of TG800: 192.168.9.95

 

Figure 1 FreePBX and TG800 connect with SPS trunk

 

2. Connect FreePBX to Yeastar TG800

2.1 Create a VoIP Trunk on TG800

Path: Gateway> VoIP Settings> VoIP trunk> Add VoIP Trunk.

Choose “Service Provider” mode, and fill in FreePBX IP address.

Figure 2 Add SIP Trunking in TG800

 

Trunk Type: Service Provider

Type: SIP

Provider Name: FreePBX

Hostname/IP: The IP of the FreePBX, 192.168.9.91

 

After creating SIP Trunking, we can check the status of this trunk, it should be OK(green).

Path: Status> System Status> Trunk Status

Figure 3 Trunks Status on TG800

2.2 Create a VoIP Trunk on FreePBX to TG800

Path: Connectivity> Trunks> Add Trunks> Add SIP (chan_pjsip) Trunk

 

Figure 4 Add VOIP Provider on FreePBX

 

Firgure 5 VoIP trunk on FreePBX

Trunk name: TG800

SIP Server: the IP of the TG800, 192.168.9.95

SIP Server Port: the default port 5060, if you want to change the port, it means the FreePBX provide the port for other devices to register to it

From Domain: the IP of the TG800, 192.168.9.95

Note: it doesn’t matter which type of trunk you need, please feel free to add SIP trunk with other type.

Click “save” and “Apply change”, please check the status of the trunk, it shows “Avail” and “Not in use”

 

Path: Admin> Asterisk CLI> execute command “pjsip show endpoints”

Figure 6 The status of the SIP trunk on FreePBX

2.3 Create an extension in FreePBX

Path: Applications> Extensions> Add Extension> Add New Chan_SIP Extension

 

 Figure 7 the SIP extension on FreePBX

Display Name: The name of the extension. For example: Sharon

Secret: the password of the extension. For example: Pincode300

 

Click “save” and “Apply change”, please check the status of the extension and it will shows OK.

Path: Admin> Asterisk CLI> execute command “sip show peers”

Figure 8 Extension status on FreePBX

 

3. Mobile to IP

In this section, we will configure incoming call to FreePBX.

Figure 9 mobile to IP

 

Step1. Configure “Mobile to IP” Route Settings in TG800.

Path: Gateway> Route Settings > Mobile to IP

 

Figure 10 Create Mobile to IP Route

Simple Mode: No

Route Name: You can name the route whatever you want, to_FreePBX

Call Source: Mobile—GSM1. You can select any GSM line or mobile group. Here we select GSM1 as an example.

Call Destination: SPS-FreePBX. All the calls from GSM1 will be sent to FreePBX via this trunk.

Hotline: 999, you can enter the number as 999 in this field, which is same to DID number on FreePBX

 

Step 2. Configure inbound route on FreePBX.

Path: Connectivity> Inbound Routes> Add Inbound Route

 

Figure 11 Create inbound route on FreePBX

Description: From_TG800

DID Number: 999

Set Destination: Extensions-300 Sharon

 

Step 3. Test a call.

now we can test incoming calls for FreePBX. If you dial the GSM1 number on TG800, the call will be routed to the extension 300 in FreePBX.

 

4. IP to Mobile

In this section, we will configure outbound call for FreePBX extensions.

Figure 12 IP to mobile

Step1. Configure Outbound route on FreePBX.

Path: Connectivity> Outbound routes> Add Outbound Route

Figure 13 Create Outbound Route on FreePBX

Route Name: to_TG800

Prefix: 9

Match pattern: x.

Trunk Sequence for Matched Routes: TG800

 

Step2. Create IP to Mobile on TG800

Path: Gateway->Route Settings->IP to Mobile -> Add IP to Mobile Route

 

Figure 14 Create IP to Mobile Route

Simple Mode: Yes

Route Name: From_FreePBX

Call Source: SPS—FreePBX

Call Destination: Mobile—GSM1

 

Step3. Test a call

After settings, all the calls from FreePBX will be routed to GSM1. We can use extension on FreePBX to make test calls. For example, call 913850614596. Here 9 is the prefix in the outbound route of FreePBX.

 

Have more questions? Submit a request

17 Comments

  • 0
    Avatar

    This is good tutorial as long as the TG and the IPPBX are on the same lan.

    Could you please assist in a config where the IPPBX is on public IP and the TG is on a network behind a nat ?

    This is my case, unfortunately the TG is showing trunk ok whereas the freepbx is showing unavailable

     

    I am obliged to do so as the Openvpn is not working for me. I have a Mikrotik openvpn .

  • 0
    Avatar

    Hi Toufic, thanks for bringing it up. If the freePBX is on public IP and TG is behind a nat, we usually do the settings as below,

    1. Configure "Gateway> VoIP Settings> VoIP trunk> Add VoIP Trunk" on TG with the public IP of freePBX. 

    2. Do port forwarding for your TG gateway, for example, port forward UDP 5060 and 10000-12000 to 192.168.9.95. 

    3. Fill the public IP of TG gateway on SIP trunk page of freePBX.

    For the openVPN the configuration, it is almost the same with the tutorial.

    Please feel free to submit a ticket on our support system https://support.yeastar.com/ if you have further issues. Our aggents will be glad to help you. 

  • 0
    Avatar

    Hi,

    Thank you for the reply. In fact my gateway is in an environment where I have no access to port forwarding and the IP address is either private or dynamic.

    That environment has no restriction for vpn or sip nor even iax.

    As for the Openvpn, could you please share a configuration with Mikrotil routerboard ? That would be the solution but unfortunately I am failing to establish a link.

    Thank you and looking forward to your reply.

     

  • 0
    Avatar

    Hi Toufic, your technical skill is very impressive. I am glad to help but we don`t have the configuration with Mikrotik routerboard, sorry for it. I suggest you to have contact Mikrotik as we consider it as a network issue. I think they may offer you more useful information of the settings on vpn. Thanks. 

  • 0
    Avatar

    Once again your interaction is appreciated.

    The setting on mikrotik has no issue, it is on the Yeastar that I am not able to adapt it.

    If I request support from Mikrotik they will not be able to reply as their provided instructions work for Windows and linux devices.

    https://wiki.mikrotik.com/wiki/OpenVPN

    Probably from your experience with yealink you could figure out a vpn.conf settings.

    Important to note that Openvpn on Mikrotik requires username and password that i could not find in yealink.

    what I did is added a file called auth.cnf with username on first line and password on the second followed by a new line

     

  • 0
    Avatar

    Hi Toufic, I notice that you have already submited the ticket on our support system, our technical support is working hard to reply you asap. Please feel free to share the information with him. Thanks. 

  • 0
    Avatar

    Hello,

    Please, i want to know if u are using GT gateway and freePbx Softswitch what is the best option to provision extensions ip phones, i want to know if static or DHCP?

  • 0
    Avatar

    Hello all,

    I have purchased the TG100 and used Sharon's article above yet i can't make calls from Mobile-to-IP nor from IP-to-mobile!!

     

    Here is what i see on the Asterisk-->CLI of my TG100..

    //-- Asterisk CLI Begins here --//

    -- Accepting overlap call from '01222485090' to 's' on channel 1, span 2
    -- Starting simple switch on 'YSGSM/1-1'
    -- Executing [s@from-gsm1:1] NoOp("YSGSM/1-1", "01222485090") in new stack
    -- Executing [s@from-gsm1:2] Set("YSGSM/1-1", "HasDelimiter=") in new stack
    -- Executing [s@from-gsm1:3] Set("YSGSM/1-1", "CEDNAME=s") in new stack
    -- Executing [s@from-gsm1:4] GotoIf("YSGSM/1-1", "0?5:10") in new stack
    -- Goto (from-gsm1,s,10)
    -- Executing [s@from-gsm1:10] Goto("YSGSM/1-1", "from-gsm1-second,s,1") in new stack
    -- Goto (from-gsm1-second,s,1)
    -- Executing [s@from-gsm1-second:1] Set("YSGSM/1-1", "REALSRCTRUNK=") in new stack
    -- Executing [s@from-gsm1-second:2] Macro("YSGSM/1-1", "Routein_GSM_IP_to_FreePBX,0,s") in new stack
    -- Executing [s@macro-Routein_GSM_IP_to_FreePBX:1] Set("YSGSM/1-1", "CDR(userfield)=MOBILE->IP") in new stack
    -- Executing [s@macro-Routein_GSM_IP_to_FreePBX:2] GotoIf("YSGSM/1-1", "0?Blacklist-Handle,s,1") in new stack
    -- Executing [s@macro-Routein_GSM_IP_to_FreePBX:3] Goto("YSGSM/1-1", "Routeout_GSM_IP_to_FreePBX,999,1") in new stack
    -- Goto (Routeout_GSM_IP_to_FreePBX,999,1)
    == Channel 'YSGSM/1-1' jumping out of macro 'Routein_GSM_IP_to_FreePBX'
    -- Executing [999@Routeout_GSM_IP_to_FreePBX:1] Set("YSGSM/1-1", "ORGINEXTEN=999") in new stack
    -- Executing [999@Routeout_GSM_IP_to_FreePBX:2] Set("YSGSM/1-1", "ORGINCONTEXT=Routeout_GSM_IP_to_FreePBX") in new stack
    -- Executing [999@Routeout_GSM_IP_to_FreePBX:3] NoOp("YSGSM/1-1", "It is not module or trunk group") in new stack
    -- Executing [999@Routeout_GSM_IP_to_FreePBX:4] Macro("YSGSM/1-1", "trunkdial-failover-0.4,1,,999,trunk-sps-FreePBX,") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:1] NoOp("YSGSM/1-1", "do call out") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:2] NoOp("YSGSM/1-1", "BLACKLIST") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:3] GotoIf("YSGSM/1-1", "0?4:5") in new stack
    -- Goto (macro-trunkdial-failover-0.4,s,5)
    -- Executing [s@macro-trunkdial-failover-0.4:5] Set("YSGSM/1-1", "TCOUNT=4") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:6] GotoIf("YSGSM/1-1", "0?7:10") in new stack
    -- Goto (macro-trunkdial-failover-0.4,s,10)
    -- Executing [s@macro-trunkdial-failover-0.4:10] Set("YSGSM/1-1", "BEGINCOUNT=4") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:11] Set("YSGSM/1-1", "OldCallerID=01222485090") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:12] Set("YSGSM/1-1", "OldCallerName=01222485090") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:13] Set("YSGSM/1-1", "TOUCH_MONITOR=01222485090-999") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:14] NoOp("YSGSM/1-1", "") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:15] Set("YSGSM/1-1", "DLSTAT=UNKNOW}") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:16] SetCktCustom("YSGSM/1-1", "sendrpid,no,no") in new stack
    -- Executing [s@macro-trunkdial-failover-0.4:17] GotoIf("YSGSM/1-1", "1>0?1-dial,3") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-dial,3)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:3] GotoIf("YSGSM/1-1", "0?4:19") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-dial,19)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:19] Set("YSGSM/1-1", "SINGAL_TIMEOUT=10000000") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:20] Set("YSGSM/1-1", "SINGAL_TIMEOUT=10000000") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:21] Set("YSGSM/1-1", "SINGAL_TIMEOUT=10000000") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:22] Set("YSGSM/1-1", "TIMEOUT(absolute)=10000000") in new stack
    Channel will hangup at 2011-03-31 16:13:52.437 GMT-2.
    -- Executing [1-dial@macro-trunkdial-failover-0.4:23] GotoIf("YSGSM/1-1", "0?24:29") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-dial,29)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:29] GotoIf("YSGSM/1-1", "0?1-out,1") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:30] GotoIf("YSGSM/1-1", "0?setdod,1:1-dial,31") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-dial,31)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:31] Set("YSGSM/1-1", "CALLERID(name)=01222485090") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:32] Set("YSGSM/1-1", "CALLERID(num)=01222485090") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:33] GotoIf("YSGSM/1-1", "1?1-dial,36") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-dial,36)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:36] Set("YSGSM/1-1", "_SIPSRTP=0") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:37] Set("YSGSM/1-1", "OUTDIALOPT=tTkKWwXx") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:38] Set("YSGSM/1-1", "DIALNUMBER=/999") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:39] GotoIf("YSGSM/1-1", "0?Blacklist-Handle,s,1") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:40] GotoIf("YSGSM/1-1", "0?41:42") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-dial,42)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:42] GotoIf("YSGSM/1-1", "0?43:45") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-dial,45)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:45] Set("YSGSM/1-1", "DIALNUMBER=/999") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:46] Set("YSGSM/1-1", "ACCOUNT_RINGTIME=") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:47] GotoIf("YSGSM/1-1", "0?48:53") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-dial,53)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:53] Dial("YSGSM/1-1", "SIP/trunk-sps-FreePBX/999,,tTkKWwXx") in new stack
    == Using SIP RTP TOS bits 184
    == Using SIP RTP CoS mark 5
    == Using SIP VRTP TOS bits 136
    == Using SIP VRTP CoS mark 4
    -- Called trunk-sps-FreePBX/999


    [2010-12-05 22:27:12] NOTICE[1321]: chan_sip.c:19286 handle_response_invite: Failed to authenticate on INVITE to '"01222485090" <sip:01222485090@192.168.5.150>;tag=as591225fa'

    -- SIP/trunk-sps-FreePBX-00000009 is circuit-busy
    == Everyone is busy/congested at this time (1:0/1/0)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:54] Goto("YSGSM/1-1", "1-CONGESTION,1") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-CONGESTION,1)
    -- Executing [1-CONGESTION@macro-trunkdial-failover-0.4:1] Set("YSGSM/1-1", "DLSTAT=9-CONGESTION") in new stack
    -- Executing [1-CONGESTION@macro-trunkdial-failover-0.4:2] GotoIf("YSGSM/1-1", "0?3:4") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-CONGESTION,4)
    -- Executing [1-CONGESTION@macro-trunkdial-failover-0.4:4] Goto("YSGSM/1-1", "2-dial,1") in new stack
    -- Goto (macro-trunkdial-failover-0.4,2-dial,1)
    -- Executing [2-dial@macro-trunkdial-failover-0.4:1] Set("YSGSM/1-1", "TCOUNT=5") in new stack
    -- Executing [2-dial@macro-trunkdial-failover-0.4:2] Set("YSGSM/1-1", "TCOUNT=4") in new stack
    -- Executing [2-dial@macro-trunkdial-failover-0.4:3] Set("YSGSM/1-1", "CALLERID(num)=01222485090") in new stack
    -- Executing [2-dial@macro-trunkdial-failover-0.4:4] Set("YSGSM/1-1", "CALLERID(name)=01222485090") in new stack
    -- Executing [2-dial@macro-trunkdial-failover-0.4:5] Goto("YSGSM/1-1", "1-dial,1") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-dial,1)
    -- Executing [1-dial@macro-trunkdial-failover-0.4:1] Set("YSGSM/1-1", "=4") in new stack
    -- Executing [1-dial@macro-trunkdial-failover-0.4:2] GotoIf("YSGSM/1-1", "1?1-out,1") in new stack
    -- Goto (macro-trunkdial-failover-0.4,1-out,1)
    -- Executing [1-out@macro-trunkdial-failover-0.4:1] NoOp("YSGSM/1-1", "all-busy-now-try-call-later") in new stack
    -- Executing [1-out@macro-trunkdial-failover-0.4:2] Hangup("YSGSM/1-1", "") in new stack
    == Spawn extension (macro-trunkdial-failover-0.4, 1-out, 2) exited non-zero on 'YSGSM/1-1' in macro 'trunkdial-failover-0.4'
    == Spawn extension (Routeout_GSM_IP_to_FreePBX, 999, 4) exited non-zero on 'YSGSM/1-1'
    -- Executing [h@Routeout_GSM_IP_to_FreePBX:1] Hangup("YSGSM/1-1", "") in new stack
    == Spawn extension (Routeout_GSM_IP_to_FreePBX, h, 1) exited non-zero on 'YSGSM/1-1'
    -- Hungup 'YSGSM/1-1'
    -- Channel 1, span 2 received AOC-E charging 0 units
    hangup return error resend at at line=192 !!!

    //-- Asterisk CLI ENDs here --//

     

    I think the problem is presented in this line! What am i missing here?! 

    I am using a FreePBX for Raspberry if this helps. Any help is appreciated from Yeastar support team.

    [2010-12-05 22:27:12] NOTICE[1321]: chan_sip.c:19286 handle_response_invite: Failed to authenticate on INVITE to '"01222485090" <sip:01222485090@192.168.5.150>;tag=as591225fa'

     

  • 0
    Avatar

    Yes, I think the problem at this line as well. The incoming call (Mobile to IP) was rejected by the FreePBX.

    Did you setup any kind of trunk in FreePBX? Can you try get some CLI logs on Free PBX and post here?

  • 0
    Avatar

    If you have setup SIP trunk and Inbound route correctly in your Free PBX, try check if you can find a setting named "Allow Guest" in FreePBX and see if it helps.

  • 0
    Avatar

    Followed this tutorial with Yeastar TG400 doesnt work .ie i couldnt get the incoming calls to work. ALso the TG400 did not provide any logs so that i could trace where the problem was. The trunk status was ok but when  call the GSM line it could not ring. The call was not also reaching the Freepbx

     

  • 0
    Avatar

    Hi,

    I followed the tutorial config literally and got my TG800 registered with my freepbx server which is a VM in vmware workstation. However, only outgoing call is successful, I still cannot make outgoing call. Also, in the trunk type, there is no service provider type but there is peer type, are they the same ?

    Thanks.

  • 0
    Avatar

    The service provider type is the same as Peer Type. Refer to this:  https://support.yeastar.com/hc/en-us/articles/360020484033-Yeaster-Gateway-SIP-Trunk-Basic-Guide .

     

    You might check if your IPtoMobile route is correctly configured.

    You could understand the route login: https://support.yeastar.com/hc/en-us/articles/222007887 

    Then refer to the typical example: https://support.yeastar.com/hc/en-us/articles/360036348373 

     

  • 1
    Avatar

    There is a mistake in my post. in fact the IP to Mobile call routing is successful. I can call external numbers from internal phones connected to freepbx servers through TG800. The issue is that the incoming calls reach the TG800, I can see the SIM port blinking, I can hear a ringtone, then the call is answered and I can only hear noise for few seconds and the call goes off. the TG800 does not pass the incoming call to the freepbx server. I double checked the mobile to IP setting and it matches exactly what is described in the tutorials.

    Help please I'm stuck for more than one week now.

  • 0
    Avatar

    i have the same problem like Adoum Albechir on my yeastar TG400 please i need help. 

    Thanks

  • 0
    Avatar

    Adoum Albechir are you able to capture an Asterisk log and share it here to see if I or other user can help find the reason.

    https://support.yeastar.com/hc/en-us/articles/217862368-How-to-Capture-Asterisk-CLI-logs-for-Yeastar-Devices 

    Enable the SIP debug with "sip set debug on"

    You can post the log by a google disk or other share method.

  • 0
    Avatar

    i have the same problem on my yeastar TG400 Firmware Version:

    91.3.0.21
    with Freepbx 16
     
    The outgoing call working but the incoming call, not working 
    note:
    I'm using register trunk, not peer trunk because the TG400 doesn't have static IP 
     
     

    please I need help. 

    Thanks

    Edited by yosry elfeky
Please sign in to leave a comment.