Posts

FreePBX multiple time conditions

The easiest way to get multiple time conditions in FreePBX is to daisy chain them. A common scenario is to have a standard time condition for normal opening hours and in addition to that, time conditions for holidays occuring on normal weekdays, like christmas and new year for example.

  • Create one time group for normal opening hours, for example monday to friday 08.00-17.00.
  • Create one time condition for the normal opening hours, using the above time group. If time matches, connect the destination to the open IVR or queue. If time doesn’t match, connect it to a closed IVR or a voice message saying you’re closed. This is going to be the last time condition in the chain.
  • Create time groups for each of the holidays. If time matches, connect the destination to a voice message saying you’re closed. If time condition doesn’t match connect it to the next time condition. Remember, the last time condition in the chain should be the one for normal opening hours.
  • Connect the inbound route to the first time condition in your chain.

Inbound route -> Time condition for holiday 1 -> Time condition for holiday 2 -> Time condition for normal opening hours

Asterisk / FreePBX sip trunk registration problem, Serious Network Trouble

The asterisk log file (/var/log/asterisk/full) shows entries like this:

[Sep  3 04:02:08] ERROR[3984] chan_sip.c: Serious Network Trouble; __sip_xmit returns error for pkt data

Solution: The server had been moved from one public IP-address to another. In Asterisk PBX settings, the fields for both External IP and Bind Address (under Advanced) needed adjustment to the new IP-address. After server reload everything worked normally.

Asterisk no sound from client

I was running an Asterisk server behind NAT without any problems at one location. Due to reoargnization it was moved to a new location and placed behind a pfsense firewall. After a while users reported increasing problems with no sound from the clients.

It turned out running a SIP server behind a pfsense can be problematic. When moving to the SIP server to a white IP-adress (no NAT), protecting it using iptables firewall on the SIP-server, all problems disappeared.

It should be noted that the pfsense firewall was not running the latest version of pfsense so it could be caused by a problem solved in later versions of pfsense. However, for different reasons it was not possible to upgrade pfsense so the solution was to move the SIP-server from behind pfsense.

SIP-client behind NAT disconnects incoming external call after 8-10 seconds

Scenario: a SIP server running Elastix (Asterisk and FreePBX) with SIP-clients behind NAT. Outgoing calls from the clients (which where CounterPath Xten and Siemens Gigaset C530ip, i.e. completely different brands) works well, but incoming calls are disconnected after 8-10 seconds.

Googleing the problem suggests the problem is caused by a SIP REINVITE on the client side, which can’t happen because of NAT. During testing, I discovered that calls between SIP-phones connected to the same SIP PBX worked fine, even between different locations. Only calls that originated externally would be interrupted.

This made me focus on the trunks instead and I found out that the problem indeed was a REINVITE but it occured on the trunk side.

The solution was to add the following lines to the PEER DETAILS and USER DETAILS on the trunk configuration in the SIP server:

directmedia=no
canreinvite=no

Asterisk streaming music-on-hold

In Asterisk it is possible to upload .wav or .mp3 files to be used as music-on-hold (MOH). Another option is to use streaming audio but using a stream from a Shoutcast server requires some hands on.

This is how I did the setup for AsteriskNow 1.7 with FreePBX 2.9.

First of all you will need mpg123 from www.mpg123.de to get the Shoutcast stream from the Shoutcast server.
If you already have gcc on your system you can skip the first step.

yum install gcc
wget http://downloads.sourceforge.net/project/mpg123/mpg123/1.13.4/mpg123-1.13.4.tar.bz2
bunzip2 mpg123-1.13.4.tar.bz2
tar xvf mpg123-1.13.4.tar
cd mpg123-1.13.4
./configure
make
make install

Login to admin of your AsteriskNow / FreePBX server and go to Setup -> Music On Hold. Click on Add Streaming Category. Enter the following: 

Category Name:   radio
Application:     /usr/local/bin/mpg123 -q -s -r 8000 -f 8192 -b 2048 --mono http://192.168.1.2:8000
Optional Format: 
mp3

Most Shoutcast streams are sampled at 44.100 kHz or 22.050 kHz in stereo. In order to use a stream for MOH in Asterisk it must be converted to 8 kHz mono, hence the parameters -r 8000 -f 8192 and –mono.

The IP-address 192.168.1.2 and port 8000 in the example should be replaced by the real ip-adress (or hostname) and the port number of the Shoutcast server you want to stream from.

In order to test the streaming music-on-hold, the easiest way is to set up a dummy extension (extension 446 in this example).
Edit extensions_custom.conf and add the lines below: 

nano -w /etc/asterisk/extensions_custom.conf

exten => 466,1,Answer
exten => 466,2,SetMusicOnHold(radio)
exten => 466,3,MusicOnHold()
exten => 466,4,Hangup

Save it by pressing CTRL-X and respond Y.

Now login to admin of your AsteriskNow / FreePBX server and go to Tools -> Custom Extensions. Click on Add Custom Extension. Enter the following: 

Custom Extension: 466
Description:      radio
Notes

And then click Submit Changes.

Don’t forget to click the orange Submit Configuration Changes in the top of the screen.

If all works as planned you will hear the streaming Shoutcast station when you dial extension 466.