Asterisk on Raspberry Pi as GSM gateway


Introduction

Yesterday, I installed chan_dongle for my Asterisk PBX running on Raspberry Pi. chan_dongle is a driver for Asterisk PBX that allows the use of certain Huawei 3G USB dongles as a voice “board” for handling voice, SMS, and USSD. It’s like creating your own single-channel GSM gateway.

Raspberry PI with Huawei 3G dongle

Instructions

Follow these steps to set up chan_dongle:

  1. Obtain a compatible USB modem.
  2. Use DC-Unlocker software to check if the modem has voice function and is not locked.
  3. If needed, unlock the modem by following the unlock instructions and resources.
  4. (Optional) If the DC-Unlocker indicates that the modem has no voice function or you encounter issues during configuration, try upgrading the firmware.
  5. Download Raspberry-asterisk and flash it onto an SD card (at least 4GB in size). Below are the instructions for flashing on macOS:

     # Find your card (in my case, it's disk1)
     mount /dev/disk1
     diskutil unmountDisk /dev/disk1
     sudo dd if=raspbian_wheezy_20120608.img of=/dev/rdisk1 bs=1m
    

Installation

Once you have the flashed SD card, power on the Raspberry Pi and follow these steps:

  1. Upgrade the system by running the command:

     raspbx-upgrade
    
  2. Install the necessary software:

     apt-get install usbutils unzip autoconf automake
    
     # Compile USB-modeswitch
     cd /usr/src/
    
     wget http://www.draisberghof.de/usb_modeswitch/usb-modeswitch-1.2.5.tar.bz2
     wget http://www.draisberghof.de/usb_modeswitch/usb-modeswitch-data-20121109.tar.bz2
    
     tar -jxvf usb-modeswitch-1.2.5.tar.bz2
     tar -jxvf usb-modeswitch-data-20121109.tar.bz2
    
     cd usb-modeswitch-1.2.5
     make all
     make install
    
     cd ../usb-modeswitch-data-20121109
     make install
    
     cd ..
    
  3. Plug in the Huawei USB stick (if already plugged, eject it first) and check the output of the lsusb command:

     lsusb | grep Huawei
    

    The output should resemble:

     Bus 001 Device 005: ID 12d1:140c Huawei Technologies Co., Ltd.
    
  4. Switch the USB-stick to modem mode. Use the values obtained from the previous step (v and p flags) and perform a Google search for your modem model and brand to find the value for the M flag.

     usb_modeswitch -v 0x12d1 -p 0x140c -H -s 5 -M 55534243000000000000000000000011060000000000000000000000000000
    
  5. Download and install chan_dongle:

     wget https://github.com/jstasiak/asterisk-chan-dongle/archive/asterisk11.zip
    
     unzip asterisk11.zip
    
     cd asterisk-chan-dongle-asterisk11/
     aclocal
     autoconf
     automake -a
     ./configure
     make all
     make install
     cp etc/dongle.conf /etc/asterisk/
     cp /etc/extensions.conf /etc/asterisk/extensions-dongle.conf
    
  6. Restart Asterisk PBX and check the modem status:

     asterisk -rx "core restart now"
    
     # Check devices
     asterisk -rx "dongle show devices"
    

    You should see something like this:

     # *CLI> dongle show devices
     # ID           Group State      RSSI Mode Submode Provider Name  Model      Firmware          IMEI             IMSI             Number
     # dongle0      0     Free       2    0    0       Yoigo          E1762      11.126.13.00.00   xxxx yyy  Unknown
     # *CLI>
    

That’s it! You have successfully installed and configured chan_dongle. The next step is to configure your new GSM gateway.

I am still experimenting with this device, but so far, the quality has been good and better than what I experienced with the Portech GSM gateway. The price per port is also more favorable, and it can send and receive SMS and USSD.

Good luck!

If you want to try my system, you can download the latest image here. The flashing instructions are the same as for any Raspberry Pi image: gunzip the .gz file, insert the SD card, and flash it using the Linux DD command. For example, you can refer to this resource for detailed flashing procedures.