Hello everyone,
I wanted to update you all on my progress regarding the issue I was having with sending automated SMS messages using Python scripts on my GL-Inet Spitz AX router. I found a solution using a shell script instead of Python, which I hope will be useful for others facing similar challenges.
Here’s the working script:
sms_automation.sh
#!/bin/sh
echo "Start SMS Monitor..."
MODEM="/dev/mhi_DUN"
while true; do
# Set the modem to text mode
echo -e "AT+CMGF=1\r" > $MODEM
sleep 1
# Read all SMS messages with a timeout to prevent hanging
echo -e "AT+CMGL=\"ALL\"\r" > $MODEM; timeout 5 cat $MODEM
# Variable RESPONSE is not needed here as we do not programmatically react to the content
# If you need to store and process contents, RESPONSE should be used
RESPONSE=$(echo -e "AT+CMGL=\"ALL\"\r" > $MODEM; timeout 5 cat $MODEM)
# Check if an SMS with "Start" was received
if echo "$RESPONSE" | grep -q "Start"; then
echo "Start message found. Sending response SMS."
# Send the response SMS
(echo -e "AT+CMGF=1\r"; echo -e "AT+CMGS=\"+49xxxxxxxxx\"\r"; echo -e "Test successful\x1A") > $MODEM
sleep 1
echo "Response SMS sent."
fi
# Delete all SMS messages in storage
echo -e "AT+CMGD=1,4\r" > $MODEM
sleep 1
echo "All messages deleted."
# Wait 25 seconds before the next check
sleep 25
done
To ensure that the timeout
command is available on your OpenWRT router, you might need to install it if it’s not already available. You can install it with the following commands:
opkg update
opkg install coreutils-timeout
I hope this script helps anyone looking to automate SMS handling on their routers. If you have any questions or suggestions for improvement, feel free to share!