SMS

Menggunakan Gammu Untuk SMS Gateway

Gammu adalah aplikasi open-source yang memungkinkan kamu mengirim dan menerima SMS melalui komputer menggunakan handphone atau modem yang terhubung. SMS Gateway dengan Gammu banyak digunakan untuk notifikasi, verifikasi OTP, dan komunikasi otomatis.

Apa itu Gammu?

Gammu (GNU All Mobile Management Utilities) adalah tools untuk mengelola handphone dan modem. Gammu mendukung berbagai merek handphone dan modem GSM/CDMA. Dengan Gammu, kamu bisa mengirim SMS, menerima SMS, mengelola kontak, dan banyak lagi.

Prasyarat

  • Handphone/Modem GSM yang terhubung ke komputer (USB/Serial/Bluetooth)
  • SIM Card dengan pulsa yang cukup
  • Komputer dengan OS Windows/Linux
  • PHP untuk integrasi web
  • MySQL untuk penyimpanan data SMS

Step 1: Install Gammu

# Windows - download dari https://wammu.eu/download/ # Jalankan installer dan ikuti wizard  # Linux (Ubuntu/Debian) sudo apt update sudo apt install gammu gammu-smsd  # CentOS/RHEL sudo yum install gammu gammu-smsd

Step 2: Konfigurasi Gammu

Buat file konfigurasi gammurc:

# ~/.gammurc atau /etc/gammurc [gammu] device = /dev/ttyUSB0 connection = at # Untuk Windows: device = COM3 atau COM4

Identifikasi port yang digunakan:

# Cek port yang tersedia gammu --identify

Step 3: Kirim SMS via Command Line

# Kirim SMS teks biasa gammu sendsms TEXT 08123456789 -text "Halo dari Gammu!"  # Kirim SMS dari file gammu sendsms TEXT 08123456789 -textfile message.txt  # Kirim SMS flash (langsung muncul di layar) gammu sendsms TEXT 08123456789 -flash

Step 4: Setup SMSD (SMS Daemon)

SMSD adalah service background yang otomatis memproses SMS masuk dan keluar. Buat konfigurasi SMSD:

# /etc/gammu-smsdrc [gammu] device = /dev/ttyUSB0 connection = at  [smsd] service = files logfile = /var/log/gammu-smsd.log inboxpath = /var/spool/gammu/inbox/ outboxpath = /var/spool/gammu/outbox/ sentsmspath = /var/spool/gammu/sent/ errorsmspath = /var/spool/gammu/error/
# Jalankan SMSD sudo gammu-smsd -c /etc/gammu-smsdrc  # Atau sebagai service sudo systemctl start gammu-smsd

Step 5: Integrasikan dengan PHP

Buat script PHP untuk mengirim SMS:

<?php function sendSMS($number, $message) {     $cmd = "gammu sendsms TEXT {$number} -text " . escapeshellarg($message);     $output = shell_exec($cmd);     return $output; }  // Kirim SMS $result = sendSMS("08123456789", "Verifikasi kode kamu: 123456"); echo $result; ?>

Step 6: Simpan SMS ke Database

Buat tabel MySQL untuk menyimpan data SMS:

CREATE TABLE sms_log (     id INT AUTO_INCREMENT PRIMARY KEY,     phone_number VARCHAR(20) NOT NULL,     message TEXT NOT NULL,     direction ENUM('in', 'out') NOT NULL,     status ENUM('pending', 'sent', 'failed') DEFAULT 'pending',     created_at DATETIME DEFAULT CURRENT_TIMESTAMP );

Step 7: Auto-Reply SMS Masuk

Buat script untuk memproses SMS masuk dan mengirim balasan otomatis:

<?php // Baca SMS dari inbox $inbox_path = '/var/spool/gammu/inbox/'; $files = glob($inbox_path . '*.txt');  foreach ($files as $file) {     $content = file_get_contents($file);     // Parse SMS content     // Kirim balasan     // Hapus file setelah diproses     unlink($file); } ?>

Troubleshooting

  • Device not found: Cek koneksi USB dan install driver modem
  • Permission denied: Tambah user ke grup dialout (Linux)
  • SMS gagal terkirim: Cek pulsa dan sinyal
  • SMSD tidak jalan: Cek log di /var/log/gammu-smsd.log

Kesimpulan

Gammu adalah solusi SMS Gateway yang murah dan reliable untuk kebutuhan bisnis. Dengan Gammu, kamu bisa mengirim SMS otomatis, menerima SMS, dan mengintegrasikannya dengan aplikasi web. Cocok untuk sistem notifikasi, verifikasi OTP, dan marketing SMS.

Persiapan SMS Gateway dengan Gammu

Yang perlu disiapkan:

  • Modem GSM - USB modem atau HP yang mendukung AT command
  • SIM Card - Dengan pulsa yang cukup untuk mengirim SMS
  • Gammu - Software SMS gateway yang sudah terinstall
  • Server - Komputer/server yang berjalan 24/7

Konfigurasi Gammu

Buat file konfigurasi gammurc:

[gammu]
device = /dev/ttyUSB0
connection = at
name = Phone on USB serial port

Script PHP untuk Kirim SMS

<?php
function kirimSMS($nomor, $pesan) {
    $cmd = "gammu --sendsms TEXT " . escapeshellarg($nomor) . 
           " -textutf8 " . escapeshellarg($pesan);
    exec($cmd, $output, $return);
    return $return === 0;
}

// Penggunaan
$result = kirimSMS("08123456789", "Test SMS dari PHP");
echo $result ? "SMS terkirim" : "Gagal mengirim SMS";
?>

Monitoring dan Troubleshooting

  • Cek koneksi modem - Jalankan gammu --identify
  • Monitor log - Periksa log Gammu untuk error
  • Auto-restart - Buat script watchdog untuk restart otomatis jika Gammu crash
  • Queue management - Implementasi antrian SMS untuk menghindari overload

You may also like


0 Comments


Leave a Reply

Comments with links or spam keywords will be rejected.
Scroll to Top