Gammu SMSD Command
Gammu SMSD Command
Gammu SMSD Command
Release 1.29.90
1 Overview 1
1.1 Overall schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 SMSD operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Usage 3
2.1 Storing Messages in Backend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Creating Messages to Send . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Notification about Received Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.4 Monitoring SMSD Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.5 Reporting Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Program Manuals 5
3.1 gammu-smsd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 gammu-smsd-inject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 gammu-smsd-monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
5 RunOnReceive Directive 19
5.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.2 Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6 Backend services 23
6.1 Files backend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.2 SQL Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.3 MySQL Backend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.4 PostgreSQL Backend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.5 DBI Backend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.6 Null Backend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.7 SMSD Database Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7 Developer documentation 51
7.1 Backend services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.2 Message Sending Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
i
7.3 Message Receiving Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Index 57
ii
CHAPTER
ONE
OVERVIEW
Gammu SMS Daemon is a program that periodically scans GSM modem for received messages, stores them in defined
storage and also sends messages enqueued in this storage.
The interactions of SMS Daemon and related components can be seen on following picture.
gammu-smsd-inject
Inject
Service
storage
1
Gammu SMSD Daemon Manual, Release 1.29.90
2 Chapter 1. Overview
CHAPTER
TWO
USAGE
This chapter will describe basic ways of using SMSD. It’s use is not limited to these, but they can give you overview
of SMSD abilities.
The standard mode of operating SMSD. You simply configure backend service, and all received messages will end up
in it and any message you put into outbox storage will be sent.
Creating of messages to send heavily depends on service backend you use. Most of them support gammu-smsd-inject,
which can be used to construct the message, or you can just insert message manually to the backend storage.
Alternatively you can use SMSD_InjectSMS() (from C) or using gammu.smsd.SMSD.GetStatus() (from
Python).
Once SMSD receives message and stores it in backend service, it can invoke your own program to do any message
processing, see RunOnReceive Directive.
You can use gammu-smsd-monitor to monitor status of SMSD. It uses shared memory segment to get current status of
running SMSD.
Alternatively you can get the same functionality from libGammu using SMSD_GetStatus() or python-gammu
using gammu.smsd.SMSD.GetStatus().
3
Gammu SMSD Daemon Manual, Release 1.29.90
4 Chapter 2. Usage
CHAPTER
THREE
PROGRAM MANUALS
3.1 gammu-smsd
3.1.1 Synopsis
gammu-smsd [OPTION]...
3.1.2 Description
5
Gammu SMSD Daemon Manual, Release 1.29.90
-i, -install-service
Installs SMSD as a Windows service.
-u, -uninstall-service
Uninstalls SMSD as a Windows service.
-s, -start-service
Starts SMSD Windows service.
-k, -stop-service
Stops SMSD Windows service.
-f, -max-failures=count
Terminate after defined number of failures. Use 0 to not terminate (this is default).
-X, -suicide=seconds
Kills itself after number of seconds.
-S, -run-service
Runs pogram as SMSD Windows service. This should not be used manually, but only Windows Service manager
should use this command.
-n, -service-name=name
Defines name of a Windows service. Each service requires an unique name, so if you want to run several SMSD
instances, you have to name each service differently. Default is “GammuSMSD”.
3.1.3 Examples
Linux/Unix Examples
To use SMSD as a daemon, you might want to use init script which is shipped with Gammu in contrib/init directory.
It is not installed by default, either install it manually or check INSTALL file for instructions.
Under Windows 7 you might need to disable UAC (user account control) before you will be able to install SMSD
service.
If Gammu fails to start as a Windows service (you will usually get “Error 1053: The service did not respond to the
start or control request in a timely fashion”), first check your SMSD logs. If they do not contain any useful hint, try
starting SMSD manually with exactly same parameters as you installed the service (without -i).
For example the command line can look like:
gammu-smsd.exe -c smsdrc
You now should be able to get errors from SMSD even if it fails to start as a service.
You can not use same phone by more programs in same time. However in case you did not enable locking in [gammu]
section, it might be able to start the communication with phone from more programs. In this case neither of the
programs will probably work.
There is no way to detect that SMS message is reply to another by looking at message headers. The only way to
achieve this is to add some token to the message and let the user include it in the message on reply.
3.2 gammu-smsd-inject
3.2.1 Synopsis
3.2.2 Description
3.2. gammu-smsd-inject 7
Gammu SMSD Daemon Manual, Release 1.29.90
3.2.3 Examples
To check it out, you need to have configuration file for SMSD, see SMSD Configuration File for more details about it.
Inject text message up to standard 160 chars:
echo "All your base are belong to us" | gammu-smsd-inject TEXT 123456
or
gammu-smsd-inject TEXT 123456 -text "All your base are belong to us"
or
gammu-smsd-inject TEXT 123456 -len 400 -text "All your base are belong to us"
or
gammu-smsd-inject EMS 123456 -text "All your base are belong to us"
Inject some funky message with predefined sound and animation from 2 bitmaps:
gammu-smsd-inject EMS 123456 -text "Greetings" -defsound 1 -text "from Gammu" -tone10 axelf.txt -anim
3.3 gammu-smsd-monitor
3.3.1 Synopsis
gammu-smsd-monitor [OPTION]...
3.3.2 Description
-l, -loops=count
Number of loops, by default monitor loops infinitely.
-d, -delay=seconds
Delay betwen polling SMSD state, default is 20 seconds.
-C, -csv
Print output in comma separated values format:
client;phone ID;IMEI;sent;received;failed;battery;signal
3.3. gammu-smsd-monitor 9
Gammu SMSD Daemon Manual, Release 1.29.90
FOUR
4.1 Description
gammu-smsd reads configuration from a config file. It’s location can be specified on command line, otherwise default
path /etc/gammu-smsdrc is used.
This file use ini file syntax, see ini.
Configuration file of gammu-smsd consists of at least two sections -
[gammu] and [smsd]. For SQL Service you can also use [sql].
The [gammu] section is configuration of a phone connection and is same as described in gammurc with the only
exception that
LogFile is ignored and common logging for gammu library and SMS daemon is used. However the LogFormat
directive still configures how much messages gammu emits.
[smsd]
The [smsd] section configures SMS daemon itself, which are described in following subsections. First general
parameters of SMS daemon are listed and then specific parameters for storage backends.
[include_numbers]
List of numbers from which accept messages, see Message filtering.
[exclude_numbers]
List of numbers from which reject messages, see Message filtering.
[include_smsc]
List of SMSC numbers from which accept messages, see Message filtering.
[exclude_smsc]
List of SMSC numbers from which reject messages, see Message filtering.
[sql]
Configure SQL queries used by SQL Service, you usually don’t have to modify them.
See Also:
Configurable queries
Service
SMSD service to use, one of following choices:
11
Gammu SMSD Daemon Manual, Release 1.29.90
PIN
PIN for SIM card. This is optional, but you should set it if your phone after power on requires PIN.
NetworkCode
Network personalisation password. This is optional, but some phones require it after power on.
PhoneCode
Phone lock password. This is optional, but some phones require it after power on.
LogFile
File where SMSD actions are being logged. You can also use special value syslog which will send all mes-
sages to syslog daemon. On Windows another special value eventlog exists, which will send logs to Windows
Event Log.
If you run SMSD as a system daemon (or service), it is recommended to use absolute path to log file as startup
directory might be different than you expect.
Default is to provide no logging.
DebugLevel
Debug level for SMSD. The integer value should be sum of all flags you want to enable.
1 enables basic debugging information
2 enables logging of SQL queries of service backends
4 enables logging of gammu debug information
Generally to get as much debug information as possible, use 255.
Default is 0, what should mean no extra information.
CommTimeout
How many seconds should SMSD wait after there is no message in outbox.
Default is 30.
SendTimeout
Shows how many seconds SMSD should wait for network answer during sending sms. If nothing happen during
this time, sms will be resent.
Default is 30.
MaxRetries
How many times will SMSD try to resend message if sending fails.
Default is 1.
ReceiveFrequency
The number of seconds between testing for received SMSes, when the phone is busy sending SMSes. Normally
a test for received SMSes is done every
CommTimeout seconds and after each sent SMS.
Default is 0 (not used).
StatusFrequency
The number of seconds between refreshing phone status (battery, signal) stored in shared memory and possibly
in service backends. Use 0 to disable.
Default is 15.
LoopSleep
The number of seconds how long will SMSD sleep before checking for some activity. Please note that setting
this to higher value than 1 will have effects to other time based configurations, because they will be effectively
rounded to multiply of this value.
Default is 1.
MultipartTimeout
The number of seconds how long will SMSD wait for all parts of multipart message. If all parts won’t arrive in
time, parts will be processed as separate messages.
Default is 600 (10 minutes).
CheckSecurity
Whether to check if phone wants to enter PIN.
Default is 1 (enabled).
CheckBattery
Whether to check phone battery state periodically.
Default is 1 (enabled).
CheckSignal
Whether to check signal level periodically.
Default is 1 (enabled).
ResetFrequency
The number of seconds between performing a preventive soft reset in order to minimize the cases of hanging
phones e.g. Nokia 5110 will sometimes freeze to a state when only after unmounting the battery the phone will
be functional again.
Default is 0 (not used).
HardResetFrequency
Warning: For some phones hard reset means deleting all data in it. Use
New in version 1.28.92.
ResetFrequency, unless you know what you are doing.
The number of seconds between performing a preventive hard reset in order to minimize the cases of hanging
phones.
Default is 0 (not used).
DeliveryReport
Whether delivery reports should be used, one of no, log, sms.
log one line log entry,
sms store in inbox as a received SMS
no no delivery reports
Default is no.
DeliveryReportDelay
Delay in seconds how long is still delivery report considered valid. This depends on brokeness of your network
(delivery report should have same timestamp as sent message). Increase this if delivery reports are not paired
with sent messages.
Default is 600 (10 minutes).
PhoneID
String with info about phone used for sending/receiving. This can be useful if you want to run several SMS
daemons.
When you set PhoneID, all messages (including injected ones) will be marked by this string and it allow more
SMS daemons to share single database. This option has actually no effect with Files backend.
RunOnReceive
Executes a program after receiving message.
This parameter is executed through shell, so you might need to escape some special characters and you can
include any number of parameters. Additionally parameters with identifiers of received messages are appended
to the command line. The identifiers depend on used service backend, typically it is ID of inserted row for
database backends or file name for file based backends.
Gammu SMSD waits for the script to terminate. If you make some time consuming there, it will make SMSD
not receive new messages. However to limit breakage from this situation, the waiting time is limited to two
minutes. After this time SMSD will continue in normal operation and might execute your script again.
The process has available lot of information about received message in environment, check RunOnReceive
Directive for more details.
RunOnFailure
New in version 1.28.93. Executes a program on failure.
This can be used to proactively react on some failures or to interactively detect failure of sending message.
The program will receive optional parameter, which can currently be either INIT (meaning failure during phone
initialization) or message ID, which would indicate error while sending the message.
Note: The environment with message (as is in RunOnReceive) is not passed to the command.
IncludeNumbersFile
File with list of numbers which are accepted by SMSD. The file contains one number per line, blank lines are
ignored. The file is read at startup and is reread only when configuration is being reread. See Message filtering
for details.
ExcludeNumbersFile
File with list of numbers which are not accepted by SMSD. The file contains one number per line, blank lines
are ignored. The file is read at startup and is reread only when configuration is being reread. See Message
filtering for details.
IncludeSMSCFile
File with list of SMSC numbers which are accepted by SMSD. The file contains one number per line, blank
lines are ignored. The file is read at startup and is reread only when configuration is being reread. See Message
filtering for details.
ExcludeSMSCFile
File with list of SMSC numbers which are not accepted by SMSD. The file contains one number per line, blank
lines are ignored. The file is read at startup and is reread only when configuration is being reread. See Message
filtering for details.
BackendRetries
How many times will SMSD backend retry operation.
The implementation on different backends is different, for database backends it generally means how many
times it will try to reconnect to the server.
Default is 10.
Send
Whether to enable sending of messages.
Default is True.
Receive
Whether to enable receiving of messages.
Default is True.
All DBI, MYSQL and PGSQL backends (see MySQL Backend, PostgreSQL Backend, DBI Backend for their docu-
mentation) supports same options for configuring connection to a database:
User
User name used for connection to a database.
Password
Password used for connection to a database.
Host
Database server address. It can also contain port or socket path after semicolon, for example
localhost:/path/to/socket. New in version 1.28.92.
PC
Synonym for Host. Deprecated since version 1.28.92.
Database
Name of database to use. Please note that you should create tables in this database before using gammu-smsd.
SQL files for creating needed tables are included in documentation.
SkipSMSCNumber
When you send sms from some SMS centere you can have delivery reports from other SMSC number. You can
set here number of this SMSC used by you and Gammu will not check it’s number during assigning reports to
sent SMS.
Driver
SQL driver to use.
Can be either one of native drivers (native_mysql or native_pgsql) or DBI Backend driver.
Depends on what DBI drivers you have installed, DBI supports: mysql, freetds (provides access to MS
SQL Server and Sybase), pgsql, sqlite, sqlite3, firebird and ingres, msql and oracle drivers
are under development.
DriversPath
Path, where DBI drivers are stored, this usually does not have to be set if you have properly installed drivers.
DBDir
Database directory for some (currently only sqlite) DBI drivers. Set here path where sqlite database files are
stored.
The FILES backend accepts following configuration options. See Files backend for more detailed service backend
description. Please note that all path should contain trailing path separator (/ on Unix systems):
InboxPath
Where the received SMSes are stored.
Default is current directory.
OutboxPath
Where SMSes to be sent should be placed.
Default is current directory.
SentSMSPath
Where the transmitted SMSes are placed, if same as OutboxPath transmitted messages are deleted.
Default is to delete transmitted messages.
ErrorSMSPath
Where SMSes with error in transmission is placed.
Default is same as SentSMSPath.
InboxFormat
The format in which the SMS will be stored: detail, unicode, standard.
detail format used for message backup by gammu, see gammu-smsbackup.
unicode message text stored in unicode (UTF-16)
standard message text stored in system charset
The standard and unicode settings do not apply for 8-bit messages, which are always written raw as they
are received with extension .bin.
Default is unicode.
Note: In detail format, all message parts are stored into signle file, for all others each message part is saved
separately.
OutboxFormat
The format in which messages created by gammu-smsd-inject will be stored, it accepts same values as Inbox-
Format.
Default is detail if Gammu is compiled in with backup functions, unicode otherwise.
TransmitFormat
The format for transmitting the SMS: auto, unicode, 7bit.
Default is auto.
SMSD allows to process only limited subset of incoming messages. You can define filters for sender number in
[include_numbers] and
[exclude_numbers] sections or using
IncludeNumbersFile and ExcludeNumbersFile directives.
If [include_numbers] section exists, all values (keys are ignored) from it are used as allowed phone numbers
and no other message is processed. On the other side, in [exclude_numbers] you can specify numbers which
you want to skip.
Lists from both sources are merged together. If there is any number in include list, only include list is used and only
messages in this list are being accepted. If include list is empty, exclude list can be used to ignore messages from some
numbers. If both lists are empty, all messages are accepted.
Similar filtering rules can be used for SMSC number filtering, they just use different set of configuration options -
[include_smsc] and
[exclude_smsc] sections or IncludeSMSCFile and ExcludeSMSCFile directives.
4.5 Examples
There is more complete example available in Gammu documentation. Please note that for simplicity following exam-
ples do not include [gammu] section, you can look into gammurc for some examples how it can look like.
SMSD configuration file for FILES backend could look like:
[smsd]
Service = files
PIN = 1234
LogFile = syslog
InboxPath = /var/spool/sms/inbox/
OutboPpath = /var/spool/sms/outbox/
SentSMSPath = /var/spool/sms/sent/
ErrorSMSPath = /var/spool/sms/error/
If you want to use MYSQL backend, you will need something like this:
[smsd]
Service = mysql
PIN = 1234
LogFile = syslog
User = smsd
Password = smsd
PC = localhost
Database = smsd
Enabling debugging:
[smsd]
debuglevel = 255
logfile = smsd.log
FIVE
RUNONRECEIVE DIRECTIVE
5.1 Description
Gammu SMSD can be configured by RunOnReceive directive (see SMSD Configuration File for details) to run
defined program after receiving message.
This parameter is executed through shell, so you might need to escape some special characters and you can include any
number of parameters. Additionally parameters with identifiers of received messages are appended to the command
line. The identifiers depend on used service backend, typically it is ID of inserted row for database backends or file
name for file based backends.
Gammu SMSD waits for the script to terminate. If you make some time consuming there, it will make SMSD not
receive new messages. However to limit breakage from this situation, the waiting time is limited to two minutes. After
this time SMSD will continue in normal operation and might execute your script again.
5.2 Environment
program is executed with environment which contains lot of information about the message. You can use it together
with NULL service (see Null Backend) to implement completely own processing of messages.
SMS_MESSAGES
Number of physical messages received.
DECODED_PARTS
Number of decoded message parts.
The variables further described as SMS_1_... are generated for each physical message, where 1 is replaced by
current number of message.
SMS_1_CLASS
Class of message.
SMS_1_NUMBER
Sender number.
19
Gammu SMSD Daemon Manual, Release 1.29.90
SMS_1_TEXT
Message text. Text is not available for 8-bit binary messages.
The variables further described as DECODED_1_... are generated for each message part, where 1 is replaced by
current number of part. Set are only those variables whose content is present in the message.
DECODED_1_TEXT
Decoded long message text.
DECODED_1_MMS_SENDER
Sender of MMS indication message.
DECODED_1_MMS_TITLE
title of MMS indication message.
DECODED_1_MMS_ADDRESS
Address (URL) of MMS from MMS indication message.
DECODED_1_MMS_SIZE
Size of MMS as specified in MMS indication message.
5.3 Examples
To activate this feature you need to set RunOnReceive in the SMSD Configuration File.
[smsd]
RunOnReceive = /path/to/script.sh
Following script (if used as RunOnReceive handler) passes message data to other program. This works only with
the Files backend.
#!/bin/sh
INBOX=/path/to/smsd/inbox
PROGRAM=/bin/cat
for ID in "$@" ; do
$PROGRAM < $INBOX/$ID
done
Following script (if used as RunOnReceive handler) passes message text and sender to external program.
#!/bin/sh
PROGRAM=/bin/echo
for i in ‘seq $SMS_MESSAGES‘ ; do
eval "$PROGRAM \"\${SMS_${i}_NUMBER}\" \"\${SMS_${i}_TEXT}\""
done
Following script (if used as RunOnReceive handler) will write information about each received MMS indication to
the log file. Just replace echo command with your own program to do custom processing.
#!/bin/sh
if [ $DECODED_PARTS -eq 0 ] ; then
# No decoded parts, nothing to process
exit
fi
if [ "$DECODED_1_MMS_ADDRESS" ] ; then
echo "$DECODED_1_MMS_ADDRESS" "$DECODED_1_MMS_SENDER" "$DECODED_1_MMS_TITLE" >> /tmp/smsd-mms.log
fi
Following script (if used as RunOnReceive handler) written in Python will concatenate all text from received mes-
sage:
#!/usr/bin/python
import os
import sys
numparts = int(os.environ[’DECODED_PARTS’])
5.3. Examples 21
Gammu SMSD Daemon Manual, Release 1.29.90
SIX
BACKEND SERVICES
The backend service is used to store messages (both incoming and queue of outgoing ones).
FILES backend stores all data on a filesystem in folders defined by configuration (see SMSD Configuration File for
description of configuration options).
Transmitted messages are read from a folder defined by configuration. The filename should be one of the following
formats:
• OUT<recipient>.<ext>
• OUT<priority>_<recipient>_<serial>.<ext>
• OUT<priority><date>_<time>_<serial>_<recipient>_<note>.<ext>
Explanation of fields:
23
Gammu SMSD Daemon Manual, Release 1.29.90
SQL service stores all its data in database. It can use one of these SQL backends (configuration option Driver in
smsd section):
• native_mysql for MySQL Backend
• native_pgsql for PostgreSQL Backend
• drivers supported by DBI for DBI Backend, which include:
– sqlite3 - for SQLite 3
– mysql - for MySQL
– pgsql - for PostgeSQL
– freetds - for MS SQL Server or Sybase
%I IMEI of phone
%P PHONE ID (hostname)
%N client name (eg. Gammu 1.12.3)
%R remote number 1
%C delivery datetime
%e delivery status on receiving or status error on sending
%t message reference
%d receiving datetime for received sms
%E encoded text of SMS
%c SMS coding (ie 8bit or UnicodeNoCompression)
%F sms centre number
%u UDH header
%x class
%T decoded SMS text
%A CreatorID of SMS (sending sms)
%V relative validity
1 Sender number for received messages (insert to inbox or delivery notifications), destination otherwise.
All configurable queries can be set in [sql] section. Sequence of rows in selects are mandatory.
All default queries noted here are noted for MySQL. Actual time and time addition are selected for default queries
during initialization.
delete_phone
Deletes phone from database.
Default value:
DELETE FROM phones WHERE IMEI = %I
insert_phone
Inserts phone to database.
Default value:
INSERT INTO phones (IMEI, ID, Send, Receive, InsertIntoDB, TimeOut, Client, Battery, SignalStren
VALUES (%I, %P, %1, %2, NOW(), (NOW() + INTERVAL 10 SECOND) + 0, %N, -1, -1)
save_inbox_sms_update_delivered
Update message delivery status if message was delivered.
Default value:
UPDATE sentitems SET DeliveryDateTime = %C, Status = %1, StatusError = %e WHERE ID = %2 AND TPMR
update_received
Update statistics after receiving message.
Default value:
UPDATE phones SET Received = Received + 1 WHERE IMEI = %I
refresh_send_status
Update messages in outbox.
Default value:
UPDATE outbox SET SendingTimeOut = (NOW() + INTERVAL locktime SECOND) + 0
WHERE ID = %1 AND (SendingTimeOut < NOW() OR SendingTimeOut IS NULL)
Default value:
DELETE FROM outbox WHERE ID=%1
refresh_phone_status
Update phone status (battery, signal).
Default value:
UPDATE phones SET TimeOut= (NOW() + INTERVAL 10 SECOND) + 0,
Battery = %1, SignalStrength = %2 WHERE IMEI = %I
MYSQL backend stores all data in a MySQL database server, which parameters are defined by configuration (see
SMSD Configuration File for description of configuration options).
For tables description see SMSD Database Structure.
This backend is based on SQL Service.
6.3.1 Privileges
The user accessing the database does not need much privileges, the following privleges should be enough:
GRANT USAGE ON *.* TO ’smsd’@’localhost’ IDENTIFIED BY ’password’;
Note: For creating the SQL tables you need more privileges, especially for creating triggers, which are used for some
functionality.
6.3.2 Example
-- --------------------------------------------------------
--
-- Table structure for table ‘daemons‘
--
--
-- Dumping data for table ‘daemons‘
--
-- --------------------------------------------------------
--
-- Table structure for table ‘gammu‘
--
--
-- Dumping data for table ‘gammu‘
--
-- --------------------------------------------------------
--
-- Table structure for table ‘inbox‘
--
‘Coding‘ enum(’Default_No_Compression’,’Unicode_No_Compression’,’8bit’,’Default_Compression’,’Unico
‘UDH‘ text NOT NULL,
‘SMSCNumber‘ varchar(20) NOT NULL default ’’,
‘Class‘ integer NOT NULL default ’-1’,
‘TextDecoded‘ text NOT NULL default ’’,
‘ID‘ integer unsigned NOT NULL auto_increment,
‘RecipientID‘ text NOT NULL,
‘Processed‘ enum(’false’,’true’) NOT NULL default ’false’,
PRIMARY KEY ‘ID‘ (‘ID‘)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Dumping data for table ‘inbox‘
--
-- --------------------------------------------------------
--
-- Table structure for table ‘outbox‘
--
--
-- Dumping data for table ‘outbox‘
--
-- --------------------------------------------------------
--
-- Table structure for table ‘outbox_multipart‘
--
--
-- Dumping data for table ‘outbox_multipart‘
--
-- --------------------------------------------------------
--
-- Table structure for table ‘pbk‘
--
--
-- Dumping data for table ‘pbk‘
--
-- --------------------------------------------------------
--
-- Table structure for table ‘pbk_groups‘
--
--
-- Dumping data for table ‘pbk_groups‘
--
-- --------------------------------------------------------
--
-- Table structure for table ‘phones‘
--
--
-- Dumping data for table ‘phones‘
--
-- --------------------------------------------------------
--
-- Table structure for table ‘sentitems‘
--
--
-- Dumping data for table ‘sentitems‘
--
--
-- Triggers for setting default timestamps
--
DELIMITER //
DELIMITER ;
PGSQL backend stores all data in a PostgreSQL database server, which parameters are defined by configuration (see
SMSD Configuration File for description of configuration options).
For tables description see SMSD Database Structure.
This backend is based on SQL Service.
6.4.1 Example
-- --------------------------------------------------------
--
-- Function declaration for updating timestamps
--
CREATE LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION update_timestamp() RETURNS trigger AS $update_timestamp$
BEGIN
NEW.UpdatedInDB := LOCALTIMESTAMP(0);
RETURN NEW;
END;
$update_timestamp$ LANGUAGE plpgsql;
-- --------------------------------------------------------
--
-- Sequence declarations for tables’ primary keys
--
-- --------------------------------------------------------
--
-- Index declarations for tables’ primary keys
--
-- --------------------------------------------------------
--
-- Table structure for table "daemons"
--
--
-- Dumping data for table "daemons"
--
-- --------------------------------------------------------
--
-- Table structure for table "gammu"
--
--
-- Dumping data for table "gammu"
--
-- --------------------------------------------------------
--
-- Table structure for table "inbox"
--
CHECK (Coding IN
(’Default_No_Compression’,’Unicode_No_Compression’,’8bit’,’Default_Compression’,’Unicode_Compressio
);
--
-- Dumping data for table "inbox"
--
-- --------------------------------------------------------
--
-- Create trigger for table "inbox"
--
CREATE TRIGGER update_timestamp BEFORE UPDATE ON inbox FOR EACH ROW EXECUTE PROCEDURE update_timestam
-- --------------------------------------------------------
--
-- Table structure for table "outbox"
--
--
-- Dumping data for table "outbox"
--
-- --------------------------------------------------------
--
-- Create trigger for table "outbox"
--
CREATE TRIGGER update_timestamp BEFORE UPDATE ON outbox FOR EACH ROW EXECUTE PROCEDURE update_timesta
-- --------------------------------------------------------
--
-- Table structure for table "outbox_multipart"
--
--
-- Dumping data for table "outbox_multipart"
--
-- --------------------------------------------------------
--
-- Table structure for table "pbk"
--
--
-- Dumping data for table "pbk"
--
-- --------------------------------------------------------
--
-- Table structure for table "pbk_groups"
--
--
-- Dumping data for table "pbk_groups"
--
-- --------------------------------------------------------
--
-- Table structure for table "phones"
--
--
-- Dumping data for table "phones"
--
-- --------------------------------------------------------
--
-- Create trigger for table "phones"
--
CREATE TRIGGER update_timestamp BEFORE UPDATE ON phones FOR EACH ROW EXECUTE PROCEDURE update_timesta
-- --------------------------------------------------------
--
-- Table structure for table "sentitems"
--
--
-- Dumping data for table "sentitems"
--
-- --------------------------------------------------------
--
-- Create trigger for table "sentitems"
--
CREATE TRIGGER update_timestamp BEFORE UPDATE ON sentitems FOR EACH ROW EXECUTE PROCEDURE update_time
DBI backend stores all data in any database supported by libdbi, which parameters are defined by configuration (see
SMSD Configuration File for description of configuration options).
For tables description see SMSD Database Structure.
This backend is based on SQL Service.
Note: The DBI driver is currently not supported on Windows because libdbi library does not support this platform.
For complete list of drivers for libdbi see libdbi-drivers project. The drivers for example include:
• sqlite3 - for SQLite 3
• mysql - for MySQL
• pgsql - for PostgeSQL
• freetds - for MS SQL Server or Sybase
6.5.2 Example
);
Note: You can find the script in docs/sql/sqlite.sql as well. There are also scripts for other databases in
same folder.
NULL backend does not store data at all. It could be useful in case you don’t want to store messages at all and you
want to process then in
RunOnReceive handler.
The backends themselves are described in their sections, this document describes general database structure and re-
quired tables.
More SMS daemons can share single database. If you do not specify PhoneID in their configuration, all are treated
equally and you have no guarantee which one sends outgoing message. If you configure PhoneID and use it when
inserting message to the outbox table (gammu-smsd-inject does this), each SMS daemon will have separate outbox
queue.
Transmitted messages are read from table outbox and possible subsequent parts of the same message from
outbox_multipart.
daemons
gammu
Table holding single value - version of a database schema. See HISTORY for details what has changed.
inbox
outbox
Messages enqueued for sending should be placed in this table. If message is multipart, subsequent parts are stored in
table outbox_multipart.
Fields description:
UpdatedInDB (timestamp) when somebody (daemon, user, etc.) updated it
InsertIntoDB (timestamp) when message was inserted into database
SendingDateTime (timestamp) set it to some value, when want to force sending after some planned time
SendBefore (time) Send message before specified time, can be used to limit messages from being sent in night.
Default value is 23:59:59
SendAfter (time) Send message after specified time, can be used to limit messages from being sent in night.
Default value is 00:00:00 New in version 1.29.90.
Text (text) SMS text encoded using hex values in proper coding. If you want to use TextDecoded field, keep this
NULL (or empty). New in version 1.29.90.
DestinationNumber (varchar(20)) recipient number
Coding (enum(‘Default_No_Compression’, ‘Unicode_No_Compression’, ‘8bit’, ‘Default_Compression’, ‘Unicode_Compression
SMS text coding
UDH (text) User Data Header encoded using hex values which will be used for constructing the message. Without
this, message will be sent as plain text.
Class (integer) SMS class or -1 (0 is normal SMS, 1 is flash one)
TextDecoded (varchar(160)) SMS text in “human readable” form
ID (integer unsigned) SMS/SMS sequence ID
Please note that this number has to be unique also for sentitems table, so reusing message IDs might not be a
good idea.
MultiPart (enum(‘false’,’true’)) info, whether there are more SMS from this sequence in outbox_multipart
RelativeValidity (integer) SMS relative validity like encoded using GSM specs
SenderID (text) which SMSD instance should send this one sequence
SendingTimeOut (timestamp) used by SMSD instance for own targets
DeliveryReport (enum(‘default’,’yes’,’no’)) when default is used, Delivery Report is used or not according to
SMSD instance settings; yes forces Delivery Report.
CreatorID (text) sender identification, it has to match PhoneID in SMSD configuration to make SMSD process
this message
outbox_multipart
phones
Information about connected phones. This table is periodically refreshed and you can get information such as battery
or signal level from here.
Fields description:
ID (text) PhoneID value
UpdatedInDB (timestamp) when this record has been updated
InsertIntoDB (timestamp) when this record has been created (when phone has been connected)
TimeOut (timestamp) when this record expires
Send (boolean) indicates whether SMSD is sending messages, depends on configuration directive Send
Receive (boolean) indicates whether SMSD is receiving messages, depends on configuration directive Receive
IMEI (text) IMEI of phone
Client (text) client name, usually string Gammu with version
Battery (integer) battery level in percent (or -1 if unknown)
SignalStrength (integer) signal level in percent (or -1 if unknown) Changed in version 1.29.90: This used to be
called Signal. Renamed because SIGNAL is reserved word in MySQL 5.5.
Sent (integer) Number of sent SMS messages (SMSD does not reset this counter, so it might overflow).
Received (integer) Number of received SMS messages (SMSD does not reset this counter, so it might overflow).
sentitems
Log of sent messages (and unsent ones with error code). Also if delivery reports are enabled, message state is updated
after receiving delivery report.
Fields description:
UpdatedInDB (timestamp) when somebody (daemon, user, etc.) updated it
InsertIntoDB (timestamp) when message was inserted into database
SendingDateTime (timestamp) when message has been sent
DeliveryDateTime (timestamp) Time of receiving delivery report (if it has been enabled).
Status (enum(‘SendingOK’, ‘SendingOKNoReport’, ‘SendingError’, ‘DeliveryOK’, ‘DeliveryFailed’, ‘DeliveryPending’, ‘Del
Status of message sending. SendingError mens that phone failed to send the message, Error indicates some
other error while processing message.
SendingOK Message has been sent, waiting for delivery report.
SendingOKNoReport Message has been sent without asking for delivery report.
SendingError Sending has failed.
pbk
pbk_groups
6.7.4 History
6.7.5 Examples
Creating tables
SQL scripts to create all needed tables for most databases are included in Gammu documentation (docs/sql). As well
as some PHP scripts interacting with the database.
For example to create SQLite tables, issue following command:
sqlite3 smsd.db < docs/sql/sqlite.sql
To send a message, you can either use gammu-smsd-inject, which does all the magic for you, or you can insert the
message manually. The simplest example is short text message:
INSERT INTO outbox (
DestinationNumber,
TextDecoded,
CreatorID,
Coding
) VALUES (
’800123465’,
’This is a SQL test message’,
’Program’,
’Default_No_Compression’
);
Inserting multipart messages is a bit more tricky, you need to construct also UDH header and store it hexadecimally
written into UDH field. Unless you have a good reason to do this manually, use gammu-smsd-inject.
For long text message, the UDH starts with 050003 followed by byte as a message reference (you can put anything
there, but it should be different for each message, D3 in following example), byte for number of messages (02 in
example, it should be unique for each message you send to same phone number) and byte for number of current
message (01 for first message, 02 for second, etc.).
For example long text message of two parts could look like following:
INSERT INTO outbox (
CreatorID,
MultiPart,
DestinationNumber,
UDH,
TextDecoded,
Coding
) VALUES (
’Gammu 1.23.91’,
’true’,
’123465’,
’050003D30201’,
’Mqukqirip ya konej eqniu rejropocejor hugiygydewl tfej nrupxujob xuemymiyliralj. Te tvyjuh qaxum
’Default_No_Compression’
)
Note: Adding UDH means that you have less space for text, in above example you can use only 153 characters in
single message.
SEVEN
DEVELOPER DOCUMENTATION
The backend service is responsible for storing received messages and giving the SMSD core messages to send. It is
solely up to them how the message will be stored, for example currently Gammu includes backends to store messages
on filesystem (smsd_files), various databases (smsd_mysql, smsd_pgsql, smsd_dbi) or backend which does not store
anything at all (smsd_null).
Each backend service needs to support several operations, which are exported in GSM_SMSDService structure:
GSM_Error GSM_SMSDService::Init(GSM_SMSDConfig *Config)
Initializes internal state, connect to backend storage.
Parameters
• Config – Pointer to SMSD configuration data
Returns Error code.
GSM_Error GSM_SMSDService::Free(GSM_SMSDConfig *Config)
Freeing internal data, disconnect from backend storage.
Parameters
• Config – Pointer to SMSD configuration data
Returns Error code.
GSM_Error GSM_SMSDService::InitAfterConnect(GSM_SMSDConfig *Config)
Optional hook called after SMSD is connected to phone, can be used for storing infromation about phone in
backend.
Parameters
• Config – Pointer to SMSD configuration data
Returns Error code.
GSM_Error GSM_SMSDService::SaveInboxSMS(GSM_MultiSMSMessage *sms,
GSM_SMSDConfig *Config, char **Locations)
Saves message into inbox.
Parameters
• sms – Message data to save
51
Gammu SMSD Daemon Manual, Release 1.29.90
7.1.2 Message ID
You might have noticed that message ID is often used in the API. The primary reason for this is that it is usu-
ally easier for backend to handle message just by it’s internal identification instead of handling message data from
GSM_MultiSMSMessage.
If the backend does not use any IDs internally, it really does not have to provide them, with only exception of
GSM_SMSDService::FindOutboxSMS(), where ID is used for detection of repeated sending of same message.
The lifetime of ID for sent message:
• GSM_SMSDService::CreateOutboxSMS() or direct manipulation with backend storage creates new ID
• GSM_SMSDService::FindOutboxSMS() returns ID of message to process
• GSM_SMSDService::AddSentSMSInfo() and GSM_SMSDService::RefreshSendStatus()
are then notified using this ID about sending of the message
• GSM_SMSDService::MoveSMS() then moves the message based on ID to sent items
The lifetime of ID for incoming messages:
• GSM_SMSDService::SaveInboxSMS() generates the message
• RunOnReceive Directive uses this ID
new message
message in storage
FindOutboxSMS
check duplicates
Error GSM_SendSMS
Timeout
AddSentSMSInfo(ERROR) AddSentSMSInfo(OK)
Error
received message
GSM_GetNextSMS
7.2. Message Sending Workflow 55
SMSD_ValidMessage
Gammu SMSD Daemon Manual, Release 1.29.90
57
Gammu SMSD Daemon Manual, Release 1.29.90
58 Index
Gammu SMSD Daemon Manual, Release 1.29.90
GSM_SMSDService::RefreshSendStatus (C function),
53
GSM_SMSDService::SaveInboxSMS (C function), 51
H
Host, 15, 24
I
InboxFormat, 23
IncludeNumbersFile, 17
IncludeSMSCFile, 17
L
LogFile, 11
LogFormat, 11
LoopSleep, 2
O
OutboxPath, 16
P
Password, 24
R
Receive, 46
ReceiveFrequency, 2
ResetFrequency, 2, 13
RunOnReceive, 14, 19–21, 43
S
Send, 46
SentSMSPath, 16
Service, 12
StatusFrequency, 2
U
User, 24
Index 59