Tag Archives: freeswitch

FreeSWITCH status on LED display using socket connection

It is a simple experiment to show  FreeSWITCH  status on LED display using socket connection. Here is Video :

What You Need

1.Raspberry pi-3

2.MAX-7219 based 8×8 LED Matrix Displays(4.No’s or more).

Those available in kit form and assembled form. And we can purchase through on- line marketing like Amazon etc.

In my case 4 modules are powered from GPIO pins of Raspberry . It is good to use separate power for modules for more than 2 modules.

3.Female to Female connector wires

to connect GPIO pins and MAX7219 LED modules.

Next What to do(installing FreeSWITCH)

1.Prepare SD card and load Raspbian and install FreeSWITCH.  For details


2.Install Display drivers for MAX7219. 

git clone https://github.com/rm-hull/max7219.git
sudo python max7219/setup.py install

3.Do wiring.

(as given below) between GPIO of Raspberry pi and MAX 7219 matrix LED displays.

Pin        Name       Remarks            RPi Pin          RPi Function

1            Vcc          +5V Power              2                        5V0

2            Gnd           Ground                  6                        Gnd

3            DIN            Data In                 19                GPIO 10 (MOSI)

4             CS          Chip Select              24                 GPIO  8 (SPI CS0)

5            CLK           Clock                      23                GPIO 11 (SPI CLK)

4.Run demo program.

Edit matrix_demo.py according to no. of matrix devices used  i.e cascaded= n, in my case n=4.

device = max7219(serial, cascaded=4 or 1, block_orientation=block_orientation).

sudo python max7219/examples/matrix_demo.py

At Last

Use ESL connection between FreeSWITCH and Max7219demo program. For details


Here is my source file.

#!/usr/bin/env python

import string
import sys
import re
import time
import argparse

from optparse import OptionParser
from ESL import *
from luma.led_matrix.device import max7219
from luma.core.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import viewport
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT

def main(argv):


                parser = OptionParser()
                parser.add_option("-a", "--auth", dest="auth", default="ClueCon",
                                                                help="ESL password")
                parser.add_option("-s", "--server", dest="server", default="",
                                                                help="FreeSWITCH server IP address")
                parser.add_option("-p", "--port", dest="port", default="8021",
                                                                help="FreeSWITCH server event socket port")
                parser.add_option("-c", "--command", dest="command", default="status",
                                                                help="command to run, surround mutli word commands in \"\'s")

                (options, args) = parser.parse_args()

                con = ESLconnection(options.server, options.port, options.auth)
        #are we connected?

                if con.connected():
                        #run command

                        e = con.api(options.command)
                        print e.getBody()
                        global data
                        data = e.getBody()

                        print "Not Connected"


                print parser.get_usage()

def demo(n, block_orientation):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation)
    print("Created device")

    # start demo
    msg = data
    show_message(device, msg, fill="white", font=proportional(CP437_FONT))

while 1:
        if __name__ == "__main__":

        if __name__ == "__main__":
            parser = argparse.ArgumentParser(description='matrix_demo arguments',

            parser.add_argument('--cascaded', '-n', type=int, default=4, help='Number of cascaded MAX7219 LED matrices')
            parser.add_argument('--block-orientation', type=int, default=0, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')

            args = parser.parse_args()

                demo(args.cascaded, args.block_orientation)
            except KeyboardInterrupt:




WebRTC provides Real-Time Communications directly from better web browsers and devices without requiring plug-ins such as Adobe Flash nor Silverlight.

FreeSWITCH is a WebRTC gateway because it’s able to accept encrypted media from browsers, convert it, and exchange it with other communication networks  that use different codecs and encryptions, for example, PSTN, mobile carriers, legacy systems, and others. FreeSWITCH can be a gateway between your SIP network and applications and billions of browsers on desktops, tablets, and smartphones.

Configuration :

Look for the following in sofia profile and uncomment them:

    <!--uncomment for sip over websocket support-->
    <!--<param name="ws-binding"  value=":5066"/>-->

    <!--uncomment for sip over secure websocket support-->
    <!-- You need wss.pem in /usr/local/freeswitch/certs for wss -->
    <!--<param name="wss-binding" value=":7443"/>-->

Clients :

How it works :

By default, Sofia will listen on port 7443 for WSS clients. You may want to change this port if you need your clients to traverse very restrictive firewalls. Edit /usr/local/freeswitch/conf/sip-profiles/internal.xml and change the “wss-binding” value to 443. This number, 443, is the HTTPS (SSL) port, and is almost universally open in all firewalls.Remember that if you use port 443 for WSS, you cannot use that same port for HTTPS, so you will need to deploy your secure web server on another machine.

Example :

SIP signaling in JavaScript with SIP.js (WebRTC client)

Let’s carry out the most basic interaction with a web browser audio/video through WebRTC. We’ll start using SIP.js.

A web page will display a click-to-call button, and anyone can click. That call will be answered by our company’s PBX and routed to our employee extension (1000). Our employee will wait on a browser with the “answer” web page open, and will automatically be connected to the incoming call.

call.html :

        <button id="startCall">Start Call</button>
        <button id="endCall">End Call</button>
        <video id="remoteVideo"></video>
        <video id="localVideo" muted="muted" width="128px" height="96px"></video>

<script src="js/sip-0.7.0.min.js"></script>
<script src="call.js"></script>

call.js :

var session;

var endButton = document.getElementById('endCall')
endButton.addEventListener("click", function(){
    alert("Call Ended");
}, false);

var startButton = document.getElementById('startCall');
startButton.addEventListener("click", function(){
    session = userAgent.invite('sip:1000@', options);
    alert("Call Started")
}, false);

var userAgent = new SIP.UA({
    uri: 'sip:1000@',
    wsServers: ['ws://'],
    authorizationUser: '1000',
    password: '1234'

var options = {
    media: {
        constraints: {
            audio: true,
            video: true
        render: {
            remote: document.getElementById('remoteVideo'),
            local: document.getElementById('localVideo')

answer.html :

    <button id="endCall">End Call</button>
    <video id="remoteVideo"></video>
    <video id="localVideo" muted="muted" width="128px" height="96px"></video>

<script src="js/sip-0.7.0.min.js"></script>
<script src="answer.js"></script>

answer.js :

var session;
var endButton = document.getElementById('endCall');
    endButton.addEventListener("click", function () {
        alert("Call Ended");
    }, false);

var userAgent = new SIP.UA({
        uri: 'sip:1000@',
        wsServers: ['ws://'],
        authorizationUser: '1000',
        password: '1234'

userAgent.on('invite', function (ciapalo) {
        session = ciapalo;
            media: {
            constraints: {
            audio: true,
            video: true
            render: {

How it works :

Our employee (the callee, or the person who will answer the call) will sit tight with the answer.html web page open on their browser.

Our customer (the caller, or the person who initiates the communication) will visit the call.html webpage and then click on the Start Call button. This clicking will activate the JavaScript that creates the communication session using the invite method of the user agent, passing as an argument the SIP address of our employee.

use this to see if ws and wss work :

sofia status profile internal

Web-based call control with mod_httapi

The mod_httapi module was built to allow you to make your call control and IVRs dynamic. With it you can generate custom IVRs based on user input. Freeswitch mod_httapi is a simple HTTP POST operation to send various bits of information to a web application for restful way to control freeswitch call flows.

This module provides an HTTP based Telephony API using a standard FreeSWITCH application interface as well as a cached http file format interface.

HTTAPI syntax :-

<document type="text/freeswitch-httapi">

mod_httapi configuration file :-

The mod_httapi configuration file is found in conf/autoload_configs and is named httapi.conf.xml . It contains several settings parameters as well as a profiles section. The example configuration contains a default HTTAPI profile or you may create your own profiles.

Inside the profile tag you will notice a number of param entries. These control things such as default settings for various work actions, permissions control (see the following sections), and the default URL to use for HTTP requests.

Example :-

<action application="httapi "/>

Example :-

You don’t need to answer the call in the dialplan before calling into httapi Both extensions below will make httapi requests to my application:

 <extension name="test">
       <condition field="destination_number" expression="^8191$">
           <action application="httapi" data="{url=http://localhost/simver/FSHttApi/Test}" />
   <extension name="test1">
       <condition field="destination_number" expression="^8192$">
           <action application="answer" />
           <action application="httapi" data="{url=http://localhost/simver/FSHttApi/Test}" />

Below example call from web :-

http://localhost:8080/webapi/originate?user/1000 &bridge

In above example if call is successfully bridge than it give response like :

+OK 0a24779a-bd38-11e6-9b18-63e75558dcda

Permissions :-
With all the control that you have in httapi , sometimes it becomes necessary to little bit with permissions on things such as variables that shouldn’t be changed, or applications and APIs that you don’t want to execute. Permissions tag you’ll find many different permissions that you can enable, with even more fine-grained control over certain aspects of some of them.

Reference link :-


How to build and install FreeSWITCH 1.6 on Debian 8 Jessie

FreeSWITCH is an opensource telephony soft switch created in 2006. As per official wiki  page,

It is a scalable open source cross-platform telephony platform designed to route and interconnect popular communication protocols using audio, video, text or any other form of media.

Sounds good. right ?

We are using Debian for this tutorial as it is very stable & mature linux distribution and FreeSWITCH core developers’ choice-of-distribution .
You can read more about FreeSWITCH on there wiki page.

Now lets cut a crap & start an action, assuming you  already have working Debian 8 OS.

Build & Install FreeSWITCH

There are different ways to install FreeSWITCH. In this tutorial, we will see how to install it from source.

  1. First update your Debian box & install curl & git.
    apt-get update && apt-get install -y curl git
  2. Add FreeSWITCH GPG key to APT sources keyring.
    curl https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -
  3. Add FreeSWITCH repository to APT sources.
    echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list
  4. Once again update your system.
     apt-get update
  5. Now lets first install FreeSWITCH dependencies.
    apt-get install -y --force-yes freeswitch-video-deps-most
  6. Though above step takes care of most of dependencies, few still remains required to compile mod_fsv. So install them as,

     apt-get install -y libyuv-dev libvpx2-dev
  7. Grab source code of FreeSWITCH as follows,
     git config --global pull.rebase true
     cd /usr/src/
     git clone https://freeswitch.org/stash/scm/fs/freeswitch.git freeswitch.git
  8. Now lets compile FreeSWITCH source for version 1.6
    cd freeswitch.git
     git checkout v1.6
     ./bootstrap.sh -j
     ./configure -C
     make && make install
  9. Now lets compile sounds
    make all cd-sounds-install cd-moh-install
  10. Lets create simlinks to required binaries to access them from anywhere.
    ln -s /usr/local/freeswitch/bin/freeswitch /usr/bin/freeswitch
    ln -s /usr/local/freeswitch/bin/fs_cli /usr/bin/fs_cli


Set Owner & Permissions

cd /usr/local
groupadd freeswitch
adduser --disabled-password  --quiet --system --home /usr/local/freeswitch --gecos "FreeSWITCH Voice Platform" --ingroup freeswitch freeswitch
chown -R freeswitch:freeswitch /usr/local/freeswitch/
chmod -R ug=rwX,o= /usr/local/freeswitch/
chmod -R u=rwx,g=rx /usr/local/freeswitch/bin/

Starting FreeSWITCH service on boot automatically

To start FreeSWITCH after each boot automatically we need to set up init script. Init script is script used by init system to manipulate services. Debian 8 is now migrated to systemd init system, we will add systemd unit file.

Copy following content to ‘/lib/systemd/system/freeswitch.service’

After=syslog.target network.target local-fs.target

; service
ExecStart=/usr/local/freeswitch/bin/freeswitch -u freeswitch -g freeswitch -ncwait -nonat -rp
; exec


Now execute following commands in your shell

chmod 750 /lib/systemd/system/freeswitch.service
ln -s /lib/systemd/system/freeswitch.service /etc/systemd/system/freeswitch.service
systemctl daemon-reload
systemctl enable freeswitch.service

Start FreeSWITCH

Now we are all set. Lets start hacking FreeSWITCH.

systemctl start freeswitch.service



  1. If something goes wrong & you try compilation again by ‘make clean’, sometimes you get errors regarding ‘spandsp’. To resolve them try to clean using
    ‘git clean -fdx’. For more info check this ticket – https://freeswitch.org/jira/browse/FS-6405



Are you facing issue of failing calls that are having G729a codec with 488 response? This article tells you how to fix that issue. When using G729 codec in FreeSWITCH if it receives following SDP in INVITE packet, that call is going to fail with 488 Incompatible Destination printing the error message mod_sofia.c:2226 CODEC NEGOTIATION ERROR.  SDP:

o=Sippy 3205873754679187826 0 IN IP4
t=0 0
m=audio 53792 RTP/AVP 18 101
c=IN IP4
a=rtpmap:18 G729a/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15

FreeSWITCH is not the offending party here, but the device that is sending G729 as G729a. The correct encoding name assigned to this codec by IANA is G729 not G729a.

To fix interop quirks like these FreeSWITCH has implemented some options that can be enabled. They are prefixed with NDLB means No Device Left Behind. The particular option that helps us with the current issue is


If you set this option to true in sofia profile as shown below, FreeSWITCH will be more forgiving to devices that are using non standard IANA codec names in SDP.

<param name="NDLB-allow-bad-iananame" value="true"/>

Note:- The situation described in this article has commercial G729 module loaded in FreeSWITCH