How to send SMS through GSM modem in Ubuntu

Equipment and specifications:

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.

  1. First thing to do is to install gnokii and gnokii-cli with the following command:
sudo apt install gnokii gnokii-cli
  1. 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
  1. In my case there was two parameters to modify:
    1. port was set to /dev/ttyUSB2 because I know that for my specific setup that is where my GSM modem is.
    2. model was set to AT because that will work for any other device that is not specific phones mentioned in the documentation.
    3. 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
    
  2. 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
  1. 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:

Screenshot_20240107_004140_Messages

From the image above the proof is the last message displayed (Sunday, January 7 at 12:40 AM)

20240107_004111

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: