Helmsman, hard to port!#
smstools3 is an SMS (Short Message Service) gateway software, enabling sms notifications to be sent via a GSM modem (or phone).
Objectives#
Cover the installation process for the smsd service, and provide the following services
- Send sms messages
- Receive sms messages (not currently implemented)
Prerequisites#
- A platform running OpenBSD, here our RockPro64
- A USB 3g / 4g modem
- A SIM card / 1 subscription without data for example
OpenBSD uses the umsm driver, and the dedicated man page provides an exhaustive list of supported devices.
Installation#
Install the package:
doas pkg_add smstools3
Manage service at startup:
doas rcctl enable smsd
Configuration#
General#
smsd must be able to access the serial port. Let’s add the user _smsd to the dialer group.
doas usermeod -G dialer _smsd
- The working directory :
- Is located in /var/spool/sms/
- Must be readable and writable by _smsd.
- Log files are located in /var/log/smsd/.
- The daemon configuration file is located in /etc
dmesg will provide information on the device to be used.
umsm0 detached
umsm0 at uhub1 port 1 configuration 1 interface 0 "HUAWEI_MOBILE HUAWEI_MOBILE" rev 2.10/1.02 addr 2
ucom0 at umsm0
umsm1 at uhub1 port 1 configuration 1 interface 1 "HUAWEI_MOBILE HUAWEI_MOBILE" rev 2.10/1.02 addr 2
Here the ucom0 device corresponds to /dev/cuaU0.
Daemon#
/etc/smsd.conf
(...)
devices = GSM1
loglevel = 7
(...)
user = _smsd
pidfile = /var/run/smsds/smsd.pid
infofile = /var/run/smsd/smsd.info
logfile = /var/log/smsd/smsd.log
[GSM1]
device = /dev/cuaU0
incoming = yes
rtscts = no
senddelay = 20
(...)
pin=9999
(...)
A PIN code may be required if the SIM card supports a data subscription. The line must not contain anything other than the declaration:
pin=9999
In my case, the service wouldn’t start!
Additional modems can be added via the [GSMx] directive.
Service startup:
doas rcctl start smsd
Test the service#
the modem, waiting to receive the following information:
To: 33612345678
Hello, here is the message to send!
Case 1: sendsms binary#
As the locals are English, we won’t be using French accents.
$ sendsms
Destination(s): 33612345678
Text: Hello, here is the message to send!
--
Text: Hello, here is the message to send!
To: 33612345678
If you have stopped the service upstream, you will find a file in /var/spool/sms/outgoing/ of the form: send_OUgktp
/var/spool/sms/outgoing/send_OUgktp
To: 33612345678
Hello, here is the message to send!
When we restart the service, we see in the logs:
/var/log/smsd/smsd.log
2020-05-15 11:54:47,2, smsd: Smsd v3.1.21 started.
2020-05-15 11:54:47,2, smsd: Running as _smsd:_smsd (590:590).
2020-05-15 11:54:47,7, smsd: Running startup_check (shell): /var/spool/sms/incoming/smsd_script.FvZHG9 /tmp/smsd_data.DFODlw
2020-05-15 11:54:47,7, smsd: Done: startup_check (shell), execution time 0 sec., status: 0 (0)
2020-05-15 11:54:47,4, smsd: File mode creation mask: 022 (0644, rw-r--r--).
2020-05-15 11:54:47,5, smsd: Outgoing file checker has started. PID: 73612.
2020-05-15 11:54:47,7, smsd: All PID's: 73612,18220
2020-05-15 11:54:47,5, GSM1: Modem handler 0 has started. PID: 18220. Will only send messages.
2020-05-15 11:54:47,6, GSM1: Checking if modem is ready
2020-05-15 11:54:48,7, GSM1: -> AT
2020-05-15 11:54:48,5, smsd: SMS To: 33612345678. Moved file /var/spool/sms/outgoing/send_XrgtoZ to /var/spool/sms/checked
2020-05-15 11:54:48,7, GSM1: Command is sent, waiting for the answer. (5)
2020-05-15 11:54:48,7, GSM1: <- OK
2020-05-15 11:54:48,6, GSM1: Pre-initializing modem
2020-05-15 11:54:48,7, GSM1: -> ATE0
2020-05-15 11:54:48,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:48,7, GSM1: <- OK
2020-05-15 11:54:48,7, GSM1: -> AT+CMEE=1;+CREG=2
2020-05-15 11:54:48,5, smsd: SMS To: 33612345678. Moved file /var/spool/sms/outgoing/send_OUgktp to /var/spool/sms/checked
2020-05-15 11:54:49,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:49,7, GSM1: <- ^DSFLOWRPT:000001B1,00000000,00000000,0000000000000000,0000000000000000,00000000,00000000 OK
2020-05-15 11:54:49,6, GSM1: Checking if modem needs PIN
2020-05-15 11:54:49,7, GSM1: -> AT+CPIN?
2020-05-15 11:54:49,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:49,7, GSM1: <- +CPIN: READY OK
2020-05-15 11:54:50,7, GSM1: -> AT+CSQ
2020-05-15 11:54:50,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:50,7, GSM1: <- +CSQ: 14,99 OK
2020-05-15 11:54:50,6, GSM1: Signal Strength Indicator: (14,99) -85 dBm (Workable), Bit Error Rate: not known or not detectable
2020-05-15 11:54:50,6, GSM1: Checking if Modem is registered to the network
2020-05-15 11:54:50,7, GSM1: -> AT+CREG?
2020-05-15 11:54:50,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:50,7, GSM1: <- +CREG: 2,1,"183A","0620AB3E" OK
2020-05-15 11:54:50,6, GSM1: Modem is registered to the network
2020-05-15 11:54:50,6, GSM1: Location area code: 183A, Cell ID: AB3E
2020-05-15 11:54:50,7, GSM1: -> AT+CSQ
2020-05-15 11:54:51,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:51,7, GSM1: <- +CSQ: 14,99 OK
2020-05-15 11:54:51,6, GSM1: Signal Strength Indicator: (14,99) -85 dBm (Workable), Bit Error Rate: not known or not detectable
2020-05-15 11:54:51,6, GSM1: Selecting PDU mode
2020-05-15 11:54:51,7, GSM1: -> AT+CMGF=0
2020-05-15 11:54:51,7, GSM1: Command is sent, waiting for the answer. (5)
2020-05-15 11:54:51,7, GSM1: <- ^DSFLOWRPT:000001B3,00000000,00000000,0000000000000000,0000000000000000,00000000,00000000 OK
2020-05-15 11:54:51,7, GSM1: -> AT+CGSN
2020-05-15 11:54:52,7, GSM1: Command is sent, waiting for the answer. (5)
2020-05-15 11:54:52,7, GSM1: <- 123456789101112 OK
2020-05-15 11:54:52,5, GSM1: IMEI: 123456789101112
2020-05-15 11:54:52,7, GSM1: -> AT+CIMI
2020-05-15 11:54:52,7, GSM1: Command is sent, waiting for the answer. (5)
2020-05-15 11:54:52,7, GSM1: <- 234567891011121 OK
2020-05-15 11:54:52,5, GSM1: IMSI: 234567891011121
2020-05-15 11:54:52,5, GSM1: Waiting for messages to send...
2020-05-15 11:54:52,6, GSM1: I have to send 1 short message for /var/spool/sms/checked/send_OUgktp
2020-05-15 11:54:52,6, GSM1: Sending SMS from to 33612345678
2020-05-15 11:54:52,6, GSM1: Checking if modem is ready
2020-05-15 11:54:52,7, GSM1: -> AT
2020-05-15 11:54:52,7, GSM1: Command is sent, waiting for the answer. (5)
2020-05-15 11:54:52,7, GSM1: <- OK
2020-05-15 11:54:52,6, GSM1: Pre-initializing modem
2020-05-15 11:54:52,7, GSM1: -> ATE0
2020-05-15 11:54:53,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:53,7, GSM1: <- OK
2020-05-15 11:54:53,7, GSM1: -> AT+CMEE=1;+CREG=2
2020-05-15 11:54:54,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:54,7, GSM1: <- ^DSFLOWRPT:000001B5,00000000,00000000,0000000000000000,0000000000000000,00000000,00000000 OK
2020-05-15 11:54:54,6, GSM1: Checking if modem needs PIN
2020-05-15 11:54:54,7, GSM1: -> AT+CPIN?
2020-05-15 11:54:54,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:54,7, GSM1: <- +CPIN: READY OK
2020-05-15 11:54:54,7, GSM1: -> AT+CSQ
2020-05-15 11:54:54,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:54,7, GSM1: <- +CSQ: 14,99 OK
2020-05-15 11:54:54,6, GSM1: Signal Strength Indicator: (14,99) -85 dBm (Workable), Bit Error Rate: not known or not detectable
2020-05-15 11:54:54,6, GSM1: Checking if Modem is registered to the network
2020-05-15 11:54:55,7, GSM1: -> AT+CREG?
2020-05-15 11:54:55,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:55,7, GSM1: <- +CREG: 2,1,"183A","0620AB3E" OK
2020-05-15 11:54:55,6, GSM1: Modem is registered to the network
2020-05-15 11:54:55,6, GSM1: Selecting PDU mode
2020-05-15 11:54:55,3, GSM1: Unexpected input: ^DSFLOWRPT:000001B7,00000000,00000000,0000000000000000,0000000000000000,00000000,00000000
2020-05-15 11:54:55,7, GSM1: -> AT+CMGF=0
2020-05-15 11:54:56,7, GSM1: Command is sent, waiting for the answer. (5)
2020-05-15 11:54:56,7, GSM1: <- OK
2020-05-15 11:54:56,7, GSM1: -> AT+CMGS=47
2020-05-15 11:54:56,7, GSM1: Command is sent, waiting for the answer. (10)
2020-05-15 11:54:56,7, GSM1: <- >
2020-05-15 11:54:56,7, GSM1: -> 0011000B913386747787F30000FF25C2B75BFDAECB5920FB3B3D4E83D86550BB3C9F87CF6550185476DBDFF9B21C1402
2020-05-15 11:55:00,7, GSM1: Command is sent, waiting for the answer. (60)
2020-05-15 11:55:00,7, GSM1: <- ^DSFLOWRPT:000001B9,00000000,00000000,0000000000000000,0000000000000000,00000000,00000000 ^DSFLOWRPT:000001BB,00000000,00000000,0000000000000000,0000000000000000,00000000,00000000 +CMGS: 109 OK
2020-05-15 11:55:00,5, GSM1: SMS sent, Message_id: 109, To: 33612345678, sending time 8 sec.
2020-05-15 11:55:00,6, GSM1: Deleted file /var/spool/sms/checked/send_OUgktp>
You should have received the message, as shown above.
To make the logs less verbose, without the AT commands, you could, for example, lower the loglevel value to 5.
Case 2: Submitting a text file.#
The service is started.
create a file mySMS-toSend in your directory:
echo "To: 3312345678" >> mySMS_toSend
echo "" >> mySMS_toSend
echo "Hello, this is my second message!" >> mySMS_toSend
mv mySMS_toSend /var/spool/sms/outgoing
The file has been sent, it has been received, let’s analyze the logs at level 5:
2020-05-21 12:22:23,5, smsd: SMS To: 33612345678. Moved file /var/spool/sms/outgoing/mySMS_toSend to /var/spool/sms/checked
2020-05-21 12:22:23,3, GSM1: Unexpected input: ^RSSI:16 ^HCSQ:"LTE",40,26,76,14 ^RSSI:14 ^HCSQ:"LTE",37,27,76,22 ^RSSI:14 ^HCSQ:"LTE",37,26,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,76,22 ^RSSI:14 ^HCSQ:"LTE",37,27,76,20 ^RSSI:16 ^HCSQ:"LTE",40,27,76,16 ^RSSI:16 ^HCSQ:"LTE",40,28,76,16 ^RSSI:14 ^HCSQ:"LTE",37,26,66,18 ^RSSI:14 ^HCSQ:"LTE",37,27,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,76,20 ^RSSI:15 ^HCSQ:"LTE",38,27,71,20 ^RSSI:16 ^HCSQ:"LTE",40,27,76,16 ^RSSI:14 ^HCSQ:"LTE",37,27,76,20 ^RSSI:14 ^HCSQ:"LTE",37,27,76,20 ^RSSI:15 ^HCSQ:"LTE",39,27,76,16 ^RSSI:15 ^HCSQ:"LTE",38,26,71,18 ^RSSI:15 ^HCSQ:"LTE",38,27,66,18 ^RSSI:14 ^HCSQ:"LTE",37,27,76,22 ^RSSI:14 ^HCSQ:"LTE",37,27,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,76,20 ^RSSI:14 ^HCSQ:"LTE",37,26,76,20 ^RSSI:14 ^HCSQ:"LTE",37,26,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,71,22 ^RSSI:14 ^HCSQ:"LTE",37,26,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,76,20 ^RSSI:14 ^HCSQ:"LTE",37,27,76,22 ^RSSI:16 ^HCSQ:"LTE",40,27,76,16 ^RSSI:15 ^HCSQ:"LTE",38,26,66,18 ^RSSI:14 ^HCSQ:"LTE",36,27,76,22 ^RSSI:14 ^HCSQ:"LTE",37,27,76,20 ^RSSI:16 ^HCSQ:"LTE",40,27,76,14 ^RSSI:14 ^HCSQ:"LTE",37,27,76,22 ^RSSI:15 ^HCSQ:"LTE",38,27,71,18 ^RSSI:14 ^HCSQ:"LTE",36,26,71,20 ^RSSI:15 ^HCSQ:"LTE",38,27,76,20 ^RSSI:14 ^HCSQ:"LTE",37,27,81,22 ^RSSI:14 ^HCSQ:"LTE",37,26,71,20 ^RSSI:14 ^HCSQ:"LTE",37,26,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,71,22 ^RSSI:14 ^HCSQ:"LTE",37,27,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,76,20 ^RSSI:14 ^HCSQ:"LTE",37,27,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,76,22 ^RSSI:14 ^HCSQ:"LTE",37,27,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,71,20 ^RSSI:14 ^HCSQ:"LTE",37,27,71,20 ^RSSI:15 ^HCSQ:"LTE",38,27,71,20 ^RSSI:15 ^HCSQ:"LTE",38,27,71,20 ^RSSI:16 ^HCSQ:"LTE",40,27,71,14 ^RSSI:14 ^HCSQ:"LTE",37,27,71,20 ^RSSI:15 ^HCSQ:"LTE",39,27,71,16
2020-05-21 12:22:30,5, GSM1: SMS sent, Message_id: 111, To: 33612345678, sending time 7 sec.
Verbosity: 3 log lines.