Monday, September 21, 2015

Configuring sms gateway with gammu and Kalkun on Ubuntu 14.04

Hello everyone, in this lab am going to show you how to install and configure sms gateway using gammu and Kalkun. An SMS gateway allows a computer to send or receive Short Message Service (SMS) transmissions to or from a telecommunications network.

Lab requirements
Hardware:
-A computer installed with Operating system, you can install windows, Mac or Linux operating systems, am using Ubuntu 14.04
--Modem with is supported by gammu, see supported modems here.Am using zte MF 190 in my lab.

Software:
-Gammu
    An open source program for communicating with mobile phones.It is command line sms gateway utility which allows to use all libGammu features.

-Kalkun
  Kalkun is open source web-based SMS (Short Message Service) management, it use gammu-smsd (part of gammu family) as SMS gateway engine to deliver and retrieve messages from your phone/modem.


Procedures
The lab consist two main steps
-Gammu installation
-Kalkun installation


********************
1. Gammu installation
********************

Prepare your machine
 As this is new installed Linux server, you should run the following command to prepare your server for gammu installation

sudo apt-get  update
sudo apt-get  upgrade

Install Gammu
sudo apt-get install gammu gammu-smsd

Now connect you modem and check is it is detected by running the following command

dmesg | grep tty

Output
sudo dmesg | grep tty
[    0.000000] console [tty0] enabled
[    0.827573] 00:04: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[  203.063947] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
[  203.064281] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
[  203.064416] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2

Now configure gammu, create gammrc file and add the the following

sudo vim /root/.gammurc

The file should look like

[gammu]

port = /dev/ttyUSB2
model =
connection=at115200
synchronizetime = yes
logfile = /var/log/smsdlog
logformat = nothing
use_locking =
gammuloc =

Note:
port: /dev/ttyUSB* (depends on your usb modem attached port)

Test the connection between gammu and modem by running one of the following command

a. get modem identify

sudo gammu --identify

Device               : /dev/ttyUSB2
Manufacturer         : ZTE CORPORATION
Model                : unknown (MF190)
Firmware             : BD_MF190V1.0.0B24
IMEI                 : 865720018986973
SIM IMSI             : 640045000066980

b. Send a test sms

$ sudo su
# echo "This is just a test sms" | gammu --sendsms TEXT +25571588XXXX

If you want break, press Ctrl+C...
Sending SMS 1/1....waiting for network answer..OK, message reference=16


If everything is working fine and you are able to send sms via command move to step 2 now


**********************
2. Kalkun installation
**********************

-Since Kalkun is web based sms management service, we will install LAMP (apache as website, mysql database and php) as pre-requisity

To install LAMP,use the following command

sudo apt-get install lamp-server^

or

sudo tasksel

Then select [ * ] LAMP Server, It will install all package that needed for LAMP Stack

Now configure your database

a. Create database for sms, am going to call it sms

mysql -u root -p
create database sms;


b. Import data structure for gammu into sms database

#cd /usr/share/doc/gammu/examples/sql
# ls
mysql.sql.gz  pgsql.sql.gz  sqlite.sql.gz

# gunzip mysql.sql.gz
# ls
mysql.sql  pgsql.sql.gz  sqlite.sql.gz

# mysql -u root -p sms < mysql.sql

Check if the schema is imported

# mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.5.44-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sms                |
+--------------------+
4 rows in set (0.00 sec)

mysql>
mysql> use sms

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables;
 
+------------------+
| Tables_in_sms    |
+------------------+
| daemons          |
| gammu            |
| inbox            |
| outbox           |
| outbox_multipart |
| pbk              |
| pbk_groups       |
| phones           |
| sentitems        |
+------------------+
9 rows in set (0.00 sec)

mysql>


-Configure sms daemon

# vi /etc/gammu-smsdrc

The file should look something like

# Configuration file for Gammu SMS Daemon

# Gammu library configuration, see gammurc(5)
[gammu]
# Please configure this!
port = /dev/ttyUSB2
connection=at115200
# Debugging
#logformat = textall

# SMSD configuration, see gammu-smsdrc(5)
[smsd]
service = sql
logfile = /var/log/smsdlog
# Increase for debugging information
debuglevel = 0

# Paths where messages are stored
inboxpath = /var/spool/gammu/inbox/
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/
errorsmspath = /var/spool/gammu/error/

#mysql connnection
Driver=native_mysql
User=root
Password= [Your mysql dababase password here]
PC=Localhost
Database=sms


Close and save the file.
-Run the service
# /etc/init.d/gammu-smsd start


-Check the service
#tail -f /var/log/smsdlog

b. Now download and install Kalkun
Download and extract the latest source code to your web root folder.

# cd /var/www/html
# mkdir sms
#cd sms

# wget http://downloads.sourceforge.net/project/kalkun/kalkun/0.7.1/kalkun_0.7.1.zip

#unzip kalkun_0.7.1.zip

open vim application/config/database.php and insert your mysql info, as below

$db['default']['hostname'] = "localhost";

// MySQL
$db['default']['username'] = "root";
$db['default']['password'] = "[your password here]";
$db['default']['database'] = "sms";
$db['default']['dbdriver'] = "mysql";


Change the ownership of sms folder to be accessible by apache user

#chown -R www-data:root /var/www/html/sms

Now restart apache

# /etc/init.d/apache2 restart

Now go to your browser http://<server IP>/sms/ and continue with installation, see below



When install is success rename or remove the install folder

Rename by the following command

# mv install/ install.bk

Finalize your installation by doing the following

a. -Open vim /etc/gammu-smsdrc and add the following line

runonreceive = /var/www/html/sms/scripts/daemon.sh

b.Edit the daemon file and its daemon.php in /scripts folder

#vim /var/www/html/sms/scripts/daemon.sh
and change to 

DAEMON=/var/www/html/sms/scripts/daemon.php

c. Add your url in your daemon.php file

#vim /var/www/html/sms/scripts/daemon.php

change the following line as below

$url = "http://localhost/sms";

Now your are good, stop and start smsd service

#/etc/init.d/gammu-smsd stop
#/etc/init.d/gammu-smsd start

Good to your browser on
http://<server ip>/sms

username is kalkun and password is kalkun.



Enjoy!!
Drop comments if you face any problems.


3 comments:

  1. Thanks for sharing!!!
    Now Send billions of SMS per second- anytime anywhere from MSGCLUB Bulk sms gateway and APIhttp://www.msgclub.net/

    ReplyDelete
  2. Hello Shivangi,thanks for the feedback, are you SMS prices affordable?

    ReplyDelete