Installing Gammu (SMS Gateway) pada Linux

Gammu adalah sebuah software gratis (open source) yang dapat mengolah dan mengontrol pesan dari modem GSM atau pun HP, sehingga software Gammu bisa digunakan dan diaplikasikan menjadi sms gateway. Daftar telepon dan modem yang didukung oleh Gammu bisa dilihat di database Gammu.

Tahapan-tahapan yang dilakukan sebagai berikut:

1. Sistem operasi linux wajib di install webserver (apache) yang didukung oleh php dan database (mysql). Jika belum diinstall silahkan di install terlebih dahulu ..😀

2. Pasang modem yang akan digunakan ke komputer, di pastikan modem sudah terdetect di mesin linux (serial ataupun usb).

3. Download source Gammu di http://wammu.eu/download/gammu/source/

wget http://nchc.dl.sourceforge.net/project/gammu/gammu/1.30.0/gammu-1.30.0.tar.bz2

4. Setelah selesai download source Gammu, extract source tersebut kemudian lakukan installasi.

tar -jxvf gammu-1.30.0.tar.bz2

cd gammu-1.30.0

./configure

make all

make install

5. Masuk ke direktori docs pada master Gammu dan copy smsdrc dan gammurc ke direktori etc/

cd gammu-1.30.0/docs/config

cp gammurc smsdrc /etc/

6. Edit config file smsdrc dan gammurc yang barusan kita copy

mv /etc/smsdrc /etc/smsdrc_modem1

mcedit /etc/smsdrc_modem1

# This is a sample Gammu SMSD configuration file. It’s required for gammu-smsd,
# see gammu-smsdrc(5) for documentation.

# Gammu configuration, this section is like section “gammu” in “gammurc” file,
# see gammurc(5) for documentation.
[gammu]
device = /dev/ttyS0 # Port yang digunakan modem
#model = 6110
connection = at115200 # Lihat pada telephone dan modem 
#synchronizetime = yes
#logfile = gammulog # this is not used at all in SMSD mode
#logformat = textall
#use_locking = yes
#gammuloc = gammu.us
#startinfo = yes

# When uncomment this section and insert numbers here, smsd will process
# incoming sms only from numbers written here (incoming sms from all other
# numbers will be deleted)
#[include_numbers]
#number1 = 1234

# When uncomment this section and insert numbers here, smsd will process
# incoming sms from all numbers not written here (incoming sms from numbers
# written here will be deleted). This is “black” list.
# Note: after using “include_numbers” section this one will be ignored
#[exclude_numbers]
#number1 = 1234

# General SMSD settings, see gammu-smsdrc(5) for detailed description.
[smsd]
# SMSD service to use, one of FILES, MYSQL, PGSQL, DBI
#service = files
service = sql
driver = native_mysql
# PIN for SIM card
PIN = 1234
# File (or stderr, syslog, eventlog) where information will be logged
logfile = /var/log/gammu/gammu-star.log
# Amount of information being logged, each bit mean one level
debuglevel = 1
# Configuration for using more phones on same database
#phoneid = Line1
# Script to be executed when new message has been received

#runonreceive = /some/script

# Commication frequency settings
commtimeout = 20
sendtimeout = 30
#receivefrequency = 0

#
# gaus insert
maxretries = 2
multiparttimeout = 300

# Phone communication settings
checksecurity = 0

#
# Edited
resetfrequency = 3000

# Delivery report configuration
deliveryreport = no
#deliveryreportdelay = 10

# Ignoring broken SMSC
#skipsmscnumber = +48602123456

# Database backends congfiguration
user = gammu
password = ****
pc = localhost
# pc can also contain port or socket path after colon (eg. localhost:/path/to/socket)
#database = smsd
database = gammu-1.30

# DBI configuration
#driver = sqlite
# driverspath = /usr/lib/dbd/
# Database directory for sqlite
# dbdir = /var/lib/smsd

# Files backend configuration
#inboxpath = /var/spool/sms/inbox/
#outboxpath = /var/spool/sms/outbox/
#sentsmspath = /var/spool/sms/sent/

#errorsmspath = /var/spool/sms/error/
#inboxformat = unicode
#transmitformat = auto
#outboxformat = detail

cp /etc/smsdrc_modem1 /etc/smsdrc_modem2

mcedit /etc/smsdrc_modem2

# This is a sample Gammu SMSD configuration file. It’s required for gammu-smsd,
# see gammu-smsdrc(5) for documentation.

# Gammu configuration, this section is like section “gammu” in “gammurc” file,
# see gammurc(5) for documentation.
[gammu]
device = /dev/ttyUSB0 # Port yang digunakan modem
#model = 6110
connection = at115200 # Lihat pada telephone dan modem 
#synchronizetime = yes
#logfile = gammulog # this is not used at all in SMSD mode
#logformat = textall
#use_locking = yes
#gammuloc = gammu.us
#startinfo = yes

# When uncomment this section and insert numbers here, smsd will process
# incoming sms only from numbers written here (incoming sms from all other
# numbers will be deleted)
#[include_numbers]
#number1 = 1234

# When uncomment this section and insert numbers here, smsd will process
# incoming sms from all numbers not written here (incoming sms from numbers
# written here will be deleted). This is “black” list.
# Note: after using “include_numbers” section this one will be ignored
#[exclude_numbers]
#number1 = 1234

# General SMSD settings, see gammu-smsdrc(5) for detailed description.
[smsd]
# SMSD service to use, one of FILES, MYSQL, PGSQL, DBI
#service = files
service = sql
driver = native_mysql
# PIN for SIM card
PIN = 1234
# File (or stderr, syslog, eventlog) where information will be logged
logfile = /var/log/gammu/gammu-star.log
# Amount of information being logged, each bit mean one level
debuglevel = 1
# Configuration for using more phones on same database
#phoneid = Line1
# Script to be executed when new message has been received

#runonreceive = /some/script

# Commication frequency settings
commtimeout = 20
sendtimeout = 30
#receivefrequency = 0

#
# gaus insert
maxretries = 2
multiparttimeout = 300

# Phone communication settings
checksecurity = 0

#
# Edited
resetfrequency = 3000

# Delivery report configuration
deliveryreport = no
#deliveryreportdelay = 10

# Ignoring broken SMSC
#skipsmscnumber = +48602123456

# Database backends congfiguration
user = gammu
password = ****
pc = localhost
# pc can also contain port or socket path after colon (eg. localhost:/path/to/socket)
#database = smsd
database = gammu-1.30

# DBI configuration
#driver = sqlite
# driverspath = /usr/lib/dbd/
# Database directory for sqlite
# dbdir = /var/lib/smsd

# Files backend configuration
#inboxpath = /var/spool/sms/inbox/
#outboxpath = /var/spool/sms/outbox/
#sentsmspath = /var/spool/sms/sent/

#errorsmspath = /var/spool/sms/error/
#inboxformat = unicode
#transmitformat = auto
#outboxformat = detail

mcedit /etc/gammurc

[gammu]

port = /dev/ttyUSB0 # Port modem jika menggunakan USB
model =
connection = at115200 # Lihat pada telephone dan modem 
synchronizetime = yes
logfile =
logformat = nothing
use_locking =
gammuloc =

[gammu1]
port = /dev/ttyS0 # Port modem jika menggunakan Serial
model =
connection = at115200 # Lihat pada telephone dan modem 
synchronizetime = yes
logfile =
logformat = nothing
use_locking =
gammuloc =

Bisa menggunakan perintah gammu-config pada konsole!

7. Simpan smsdrc (smsdrc_modem1 / smsdrc_modem2) dan gammurc yang sudah kita edit, kemudian lakukan test pada konfigurasi Gammu dengan mengetikkan perintah :

/usr/local/bin/gammu –identify

/usr/local/bin/gammu 1 –identify

8. Jika modem sudah terdekteksi, selanjutnya buat database mysql, masuk ke direktori sql yg ada di source Gammu.

cd gammu-1.30.0/docs/sql

– Membuat databases Gammu;

mysqladmin –u root –p create gammu-1.30-H

– Buat table Gammu dari file mysql.sql;

mysql -u root -p gammu-1.30-H < mysql.sql

9. Periksa kembali config smsdrc untuk setting database yang baru kita buat.

mcedit /etc/smsdrc_modem1

mcedit /etc/smsdrc_modem2

# edit pada bagian :

# Database backends congfiguration
user = gammu    # user yang digunakan
password = *** # password
pc = localhost
# pc can also contain port or socket path after colon (eg. localhost:/path/to/socket)
database = gammu-1.30-H # database yang dibuat

10 . Jalankan perintah pada konsole linux,

# Modem 1

/usr/local/bin/gammu-smsd –config /etc/smsdrc_modem1 –daemon

# Modem 2

/usr/local/bin/gammu-smsd –config /etc/smsdrc_modem2 –daemon

dan jika proses starting gammu pada konsole berhasil, buat script untuk menjalankan gammu sbb:

mcedit /etc/rc.d/rc.gammu1

#!/bin/sh
# System startup script for the gammu sms daemon
#

/usr/local/bin/gammu –identify

sleep 30

gammu=/usr/local/bin/gammu-smsd

do_start () {
echo -n “Starting SMS daemon..”
echo
$gammu –config /etc/smsdrc-modem1 –daemon
}

do_stop () {
echo -n “Shutting down SMS daemon…”
echo
killall gammu-smsd
}

case “$1” in
start)
do_start
;;
restart|reload|force-reload)
do_stop
do_start
;;
stop)
do_stop
;;
*)
echo “Usage: $0 start|stop|restart” >&2
exit 3
;;
esac

mcedit /etc/rc.d/rc.gammu2

#!/bin/sh
# System startup script for the gammu sms daemon
#

/usr/local/bin/gammu 1 –identify

sleep 30

gam=/usr/local/bin/gammu-smsd

do_start () {
echo -n “Starting SMS daemon..”
echo
$gam –config /etc/smsdrc-modem2 –daemon
}

do_stop () {
echo -n “Shutting down SMS daemon…”
echo
killall gammu-smsd
}

case “$1” in
start)
do_start
;;
restart|reload|force-reload)
do_stop
do_start
;;
stop)
do_stop
;;
*)
echo “Usage: $0 start|stop|restart” >&2
exit 3
;;
esac

simpan script diatas kemudian ketikkan perintah sbb:

chmod +x /etc/rc.d/rc.gammu*

masukan perintah untuk menjalankan script di /etc/rc.d/rc.local

/etc/rc.d/rc.gammu1 start

/etc/rc.d/rc.gammu2 start

11. Berikut script PHP sms gateway yang dulu entah dapet’nya dari mana, maap klo gak di cantumkan sumber ..🙂

# Untuk terima / baca sms

mcedit sms.php

<html>
<head>
<title>SMS Center</title>
<meta http-equiv=Refresh content=”30″>
<meta name=”description” content=”SMS” />
<meta name=”keywords” content=”SMS” />

<style type=”text/css”>
body {background-color: #FFFFFF}
h1 {background-color: #FF8000}
h1 {color: #000066}
body
{
background-image:
url(‘sms_logo.jpg’);
background-repeat:
no-repeat;
background-position:
right;
}
</style>
</head>
<font face=”tahoma”>
<body>
<center><h1>SMS CENTER</h1></center>

<a href=”#” onclick=”window.open(‘send-sms.php’, ”, ‘width=300,height=200,toolbar=0,statusbar=0,location=0’);”>Kirim SMS / Balas SMS</a>

<FORM ACTION=sms.php method=”post”>
Search SMS-s by first entered chars:
<INPUT NAME=Char SIZE=20>
<INPUT TYPE=SUBMIT VALUE=”Search”><br/><br/>
</FORM>

<?
function mysql_timestamp_to_human($dt) //mysql timestamp to human readable
{
$yr=strval(substr($dt,0,4)); //year
$mo=strval(substr($dt,4,2)); //month
$da=strval(substr($dt,6,2)); //day
$hr=strval(substr($dt,8,2)); //hour
$mi=strval(substr($dt,10,2)); //minute
//$se=strval(substr($dt,12,2)); //sec

return date(“d M Y H:i”, mktime ($hr,$mi,0,$mo,$da,$yr)).””; //format of displayed date and time
}

mysql_connect(“localhost”, “***”, “***”) or die(mysql_error()); //connect to mysql
mysql_select_db(“gammu-1.30-H”) or die(mysql_error()); //select database
if ($Char!=””) //check if char was inserted
$If = “WHERE TextDecoded LIKE ‘”.AddSlashes($Char).”%'”; //if yes, change variable
else
$If = “”; //or do nothing

$result = mysql_query(“SELECT * FROM inbox $If ORDER BY ReceivingDateTime DESC”); //select data with variable and order it by time and date of the reception

echo “<table border=1>”; //begin creation of table
echo “<tr> <th>TANGGAL </th><th>NO. PENGIRIM</th> <th> MESSAGES</th> </tr>”; //header of the table
while($row = mysql_fetch_array( $result )) { //create variable row
// Print out the contents of each row into a table

echo “<tr><td>”; //begin of row and cell
$d= $row[‘ReceivingDateTime’]; //create variable for function at begin
//echo mysql_timestamp_to_human($d); //paste normal date
echo $row[‘ReceivingDateTime’];
echo “</td><td>”;// end and begin of cell
//echo substr($row[‘SenderNumber’], 0, strlen($row[‘SenderNumber’])-3).”XXX”; //show sender number
echo $row[‘SenderNumber’];
echo “</td><td>”; //end and begin of cell
echo $row[‘TextDecoded’]; //show text of the message
echo “</td></tr>”; //end of the cell and row
}
echo “</table>”; //end of table

?>

<p><B>Backup data SMS ke EXCEL Silahkan klik <a href=”excel.php”>disini!!</a></B></p>

<div style=”position: fixed; bottom: 0; left: 50%;”>Powered by <a href=”https://xf86config.wordpress.com”>xf86config</a></div&gt;

<br><br><br>
</font>
</body>
</html>

# Untuk kirim sms

mcedit send-sms.php

<?php

ob_start();

?>
<html>
<head></head>
<body>

<?php

function getPostVariable( $name ) {
return ( isset( $_POST[ $name ] ) ? trim( urldecode( get_magic_quotes_gpc() ? stripslashes( $_POST[ $name ] ) : $_POST[ $name ] ) ) : null );
}

if ( empty( $_GET[ ‘accepted’ ] ) ) {
if ( empty( $_POST[ ‘submit’ ] ) ) {
?>
<form method=”post”>
Destination: <input type=”text” name=”destination” /><br />
Message: <input type=”text” name=”message” /><br />
<input type=”submit” name=”submit” value=”  Send message  ” />
</form>
<?php
} else {
$destination = getPostVariable( ‘destination’ );
$message = getPostVariable( ‘message’ );
//system( ‘/usr/local/bin/gammu –sendsms EMS ‘ . escapeshellarg( $destination ) . ‘ -text ‘ . escapeshellarg( $message ) ); // try this one
system( sprintf( ‘/usr/local/bin/gammu –sendsms EMS %s -text %s’, escapeshellarg( $destination ), escapeshellarg( $message ) ) );
header( ‘Location: ‘ . $_SERVER[ ‘PHP_SELF’ ] . ‘?accepted=yes’ );
exit();
}
} else {
?>
<p>Your message was accepted.</p>
<?php
}

?>

</body>
</html>
<?php

$output = ob_get_contents();
ob_end_clean();

echo $output;
?>

# Untuk export sms ke microsoft excel

mcedit excel.php

<?php
// Original PHP code by Chirp Internet: http://www.chirp.com.au
// Please acknowledge use of this code by including this header.
function cleanData(&$str)
{
$str = preg_replace(“/\t/”, “\\t”, $str);
$str = preg_replace(“/\r?\n/”, “\\n”, $str);
if(strstr($str, ‘”‘)) $str = ‘”‘ . str_replace(‘”‘, ‘””‘, $str) . ‘”‘;
}

$n = 1;
// menentukan timestamp 1 hari sebelumnya dari tanggal hari ini
$prevN = mktime(0, 0, 0, date(“m”), date(“d”) – $n, date(“Y”) );
// menampilkan tanggal 1 hari sebelumnya dari tanggal hari ini berdasarkan timestamp nya
//echo date(“d-m-Y”, $prevN);
$mtgl = date(“Y-m-d”, $prevN);
//echo $mtgl;
// file name for download
$filename = “Backup_SMS_” . date(“d-m-Y”, $prevN) . “.xls”;
header(“Content-Disposition: attachment; filename=\”$filename\””);
header(“Content-Type: application/vnd.ms-excel”);
$flag = false;
$conn = mysql_connect(“localhost”, “***”, “***”);
mysql_select_db(“gammu-1.30-H”);
//$result = mysql_query(“select * from INBOX where tgl=’$mtgl’ order by ID asc”) or die(‘Query failed!’);
//$result = mysql_query(“SELECT inbox.id, inbox.tgl, inbox.jam, inbox.no_hp, phonebook.nama_lengkap, inbox.isi FROM inbox LEFT JOIN phonebook ON inbox.no_hp=phonebook.no_hp wher
e inbox.tgl=’$mtgl’ order by ID DESC”) or die(‘Query failed!’);
$result = mysql_query(“SELECT * FROM inbox $If ORDER BY ReceivingDateTime DESC”) or die(‘Query failed!’);
while(false !== ($row = mysql_fetch_assoc($result))) {
if(!$flag) {
// display field/column names as first row
echo implode(“\t”, array_keys($row)) . “\n”;
$flag = true;
}
array_walk($row, ‘cleanData’);
echo implode(“\t”, array_values($row)) . “\n”;
}
?>

Selesai ..

About Agus Firdaus

Just me ..

6 responses to “Installing Gammu (SMS Gateway) pada Linux”

  1. POE2NK (@ududmlulu) says :

    ninggalin jejak di sini dulu ahhh ^_^

  2. arief says :

    mas, kenapa ketika menjalankan skrip :

    sudo gammu-smsd –config /etc/smsdrc –daemon

    terjadi error seperti ini

    Log filename is “/var/log/smsdlog”
    gammu-smsd[15472]: No SMSD service configured, please set service to use in configuration file!
    Failed to read config: Service configuration is missing.

    apakah ada yg blm dikonfigurasi? dan bagaimana konfigurasinya?

    mohon bantuannya, thx🙂

    • Agus Firdaus says :

      Modem’nya pake apa ya mas, klo saya pake’nya modem wavecom, satu menggunakan serial dan satunya lagi USB😀

      Coba di lihat dulu pada log message di mesin linux, apakah modem sudah terdetect apa belum mas, dmesg atau pada /var/log/message | /var/log/syslog

      Untuk detect modem menggunakan perintah gammu –identify, tapi sebelumnya setting dulu configurasi gammu’nya, bisa menggunakan perintah gammu-config, dari perintah tersebut menghasilkan gammurc

      berikut contoh gammurc dr mesin slackware saya :

      [gammu]

      port = /dev/ttyUSB0 # Modem 1 menggunakan USB
      model =
      connection = at115200
      synchronizetime = yes
      logfile =
      logformat = nothing
      use_locking =
      gammuloc =

      [gammu1] # Modem 2 menggunakan serial, –identify 1
      port = /dev/ttyS0
      model =
      connection = at115200
      synchronizetime = yes
      logfile =
      logformat = nothing
      use_locking =
      gammuloc =

      Untuk daemon’nya (smsdrc), ada di tulisan ini mas ..

  3. ngunyink says :

    trs jalan nin program ni di mana

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: