Friday, March 24, 2023

Using a Pine Phone as a SMS gateway - Part 2

I've noticed that SMS messages weren't being sent and discovered that  mmcli -L  was yielding  No modems were found . This is annoying. After checking through several online forums where folks reported similar disappearing modems, including one that turned out to be a hardware failure (hopefully not my problem!), I ran across a suggestion to change  /usr/lib/udev/rules.d/80-modem-eg25.rules  to replace  {power/control}="auto"  with  {power/control}="on"  and then issued a  systemctl restart udev  for good measure.

 

We'll see how it goes...

Friday, February 24, 2023

Using a Pine Phone as a SMS gateway

Having become disenchanted with the unreliability of using email to send SMS messages, I decided that it was finally worth the cost and effort to add a new line to my mobility account and use that SIM card in a modem that is capable of sending SMS directly.

I started with a modem from Amazon. This was a "OSTENT WCDMA/UMTS/HSDPA/HSPA+/FDD-LTE 4G Modem with SIMCOM SIM7600A Module USB Port at Commands Bulk SMS MMS TCP/IP" modem which, based on the description, seemed like exactly what I wanted. Unfortunately, the item I received was either a lemon or just not friendly with the AT&T network. After many hours of fiddling with it, and struggling with zero documentation, I threw in the towel and returned it.

Next I picked up a "4G LTE" USB modem dongle from Aliexpress. At $10 it was an order of magnitude less expensive than the OSTENT modem and I figured it was worth the gamble. Upon arrival and attachment to PC I found that this dongle was actually a WIFI to LTE router, which isn't exactly what I needed, but I figured I could just ignore the WIFI functionality and just try to manipulate the LTE modem directly. I discovered that this dongle actually runs Android 4.4.4 (KitKat) and that I could attempt to send SMS directly via the adb shell. This was exciting and seemed to be exactly what I was looking for. Unfortunately, again, I found that even though i was sending properly formatted service commands to the modem via the adb shell, the messages never got sent. I assume that there was just something not exactly right about the APN, SMSC, or other parameters, or perhaps it was just that AT&T wasn't allowing (whitelisting) the IMEI. Whatever the cause, this was another failure that didn't seem immediately surmountable. I'll store this dongle away for future experimentation.

Finally, I pulled out my old Pine Phone (running Mobian) and discovered the (relative) pure bliss of the mmcli interface. Within ten minutes I had worked out the command structure I needed and wrote a base script that would discover the modem id, craft the SMS for that modem, and then send the SMS. It works beautifully, and I can send SMS from various machines on the network using SSH to the Pine Phone to invoke the bash script. It's just fantastic.

Actually, let me step back for one minute. The initial attempts to send SMS from the Pine Phone failed. I was following some steps to enable the modem via mmcli and was running into the following:




mobian@mobian:~$ mmcli -L
    /org/freedesktop/ModemManager1/Modem/0 [QUALCOMM INCORPORATED] QUECTEL Mobile Broadband Module
mobian@mobian:~$ sudo mmcli -m 0 -e
[sudo] password for mobian: 
error: couldn't enable the modem: 'GDBus.Error:org.freedesktop.ModemManager1.Error.Core.WrongState: modem in failed state'
mobian@mobian:~$ sudo mmcli -m 0 --messaging-create-sms="text='Hello world',number='+1xxxxxxxxxx'"
error: modem not enabled yet
mobian@mobian:~$

 

It turns out that the "chatty" messaging application in Mobian was preventing mmcli from manipulating the modem. I renamed /usr/bin/chatty and killed the existing chatty process to release the modem and instantly mmcli started behaving as expected and I was off and running.

The friendly Linux environment of Mobian on the Pine Phone is just a dream compared to the nightmare of the undocumented OSTENT interface and the frustration of the Android dongle. Yeah, using a full-blown phone to perform this function is overkill and more expensive than it should have been, but I had the Pine Phone already from previous tinkering and it was just sitting on the shelf doing nothing, and now it's serving a useful purpose again.

BONUS - Here is the intial script I wrote to accept the target phone number and message as arguments. This is then easily invoked either locally or via ssh (zero interaction if using keys) from a remote host. Perhaps it's useful as a starting place for you.




#!/usr/bin/env bash

_DEST_NUMBER=$1
shift
_SMS_MESSAGE="$@"

echo "Sending \"${_SMS_MESSAGE}\" to ${_DEST_NUMBER}"

_MODEM_NUM=$(basename $(mmcli -L | awk '{print $1;}'))

_MESSAGE_CREATION=$(mmcli -m ${_MODEM_NUM} --messaging-create-sms="text='${_SMS_MESSAGE}',number='${_DEST_NUMBER}'")

_MESSAGE_ID=$(basename "${_MESSAGE_CREATION}")

mmcli -m ${_MODEM_NUM} -s ${_MESSAGE_ID} --send

exit 0

 

That's all for today.