Sabtu, 17 Maret 2012

Install Gammu Debian/Ubuntu

1.  Install dependency aplikasi gammu dan librarynya
root@faldy~# sudo apt-get install gammu gammu-smsd libgammu7 libgsmsd7

2. Masukkan Modem USB anda, disini saya menggunakan modem SIERRA At&T
 root@faldy~# 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@faldy~#

Dari Informasi diatas diketahui bahwa modem sudah terdeteksi dan berada pada port ttysUSB2
Buat configurasi gammu dengan perintah berikut (sesuaikan Port dan Connection)

root@faldy~# 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@faldy~# 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@faldy~#

Check kembali apakah gammu sudah bisa berkomunikasi dengan modem anda.
root@faldy~# 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@faldy~#


 root@faldy:/usr/share/doc/gammu/examples/sql# ls
 mysql.sql  pgsql.sql.gz  sqlite.sql.gz
  root@faldy:/usr/share/doc/gammu/examples/sql#

Create Database gammu
root@faldy:/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@faldy:/usr/share/doc/gammu/examples/sql# mysql -u root -p gammu < mysql.sql
 Enter password:
  
root@faldy:/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@faldy:/# 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@faldy~# 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@faldy~#

Check log
 root@faldy~# 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@faldy~#

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";
?>

Kalau ada yang mau ditanya . tanya sama saya mungkin bisa bantu ^_^
untuk Autoreplynya nanti pake trigger ^^

3 komentar: