How to send SMS through GSM modem in Ubuntu
Equipment and specifications:
- Khadas VIM4 (SKU: KVIM4-N-02)
- Quectel EM06 4G LTE Module (SKU: K-LTE-002) (EM06-E - EMEA / APAC / Brazil)
- New M2X Extension (SKU: KM2X-V-002)
- 30W USB-C Adapter (SKU: KP30W-EU-002) (EU + USB-C Cable)
- Free telecom SIM Card (EU)
- Ubuntu 22.04.3 LTS jammy (installed via OOWOW)
- gnokii 0.6.31
IMPORTANT: I am assuming the GSM modem (Quectel EM06) is already connected to the SBC, a working SIM card is inserted and in status registered getting a strong enough signal.
- First thing to do is to install
gnokii
andgnokii-cli
with the following command:
sudo apt install gnokii gnokii-cli
- Once installed we need to create a configuration file. I found a sample configuration file located at
/etc/xdg/gnokii/config
(config
is the name of the file). I copied this file to/etc/
with the following command:
khadas@Khadas:/etc# sudo cp /etc/xdg/gnokii/config /etc/.gnokiirc
- In my case there was two parameters to modify:
port
was set to/dev/ttyUSB2
because I know that for my specific setup that is where my GSM modem is.model
was set toAT
because that will work for any other device that is not specific phones mentioned in the documentation.- I added the telephone number of the SIM card used (including the country code) in the sections shown here:
[connect_script] TELEPHONE = +99123456789 [disconnect_script] TELEPHONE = +99123456789
- I ran the following command to identify the GSM modem with
gnokii
passing the configuration file as a parameter:
khadas@Khadas:~$ sudo gnokii --config /etc/.gnokiirc --identify
[sudo] password for khadas:
GNOKII Version 0.6.31
IMEI : 866680042214330
Manufacturer : Quectel
No flags section in the config file.
Model : EM06
Product name : EM06
Revision : EM06ELAR04A04M4G
- I can now send the SMS with the following command:
khadas@Khadas:~$ echo "Hello from Ubuntu @ Khadas VIM 4. Sent with gnokii 0.6.31" | sudo gnokii --config /etc/.gnokiirc --sendsms +340123456789 -r
GNOKII Version 0.6.31
Cannot read the SMSC number from your phone. If the sms send will fail, please use --smsc option explicitely giving the number.
Send succeeded with reference 28!
I am using the +
symbol because I provide the country code and the phone number together.
NOTE: Sometimes the SMS will fail to send, for example:
khadas@Khadas:~$ echo "Hello from Ubuntu @ Khadas VIM 4. Sent with gnokii 0.6.31" | sudo gnokii --config /etc/.gnokiirc --sendsms +340123456789 -r
GNOKII Version 0.6.31
Lockfile /var/lock/LCK..ttyUSB2 is stale. Overriding it...
SMS Send failed (Command timed out.)
I don't know exactly why this happens but after running the command again it was successful. I still need to do more research and testing on the subject.
Here are the results:
From the image above the proof is the last message displayed (Sunday, January 7 at 12:40 AM)
From the image above the notification on my watch.
That's it. Not as easy as it seems but at the end of the day it worked.
Sources:
- https://linux.die.net/man/1/gnokii
- https://www.mankier.com/package/gnokii
- https://www.mankier.com/1/gnokii#Options-SMS
- Chat GPT - Prompt: "how can I send an SMS using gnokii"