Develop SMS Gateway with gammu , php, mysql on ubuntu 10.10

Berhubung sudah mau magrib jadi saya  tulis denga gaya  BASBeng saja deh, bagi yang belum tahu SMS gateway, aplikasinya, serta gammu itu apa silahkan googling dulu agar tidak tersesat kemudian. Dalam eksperimen saya menggunakan Sistem Operasi Ubuntu 10.10 untuk membangun aplikasi SMS gateway ini,  sekaligus terinstall aplikasi LAMP (Linux With Apache Mysql Php5). jika requirement sudah lengkap bisa dimulai instalasi gammu ini.

1.  Install dependency aplikasi gammu dan librarynya

root@gigih:sudo apt-get install gammu gammu-smsd libgammu7 libgsmsd7
2. Masukkan Modem USB anda, disini saya menggunakan modem SIERRA At&T buatannya b*ngsat Israel. check dengan perintah berikut apakah modem terdeteksi atau tidak
 root@gigih:/var/www/sms# lsusb & wvdialconf
 [3] 19333
 Editing `/etc/wvdial.conf'.
 Scanning your serial ports for a modem.
 ttyS0<*1>: ATQ0 V1 E1 -- Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 Bus 004 Device 005: ID 1199:6856 Sierra Wireless, Inc. ATT "USB Connect 881"
 Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 Bus 003 Device 002: ID 04b3:3025 IBM Corp.
 Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 failed with 2400 baud, next try: 9600 baud
 ttyS0<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 115200 baud
 ttyS0<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.

Modem Port Scan<*1>: S1   S2   S3
 WvModem<*1>: Cannot get information for serial port.
 ttyUSB0<*1>: ATQ0 V1 E1 -- OK
 ttyUSB0<*1>: ATQ0 V1 E1 Z -- OK
 ttyUSB0<*1>: ATQ0 V1 E1 S0=0 -- OK
 ttyUSB0<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
 ttyUSB0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
 ttyUSB0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
 ttyUSB0<*1>: Modem Identifier: ATI -- MC8781
 ttyUSB0<*1>: Speed 9600: AT -- OK
 ttyUSB0<*1>: Max speed is 9600; that should be safe.
 ttyUSB0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
 WvModem<*1>: Cannot get information for serial port.
 ttyUSB1<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud
 ttyUSB1<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 9600 baud
 ttyUSB1<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.
 WvModem<*1>: Cannot get information for serial port.
 ttyUSB2<*1>: ATQ0 V1 E1 -- OK
 ttyUSB2<*1>: ATQ0 V1 E1 Z -- AT+CPMS="SM","SM"
 ttyUSB2<*1>: ATQ0 V1 E1 S0=0 -- OK
 ttyUSB2<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
 ttyUSB2<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
 ttyUSB2<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
 ttyUSB2<*1>: Modem Identifier: ATI -- ATI
 ttyUSB2<*1>: Speed 9600: AT -- OK
 ttyUSB2<*1>: Modem Identifier: ATI -- Manufacturer: Sierra Wireless, Inc.
 ttyUSB2<*1>: Max speed is 9600; that should be safe.
 ttyUSB2<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
 Found a modem on /dev/ttyUSB0.
 Modem configuration written to /etc/wvdial.conf.
 ttyUSB0<Info>: Speed 9600; init "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
 ttyUSB2<Info>: Speed 9600; init "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
 [3]   Done                    lsusb
 root@gigih:/var/www/sms#

Dari Informasi diatas diketahui bahwa modem sudah terdeteksi dan berada pada port ttysUSB2

Buat configurasi gammu dengan perintah berikut (sesuaikan Port dan Connection)
 root@gigih:/# gammu-config
 ┌───────────────────────
 │ Current Gammu configuration
 │
 │  P Port                 (/dev/ttyUSB2)
 │  C Connection           (at)
 │  M Model                ()
 │  D Synchronize time     (yes)
 │  F Log file             (/etc/gammu)
 │  O Log format           (textall)
 │  L Use locking          ()
 │  G Gammu localisation   ()
 │  H Help
 │  S Save
 │
 │
 │        <Ok>            <Cancel>
 │
 └───────────────────────
root@gigih:/var/www/sms# more /root/.gammurc
# This is a generated gammurc file.
 # It was generated by Gammu configurator 0.4
 # In Unix/Linux  : copy it into your home directory and name it .gammurc
 #                  or into /etc and name it gammurc
 # In Win32       : copy it into directory with Gammu.exe and name gammurc
 # Port           : in Windows/DOS: "com*:",
 #                  (instead of "*" please put "1", "2", etc.)
 #                  in other (Linux/Unix) "/dev/ttyS%"
 #                                     or "/dev/ircomm%" ("irda" connection)
 #                  (instead of "%" please put "0", "1", "2", etc.)
 # Model          : use only, when Gammu doesn't recognize your phone model.
 #                  Put it here. Example values: "6110", "6150", "6210", "8210"
 # Connection     : type of connection. Use "fbus" or "mbus" or "dlr3" or
 #                  "irda" (Infrared over sockets) or "infrared" (DirectIR)
 #                  or "at19200" (AT commands on 19200, 8 bits, None parity,
 #                  1 stop bit, no flow control) or "at115200" (AT commands on
 #                  115200, 8 bits, None parity, 1 stop bit, no flow control)
 #                  or "atblue" (AT over BlueTooth) or "dlr3blue" (FBUS
 #                  over BlueTooth)
 # SynchronizeTime: if you want to set time from computer to phone during
 #                  starting connection. Do not rather use this option when want
 #                  to reset phone during connection (in some phones need to
 #                  set time again after restart)
 # Logfile        : Use, when want to have logfile from communication.
 # Logformat      : What debug info and format should be used:
 #                  "nothing" - no debug level, "text" - transmission dump in
 #                  text format, "textall" - all possible info in text format,
 #                  "errors"  - errors in text format, "binary" - transmission
 #                  dump in binary format
 # Use_Locking    : under Unix/Linux use "yes", if want to lock used device
 #                  to prevent using it by other applications
 # GammuLoc       : name of localisation file
[gammu]
port = /dev/ttyUSB2
 model = 
 connection = at
 synchronizetime = yes
 logfile = /etc/gammu
 logformat = textall
 use_locking = 
 gammuloc =
 root@gigih:/var/www/sms#

Check kembali apakah gammu sudah bisa berkomunikasi dengan modem anda.

root@gigih:/# gammu --identify
 Device               : /dev/ttyUSB2
 Manufacturer         : Sierra Wireless, Inc.
 Model                : unknown (MC8781)
 Firmware             : F1_0_0_4CAP C:/WS/FW/F1_0_0_4CAP/MSM7200R3/SRC/AMSS 2007/09/25 18:39:23
 IMEI                 : 356685013198591
 SIM IMSI             : 510014010262841
 root@gigih:/#
 
root@gigih:/usr/share/doc/gammu/examples/sql# ls mysql.sql  pgsql.sql.gz  sqlite.sql.gz root@gigih:/usr/share/doc/gammu/examples/sql#

Create Database gammu

root@gigih:/usr/share/doc/gammu/examples/sql# mysql -u root -p
 Enter password: 
 Welcome to the MySQL monitor.  Commands end with ; or g.
 Your MySQL connection id is 147
 Server version: 5.1.49-1ubuntu8.1 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
 This software comes with ABSOLUTELY NO WARRANTY. This is free software,
 and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> create database gammu;
 ok
 mysql>
root@gigih:/usr/share/doc/gammu/examples/sql# mysql -u root -p gammu < mysql.sql
 Enter password:
 root@gigih:/usr/share/doc/gammu/examples/sql#
mysql> use gammu;
 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_gammu  |
 +------------------+
 | daemons          |
 | gammu            |
 | inbox            |
 | outbox           |
 | outbox_multipart |
 | pbk              |
 | pbk_groups       |
 | phones           |
 | sentitems        |
 +------------------+
 9 rows in set (0.00 sec)
mysql>
Edit gammu-smsdrc agar bisa tersambung dengan database MYSQL
root@gigih:/# vi /etc/gammu-smsdrc
 port = /dev/ttyUSB2
 connection = at
 startinfo = yes
 # Debugging
 logformat = textall
 # SMSD configuration, see gammu-smsdrc(5)
 [smsd]
 service = mysql    #INGAT JIKA INGIN MENGGUNAKAN MYSQL rubah menjasi MYSQL jika dlm bentuk file menjadi FILES
 logfile = /etc/smsdlog
 # Increase for debugging information
 debuglevel = 255
 user = root     #bagian ini user mysql
 password = 123456789   #Password mysql
 pc = localhost  #Server Mysql
 database = gammu  #Nama Database
 # 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/

Pengujian Send SMS dari Console

root@gigih:/# echo "testing" | gammu --sendsms TEXT 085289774152
 If you want break, press Ctrl+C...
 Sending SMS 1/1....waiting for network answer..OK, message reference=113
 root@gigih:/#
Check log
 root@gigih:# tail -f /etc/smsdlog 
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: gammu: 41A|54T|2B+|43C|4DM|47G|4CL|3D=|344|0D                          AT+CMGL=4.      
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: gammu: 1 "AT+CMGL=4"
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: gammu: 2 "OK"
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: gammu: RECEIVED frametype 0x00/length 0x10/16
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: gammu: 41A|54T|2B+|43C|4DM|47G|4CL|3D=|344|0D |0D |0A |4FO|4BK|0D |0A  AT+CMGL=4...OK..
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: gammu: SMS listing received
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: gammu: Read 0 SMS locations
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: gammu: GSM_GetNextSMS failed with error EMPTY[22]: Entry is empty.
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: gammu: Leaving GSM_GetNextSMS
 Tue 2011/07/19 17:52:04 gammu-smsd[22560]: Execute SQL: UPDATE `phones` SET `TimeOut`= (NOW() + INTERVAL 10 SECOND)+0, `Battery`= 100, `Signal`= 9 WHERE `IMEI` = '356685013198591'
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: Entering GSM_GetSecurityStatus
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: Getting security code status
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: SENDING frametype 0x00/length 0x09/9
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: 41A|54T|2B+|43C|50P|49I|4EN|3F?|0D                              AT+CPIN?.       
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: 1 "AT+CPIN?"
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: 2 "+CPIN: READY"
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: 3 "OK"
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: RECEIVED frametype 0x00/length 0x1F/31
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: 41A|54T|2B+|43C|50P|49I|4EN|3F?|0D |0D |0A |2B+|43C|50P|49I|4EN AT+CPIN?...+CPIN
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: 3A:|20 |52R|45E|41A|44D|59Y|0D |0A |0D |0A |4FO|4BK|0D |0A      : READY....OK.. 
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: Parsing +CPIN: READY with +CPIN: @r
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: Grabbed string from reply: "READY" (parsed 5 bytes)
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: Parsed raw string "READY"
 Tue 2011/07/19 17:52:05 gammu-smsd[22560]: gammu: Security status received - nothing to enter
 ^C
 root@gigih:#

Terakhir buat aplikasi backend PHP untuk eksekusi SMS via WEB menggunakan PHP Script

isi kode  form.php
 <h1>Kirim SMS</h1>
<form method="post" action="send.php">
 Nomor HP Tujuan<br>
 <input type="text" name="nohp"><br><br>
 Isi SMS<br>
 <textarea name="sms"></textarea><br><br>
 Format SMS<br>
 <input type="radio" name="format" value="flash"> Flash SMS <br>
 <input type="radio" name="format" value="normal"> Normal SMS <br><br>
 <input type="submit" name="submit" value="Kirim SMS">
 </form>

isi kode  send.php

<?php
// koneksi ke database Gammu
 mysql_connect("dbhost", "dbuser", "dbpass");
 mysql_select_db("dbname");
// baca no tujuan
 $no_tujuan = $_POST['nohp'];
// baca isi sms
 $isi_sms = $_POST['sms'];
// baca format sms
 $pilih_format = $_POST['format'];
if ($pilih_format == "flash")
 {
 // jika format yang dipilih 'flash'
// query kirim sms format flash
 $query = "INSERT INTO outbox(DestinationNumber, TextDecoded, CreatorID, Class)
 VALUES ('$no_tujuan', '$isi_sms', 'Gammu', '0')";
// jalankan query
 mysql_query($query);
 }
 else if ($pilih_format == "normal")
 {
 // jika format yang dipilih 'normal'
// query kirim sms normal
 $query = "INSERT INTO outbox(DestinationNumber, TextDecoded, CreatorID, Class)
 VALUES ('$no_tujuan', '$isi_sms', 'Gammu', '-1')";
// jalankan query
 mysql_query($query);
 }
 else echo "Anda belum memilih format SMS";
?>

5 thoughts on “Develop SMS Gateway with gammu , php, mysql on ubuntu 10.10”

  1. kok gak mau ngirim ya mas? udah diterapin tetep aja gak masuk ke database

    tapi kalo make terminal terkirim, tapi make php gak terkirim n gak masuk ke database

  2. db user dan password sudah dipastikan bener ???.

    logikanya simple saja form html digunakan sebagai data input untuk di proses oleh program send.php
    send.php akan mengambil data nomer tujuan, isi sms, tipe sms, data ini akan dicopy ke outbox db gammu yg selanjutnya akan diproses secara otomatis oleh gammu daemon untuk dikirimkan,

    Pertanyaan saya apakah gammu sudah dibuat jalan untuk service mysql ??
    pastikan configurasi anda sama dgn contoh berikut;

    admin1@ubuntu:~$ ll /etc/gammu-smsdrc
    -rw-r–r– 1 root root 434 2011-07-27 15:28 /etc/gammu-smsdrc

    admin1@ubuntu:~$ cat /etc/gammu-smsdrc
    # Configuration file for Gammu SMS Daemon

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

    # SMSD configuration, see gammu-smsdrc(5)
    [smsd]
    service = mysql
    logfile = /etc/smsdlog
    # Increase for debugging information
    debuglevel = 255

    # Paths where messages are stored

    user = root
    password = xxx
    database = gammu

    ================================================================================
    contoh log saya ketika sukses membaca sms

    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: Lemlit 1234567
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: Leaving GSM_GetNextSMS
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: Received message from +6285289774152
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: Execute SQL: INSERT INTO `inbox` (`ReceivingDateTime`,`Text`,`SenderNumber`,`Coding`,`SMSCNumber`,`UDH`, `Class`,`TextDecoded`,`RecipientID`) VALUES (‘20110728122354′,’004C0065006D006C0069007400200031003200330034003500360037′,’+6285289774152′,’Default_No_Compression’,’+6281100000′,”,’-1′,’Lemlit 1234567′,”)
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: Inserted message id 22
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: Execute SQL: UPDATE phones SET Received = Received + 1 WHERE IMEI = ‘356685013198591’
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: Entering GSM_DeleteSMS
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: Location = 0, Folder = 0
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: SMS folder 0 & location 0 -> ATGEN folder 1 & location 0
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: Getting SMS
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: SENDING frametype 0x00/length 0x0A/10
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 41A|54T|2B+|43C|4DM|47G|52R|3D=|300|0D AT+CMGR=0.
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 1 “AT+CMGR=0”
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 2 “+CMGR: 1,,33”
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 3 “06912618010000040D91265882794751F20000117082213245820ECC729B9DA68362B219AD66BB01”
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 4 “OK”
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: RECEIVED frametype 0x00/length 0x72/114
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 41A|54T|2B+|43C|4DM|47G|52R|3D=|300|0D |0D |0A |2B+|43C|4DM|47G AT+CMGR=0…+CMG
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 52R|3A:|20 |311|2C,|2C,|333|333|0D |0A |300|366|399|311|322|366 R: 1,,33..069126
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 311|388|300|311|300|300|300|300|300|344|300|44D|399|311|322|366 18010000040D9126
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 355|388|388|322|377|399|344|377|355|311|46F|322|300|300|300|300 5882794751F20000
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 311|311|377|300|388|322|322|311|333|322|344|355|388|322|300|45E 117082213245820E
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 43C|43C|377|322|399|42B|399|44D|41A|366|388|333|366|322|42B|322 CC729B9DA68362B2
    Fri 2003/08/01 22:25:59 gammu-smsd[1934]: gammu: 311|399|41A|44D|366|366|42B|42B|300|311|0D |0A |0D |0A |4FO|4BK 19AD66BB01….OK

    pastikan lognya sudah dibuat agar bisa memantau apakah service berjalan atau tidak disaya contohnya sy buat file /etc/smsdlog

    Selamat mencoba

  3. harusnya sama saja. sudah di check service mysql jalan dan gammu daemon nya support mysql ? jika sudah bisa kirim sms dari console ya berarti gammu sudah berjalan , yang penting log gammu-nya ITU YG PERTAMA DIPERIKSA dulu 🙂

Leave a Reply to sephtian Cancel reply

Your email address will not be published. Required fields are marked *