Getting Started with Gammu — Installation & Basic CommandsGammu is a command-line utility and library for managing mobile phones and modems. It supports sending and receiving SMS, phonebook management, call logs, and more across a wide variety of devices. This guide walks through installing Gammu on Linux, Windows, and macOS, configuring it to talk to your phone or modem, and using essential commands for everyday tasks.
What is Gammu and when to use it
Gammu is an open-source project that provides:
- SMS send/receive via a connected phone or GSM modem
- Phonebook (contacts) management and backups
- Call log access and basic device information retrieval
- Integration into scripts and automation (via command line or the python-gammu library)
Use Gammu when you need a low-level, scriptable tool to interact with mobile devices over serial/USB connections or to run an SMS gateway from inexpensive GSM modems.
1. Installing Gammu
Below are instructions for the most common platforms. After installation, you’ll typically configure a small file to point Gammu at your device.
Linux (Debian/Ubuntu)
On Debian-based systems, install from the package repository:
sudo apt update sudo apt install gammu gammu-smsd
- gammu: the command-line tool and library
- gammu-smsd: an optional daemon (SMSD) for running an SMS gateway service
If you need the latest version, consider building from source (see the project page) or using distribution-specific backports.
Fedora / RHEL / CentOS
On Fedora:
sudo dnf install gammu gammu-smsd
On RHEL/CentOS you may need EPEL for packages:
sudo yum install epel-release sudo yum install gammu gammu-smsd
macOS
Install via Homebrew:
brew install gammu
Homebrew may not provide gammu-smsd; for SMSD you might need to build from source.
Windows
Download the installer from the official Gammu website or use MSYS2 packages. The installer packages both the Gammu binary and the GUI clients (where available). For scripting, prefer to use the command-line binary installed to your PATH.
2. Identifying your device and connection
Gammu communicates over serial ports. Depending on the OS and device, the port name differs.
- Linux: /dev/ttyUSB0, /dev/ttyACM0, /dev/ttyS0, or a path under /dev/serial/by-id/
- macOS: /dev/tty.usbmodemXXXX or /dev/cu.usbserial-XXXX
- Windows: COM1, COM3, etc.
To discover the port:
- Unplug device, list devices (ls /dev/* or Device Manager), plug in, re-run list and note the new device.
- Use dmesg (Linux) to view kernel messages when plugging a USB modem:
dmesg | tail -n 50
Some phones require enabling a “modem” or “PC suite” mode in their settings or installing appropriate USB drivers.
3. Initial Gammu configuration
Create a configuration file at ~/.gammurc (user-wide) or /etc/gammurc (system-wide). A minimal example:
[gammu] port = /dev/ttyUSB0 connection = at115200 name = MyModem
Key fields:
- port: serial device path (or COM port on Windows)
- connection: connection type. Common values:
- at115200 — generic AT modem at 115200 baud
- at — generic AT
- fbus, ir — older Nokia protocols
- auto — let Gammu try to detect
You can also pass connection parameters on the command line:
gammu --port /dev/ttyUSB0 --connection at115200 identify
4. Verifying connection and identifying the device
Use the identify command to confirm Gammu can talk to the phone:
gammu --identify
Expected output includes model, IMEI, manufacturer, firmware, etc. If identify fails:
- Check the port is correct and no other program (like ModemManager or NetworkManager) is locking the device.
- On Linux, stop interfering services:
sudo systemctl stop ModemManager sudo systemctl stop NetworkManager
(Stopping NetworkManager may impact your network connections; instead, unload only ModemManager if possible.)
Permissions: ensure you have read/write access to the serial device. Add your user to the dialout or uucp group (depending on distro):
sudo usermod -a -G dialout $USER
Then log out and back in.
5. Basic Gammu commands (common tasks)
All commands below can be run with or without a config file by providing –port and –connection.
Send an SMS (text mode)
gammu sendsms TEXT +1234567890 -text "Hello from Gammu"
Send a multipart or Unicode SMS:
gammu sendsms TEXT +1234567890 -unicode "Привет — testing"
Receive SMS (read messages stored on device)
gammu getallsms
This lists SMS messages and metadata. You can delete or export them as needed.
Delete all SMS from phone
gammu deletesms 1 all
(Depending on device indexing; consult getallsms output.)
Read phonebook (contacts)
gammu getphonebook MEMORY
Where MEMORY is a memory location name returned by gammu identify (e.g., ME, SM, ON).
Add a contact
gammu addphoneentry TEXT "Alice" /number:"+1234567890" /memory:ME
Get device information
gammu --identify gammu --getbattery gammu --gettime
Export settings and data
- To backup SMS and phonebook, run getallsms and getphonebook and redirect output to files. For automated exports, write scripts to parse Gammu’s output or use python-gammu.
6. Using gammu-smsd (SMS daemon) — quick overview
gammu-smsd runs as a background service to send/receive SMS automatically and integrate with databases or scripts. Main use cases: SMS gateway, autoreplies, automated notifications.
Installation typically includes a config sample at /etc/gammu-smsdrc. Key configuration sections:
- [gammu] connection details (port, connection)
- [smsd] service parameters (RunOnReceive, RunOnSend, Service, LogFile, Database settings)
Basic steps to run:
- Configure /etc/gammu-smsdrc (or /etc/gammu-smsd/gammu-smsdrc) with correct port and database backend (MySQL, SQLite, PostgreSQL, or Files).
- Initialize the database schema (sample SQL files included).
- Start the service:
sudo systemctl enable --now gammu-smsd
RunOnReceive and RunOnSend can call scripts to process messages as they arrive or are sent.
7. Troubleshooting tips
- Identify failure reasons: run commands with verbose output:
gammu --debug --identify
- Permission denied: add user to dialout/uucp or run with sudo.
- Modem locked: stop ModemManager or other services.
- Unsupported phone protocols: older phones may require specific connection types (fbUS, nokia protocols). Try ‘auto’ or consult device-specific notes.
- USB-to-serial adapter issues: ensure drivers installed and check dmesg for errors.
- Broken multipart/Unicode messages: use -unicode flag for sendsms.
8. Example workflows
Automated SMS alert script (bash)
#!/bin/bash # send_alert.sh NUMBER="$1" MESSAGE="$2" gammu --sendsms TEXT "$NUMBER" -text "$MESSAGE"
Cron job to poll and process incoming SMS using gammu-smsd or a polling script that runs gammu getallsms and processes new entries.
Python integration (python-gammu)
- Install python-gammu via pip or package manager. Use it to embed SMS operations in Python applications with more structured APIs than parsing command-line output.
9. Security and best practices
- Restrict physical access to GSM modems to prevent unauthorized SMS/phonebook access.
- If running gammu-smsd with database backends, secure database credentials and network access.
- Monitor modem logs and set up alerts for errors or unusual send volumes to detect misuse.
10. Further resources
- Official Gammu documentation and wiki (contains device-specific notes and advanced configuration)
- Mailing lists and community forums for device quirks and troubleshooting
- python-gammu docs for programmatic usage
If you want, I can:
- Provide a ready-to-run ~/.gammurc and gammu-smsdrc sample tailored to your OS and device model.
- Walk through connecting a specific phone or modem (tell me model and OS).