Install, configure and tips on Gammu for mass sending of SMS

- Andrés Cruz

En español
Install, configure and tips on Gammu for mass sending of SMS

At the beginning of this Blog we talked a little about Gammu and the Gammu Demon; In this entry we will give some tips that generally explain how to install, configure and use Gammu on a computer with a Linux environment, specifically the Fedora distribution was used but it can be any other such as Ubuntu; the only thing that would vary are the steps to install it.

Gammu has a large number of features that allow you to control a phone almost entirely from your computer, but the main and most useful one is to send/receive SMS on your computer; Gammu specifically saves the SMS received and sent within databases that in this entry will be MYSQL; but apart from MYSQL it is possible to use SQLite or PostgreSQL.

Get and Install Gammu

You can obtain and install Gammu in several ways; from the official page in the download section we will see a set of them: Download Gammu.

In Fedora we can also install it from the repositories via terminal:

yum install gammu

Once installed; we must create a Database from which Gammu will control the entire process; or what is the same, where Gammu will control all messages sent/received; to run the SQL script in the database we execute:

mysql kalkun -u root -h localhost -p < /usr/share/doc/gammu/examples/sql/mysql.sql 

The previous SQL statement allows running the SQL script located in /usr/share/doc/gammu/examples/sql/mysql.sq in the Database called kalkun; Of course, you can also use a Database Administration System like phpMyAdmin to import the script.

Gammu considerations

As mentioned, Gammu allows you to fully control a device (understand modem or telephone); for this entry we use a ZTE MF190; you can check compatibility with the large number of phones and modems at: Gammu Phones Database.

Módem ZTE MF190

Módem ZTE MF190

Once we have our device at hand, we must create a configuration file where the Gammu daemon will take the different parameters and be able to use the device; we will call this file smsdrc-phone0, it must be located in the etc directory.

Connect your device to the computer with Gammu via USB wait a few seconds and run:

gammu -c /etc/smsdrc-phone0 --identify

Where smsdrc-phone0 is the name of the file.

And you will see information like the following:

Dispositivo          : /dev/ttyUSB1
Fabricante           : ZTE CORPORATION
Modelo               : unknown (MF190)
Firmware             : BD_MF190V1.0.0B06
IMEI                 : 357534040956887
IMSI de la SIM       : 734061041118604

Which indicates that your device is ready to use.

Sending our first SMS with Gammu

From the command line run:

gammu-smsd-inject TEXT 4161111111 -text "Hola Mundo"

Where 4161111111 is the reception phone number.

If we verify the previously created Database, we will see a table called outbox that when we execute the previous command we will see in a few seconds the SMS enqueued in this table and then a few seconds later the record is deleted, which means that the SMS was sent.

If the SMS does not "go out" or was not sent (it is kept in the outbox table) it may be due to the 3 ports that Linux occupies per connected device and for that we can create three files as follows:

/etc/smsdrc-phone0

# Configuration file for Gammu SMS Daemon

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

## SMSD configuration, see gammu-smsdrc(5)
#[smsd]
#service = files
#logfile = syslog
##Increase for debugging information
#debuglevel = 0

[smsd]
Service = sql
Driver = native_mysql
#PIN = 1234
logfile = /var/log/gammu/smsdlog1
debuglevel = 2
#runonreceive = /var/www/html/kalkun/scripts/daemon.sh
commtimeout = 30
sendtimeout = 30
phoneid=movilnet0

user = root
password = 12345
pc = localhost
database = kalkun

# 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/

/etc/smsdrc-phone1

# Configuration file for Gammu SMS Daemon

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

## SMSD configuration, see gammu-smsdrc(5)
#[smsd]
#service = files
#logfile = syslog
##Increase for debugging information
#debuglevel = 0

[smsd]
Service = sql
Driver = native_mysql
#PIN = 1234
logfile = /var/log/gammu/smsdlog1
debuglevel = 2
#runonreceive = /var/www/html/kalkun/scripts/daemon.sh
commtimeout = 30
sendtimeout = 30
phoneid=movilnet2

user = root
password = 12345
pc = localhost
database = kalkun

# 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/

/etc/smsdrc-phone2

# Configuration file for Gammu SMS Daemon

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

smsdrc-phone1

## SMSD configuration, see gammu-smsdrc(5)
#[smsd]
#service = files
#logfile = syslog
##Increase for debugging information
#debuglevel = 0

[smsd]
Service = sql
Driver = native_mysql
#PIN = 1234
logfile = /var/log/gammu/smsdlog1
debuglevel = 2
#runonreceive = /var/www/html/kalkun/scripts/daemon.sh
commtimeout = 30
sendtimeout = 30
phoneid=movilnet1

user = root
password = 12345
pc = localhost
database = kalkun

# 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/

Explanation of the previous files and Tips on Gammu

Among several configurations, the user (user) and password (password) of the database are defined, as well as the host (pc) and the database (database); a unique device id (phoneid) is also defined for each connected device, the database management system (Driver) and the port (port) that we will explain in the next paragraph.

If you look closely, the only thing that varies between the three files is the port; the reason to create three files for a single modem is because Linux occupies three ports for connected devices, and it is a bit difficult to know which one is receiving and sending SMS, you can use a single file and test which one to send/receive or simply define three files (one for each port).

In the case of wanting to test which port it is connected to once you have defined the three files, execute one command at a time:

gammu -c /etc/smsdrc-phone0 --identify
gammu -c /etc/smsdrc-phone1 --identify
gammu -c /etc/smsdrc-phone2 --identify

The fact that it does not give you information means that it is not connected to that port.

We start the daemon for each file:

gammu-smsd --daemon -c /etc/smsdrc-phone0
gammu-smsd --daemon -c /etc/smsdrc-phone1
gammu-smsd --daemon -c /etc/smsdrc-phone2

Also, if you want to test the configuration of a particular device (in case you have more than one device connected):

INSERT INTO outbox(DestinationNumber, Coding, TextDecoded,`SenderID`) VALUES ('04162147462','Default_No_Compression','Hola Mundo','movilnet0'); 

Where movilnet0 is the modem identifier.

To connect more devices to send/receive SMS, you simply have to create three files per device or check which port sends SMS through.

To check which file Gammu is taking the configuration for the device from, we run:

[root@linux03 linux03]#  gammu -c /etc/smsdrc-phone0 --identify
No response was received within the specified time. The phone is probably not connected.
[root@linux03 linux03]#  gammu -c /etc/smsdrc-phone1 --identify
Dispositivo          : /dev/ttyUSB1
Fabricante           : ZTE CORPORATION
Modelo               : unknown (MF190)
Firmware             : BD_MF190V1.0.0B06
IMEI                 : 357534040956887
IMSI de la SIM       : 734061041118604
[root@linux03 linux03]#  gammu -c /etc/smsdrc-phone2 --identify
No response was received within the specified time. The phone is probably not connected.

As you will see, the only one that gives a response is the file whose port is /dev/ttyUSB1.

Gammu SMS Handlers

There are several options that allow you to manage the device through interfaces instead of using the terminal; in this way it is possible to create an abstraction layer to work with different devices, one of them is Kalkun that provides a web interface to manage the different devices; you can see all the drivers in the following link: Third party applications using Gammu.

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.