Send SMS dengan Linux + PHP + gammu + oracle + Huawei E220

27 Jan

Send SMS dengan Linux + PHP + gammu + oracle + Huawei E220

Mengirim SMS menggunakan gammu, sebenarnya bukan hal baru buat saya, tapi selama ini saya menggunakan HP Nokia 5110. HP Nokia 5110 ini mempunyai julukan  “HP sejuta umat”, HP yang konon dimiliki oleh orang banyak dan menjadi “standard” pemilik HP.

IMG_20140127_142139

Tapi, sayang di sayang beberapa minggu ini, sms selalu gagal dikirim. Akhirnya dengan “tetesan air mata”, HP Nokia 5110 ini dipinsiunkan. Mau dijual juga nggak akan laku.

Sekarang ke inti judul blog ini “Send SMS dengan Linux + PHP + gammu + oracle + Huawei E220”

IMG_20140127_144204

1. colok USB MODEM
[root@ubsweb ~]# lsusb
Bus 002 Device 006: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E230/E270 HSDPA/HSUPA Modem
Bus 002 Device 001: ID 0000:0000
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 003: ID 0bda:0111 Realtek Semiconductor Corp. Card Reader
Bus 001 Device 007: ID 19d2:fff5 ONDA Communication S.p.A.
Bus 001 Device 001: ID 0000:0000
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

2. cek
[root@ubsweb ~]# dmesg | grep tty
serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
usb 1-1.1: ark3116 converter now attached to ttyUSB0
ark3116 ttyUSB0: ark3116 converter now disconnected from ttyUSB0
usb 1-1.1: ark3116 converter now attached to ttyUSB0
ark3116 ttyUSB0: ark3116 converter now disconnected from ttyUSB0
usb 2-1.1: GSM modem (1-port) converter now attached to ttyUSB0
usb 2-1.1: GSM modem (1-port) converter now attached to ttyUSB1
option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0
option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1

3. atasi problem “option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1”
[root@ubsweb ~]# rmmod usb-storage

4. cabut dan colok USB MODEM
[root@ubsweb ~]# dmesg | grep tty
serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
usb 1-1.1: ark3116 converter now attached to ttyUSB0
ark3116 ttyUSB0: ark3116 converter now disconnected from ttyUSB0
usb 1-1.1: ark3116 converter now attached to ttyUSB0
ark3116 ttyUSB0: ark3116 converter now disconnected from ttyUSB0
usb 2-1.1: GSM modem (1-port) converter now attached to ttyUSB0
usb 2-1.1: GSM modem (1-port) converter now attached to ttyUSB1
option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0
option1 ttyUSB1: GSM modem (1-port) converter now disconnected from ttyUSB1
usb 2-1.1: GSM modem (1-port) converter now attached to ttyUSB0
usb 2-1.1: GSM modem (1-port) converter now attached to ttyUSB1

5. install gammu
[root@ubsweb ~]# cat /etc/redhat-release
CentOS release 5.6 (Final)

5a. download cmake
[root@ubsweb ~]# wget http://pkgs.fedoraproject.org/repo/pkgs/cmake/cmake-2.8.7.tar.gz/e1b237aeaed880f65dec9c20602452f6/cmake-2.8.7.tar.gz

5b. install cmake
[root@ubsweb ~]# tar -xzvf cmake-2.8.7.tar.gz
[root@ubsweb ~]# cd cmake-2.8.7
[root@ubsweb cmake-2.8.7]# ./configure
[root@ubsweb cmake-2.8.7]# gmake

5c. test apakah cmake sudah berfungsi
[root@ubsweb cmake-2.8.7]# cd ..
[root@ubsweb ~]# cmake

5d. download gammu
[root@ubsweb ~]# wget http://sourceforge.net/projects/gammu/files/gammu/1.31.0/gammu-1.31.0.tar.gz
[root@ubsweb ~]# tar -xzvf gammu-1.31.0.tar.gz
[root@ubsweb ~]# cd gammu-1.31.0
[root@ubsweb gammu-1.31.0]# ./configure
[root@ubsweb gammu-1.31.0]# make install

5e. test gammu
[root@ubsweb gammu-1.31.0]# cd ..
[root@ubsweb ~]# gammu

5f. jika gagal
[root@ubsweb ~]# ln -s /usr/local/lib64/libGammu.so /usr/lib64/libGammu.so.7
[root@ubsweb ~]# ln -s /usr/local/lib64/libgsmsd.so /usr/lib64/libgsmsd.so.7
[root@ubsweb ~]# gammu

5g. membuat file log :
[root@ubsweb ~]# mkdir /var/log/gammu
[root@ubsweb ~]# touch /var/log/gammu/gammurc

5h. setting gammu
[root@ubsweb ~]# gammu-config
Port                 (/dev/ttyUSB0)
Connection           (at115200)

5i. gammu cek
[root@ubsweb ~]# gammu –identify
Device               : /dev/ttyUSB0
Manufacturer         : Huawei
Model                : unknown (K3565)
Firmware             : 11.608.10.51.00
IMEI                 : xxxxxxxxxxxxxxxxxxx
SIM IMSI             : xxxxxxxxxxxxxxxxxxx

6. test kirim sms
[root@ubsweb ~]# gammu –sendsms text 0815xxxxxxx
Enter the message text and press Ctrl+D:
kirim sms lewat USB MODEM + gammu + linux
If you want break, press Ctrl+C…
Sending SMS 1/1….waiting for network answer..OK, message reference=17

[root@ubsweb ~]# echo “sms test” | gammu –sendsms TEXT 0815xxxxxxx
If you want break, press Ctrl+C…
Sending SMS 1/1….waiting for network answer..OK, message reference=18

7. membuat script php dengan database oracle
[root@ubsweb gammu-1.31.0]# cd /var/www/html/monitor/
[root@ubsweb monitor]# nano send_sms.php
<?php
include(‘oraconn3.php’);

$querry       = “SELECT D.BERITA, E.NO_HP, D.KUNCI FROM “;
$querry      .= ”  ( “;
$querry      .= ”   SELECT C.BERITA, C.STATUS, C.NAMA, C.KUNCI FROM  “;
$querry      .= ”    ( SELECT A.SUBJ || ‘ DARI : ‘ || A.DARI BERITA,  A.STATUS, B.NAMA, A.KUNCI FROM HP_MSEND A, HP_DSEND B   “;
$querry      .= ”      WHERE A.KUNCI = B.KUNCI ) C “;
$querry      .= ”      WHERE STATUS <> ‘X’ ) D, HP_OWN E WHERE D.NAMA = E.NAMA “;

$kunci = “”;
$statemen     = oci_parse($ora_conn, $querry);
oci_execute($statemen);
while($dta = oci_fetch_array($statemen, OCI_BOTH))
{
if ($kunci!=$dta[2])
{
$querry2   = “UPDATE HP_MSEND SET STATUS = ‘X’ WHERE KUNCI = ‘” .$dta[2] .”‘”;
$statemen2 = oci_parse($ora_conn, $querry2);
oci_execute($statemen2);

$kunci     = $dta[2];
}
$cmd=”echo ‘”. $dta[0].”‘|/usr/local/bin/gammu sendsms TEXT “. $dta[1];
$output = shell_exec($cmd);
}
?>

8. membuat crontab
[root@ubsweb monitor]# nano phpku
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_1; export ORACLE_HOME
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
php $1

[root@ubsweb monitor]# nano send_sms
cd /var/www/html/monitor/
/var/www/html/monitor/phpku send_sms.php
[root@ubsweb monitor]# chmod a+x send_sms

[root@ubsweb monitor]# crontab -e
*  *  * * *     /var/www/html/monitor/send_sms

One Response to “Send SMS dengan Linux + PHP + gammu + oracle + Huawei E220”

  1. Profeseor April 28, 2015 at 6:25 am #

    Kalau menerima sms dan dimasukkan ke oracle ada tutorial nya nda ya?

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: