Sending sms from command line on pinephone postmarketos
I want to send sms from command line with my pinephone because my previous solution will stop working soon.
In my previous solution, a 2G/3G phone was connected to a computer with a USB cable and I was using gammu to send the sms.
This will stop working since the 2G and 3G networks will be shutdown to free bandwidth for 5G.
postmarketos
I installed Mobian (stable and latest on 20240928) and the modem was not working.
I installed Maemo leste and the moden also was not working.
With postmarketos phosh, I can call, send and receive sms.
I started the SSH server with these commands (openrc):
# Start ssh
sudo service sshd start
# Enable the service on every boot:
sudo rc-update add sshd
I had issues logging in with public key as root, as password needs to be set for root to enable root login:
Login with username "root" fails
After having put a good /root/.ssh/authorized_keys file into the root account (maybe just by copying the user account's one), if it still fails to get in, it is because the root account is disabled (no password is set). To enable public key SSH login with the root account you have to set a password for the root user first.
Searching for a solution
In my previous solution, I was using gammu. On the pinephone, gammu crashes the modem when trying to send an sms, I used /dev/ttyUSB* devices.
I saw libofono.so in the system, so I installed ofono-scripts but the send-sms script has errors and ofonod crashes with a segfault.
apk add ofono-scripts
/usr/lib/ofono/test/send-sms /quectelqmi_0 +nnnnnnnnnn "Hello world!" 0
Send message using modem /quectelqmi_0 ...
Traceback (most recent call last): File "/usr/lib/python3.12/site-packages/dbus/bus.py", line 173, in activate_name_owner
return self.get_name_owner(bus_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/dbus/bus.py", line 348, in get_name_owner
return self.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/dbus/connection.py", line 634, in call_blocking
reply_message = self.send_message_with_reply_and_block(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.ofono': no such name
I can send sms with chatty (created by purism and under gnome now), so I looked at the source code and saw that ModemManager is used to send sms.
The cli program for ModemManager is mmcli.
How to send sms from command line
The modem crashes often and it is restarted like this:
#classic
/etc/init.d/eg25-manager restart
#or
rc-service eg25-manager restart
# let the modem connect to the mobile network
sleep 30
The icons (4G...) disappear when eg25-manager is not running, it checked from command line with:
rc-status
#and
rc-status --crashed
The mmcli -L shows the modem path and when the list is empty, the modem is stopped. It also happens that the modem changes index over time.
The steps to send an sms with mmcli are:
- Find modem index with
mmcli -L - Create an SMS with the
--message-create-smsoption - Send the SMS with
--sms SMS_INDEX --send - Delete the SMS with
--messaging-delete-sms
$ mmcli -L
/org/freedesktop/ModemManager1/Modem/0 [QUALCOMM INCORPORATED] QUECTEL Mobile Broadband Module
$ mmcli -m 0 --messaging-create-sms="number=nnnnnnnn,text='it works'"
------------------------
Messaging | created sms: /org/freedesktop/ModemManager1/SMS/2
$ mmcli -m 0 --sms 2 --send
successfully sent the SMS
$ mmcli -m 0 --messaging-delete-sms=2
successfully deleted SMS from modem
The command to list already created SMS is:
$ mmcli -m 0 --messaging-list-sms
/org/freedesktop/ModemManager1/SMS/2 (unknown)
mmcli
-L, --list-modems
List available modems. Last number in path is modem index
Hashtags: #pinephone #postmarketos #cli #linux #smartphone