Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I got this device working with qmi driver. However I'd like to process sms commands as well.
Do you have any idea how can I process an incoming sms that is "status" and the the device would reply it's state, rssi, etc". I didnt find sms section in the qmi driver.
Hi,
I did use Python and the pyserial library to send and receive SMS messages using AT commands.
Code:
import serial
# Replace '/dev/ttyUSB0' with the appropriate serial port for your modem
ser = serial.Serial('/dev/ttyUSB0', baudrate=115200, timeout=1)
# Function to send an AT command and read the response
def send_at_command(command):
ser.write(command.encode() + b'\r\n')
response = ser.read(1024).decode('utf-8')
return response.strip()
# Check if the modem is ready
response = send_at_command('AT')
if 'OK' not in response:
print('Modem not ready or not responding to AT commands.')
ser.close()
exit()
# Set the SMS text mode
send_at_command('AT+CMGF=1')
# Read an incoming SMS message
response = send_at_command('AT+CMGR=1')
# Process the response to extract the SMS content and sender information
if '+CMGR:' in response:
sms_index = response.index('+CMGR:')
sms_content = response[sms_index:].split('\n', 2)[2].strip()
print('Received SMS:')
print(sms_content)
# Close the serial connection
ser.close()
Yes it is possible to interact using bash scripts..
Quote:
#!/bin/bash
# Replace '/dev/ttyUSB0' with the appropriate serial port for your modem
modem_port='/dev/ttyUSB0'
# Function to send an AT command and read the response
function send_at_command() {
echo -ne "$1\r\n" > "$modem_port"
sleep 1 # Wait for the response (adjust the sleep duration if needed)
cat "$modem_port"
}
# Check if the modem is ready
response=$(send_at_command 'AT')
if [[ $response != *"OK"* ]]; then
echo "Modem not ready or not responding to AT commands."
exit 1
fi
# Set the SMS text mode
send_at_command 'AT+CMGF=1'
# Read an incoming SMS message
response=$(send_at_command 'AT+CMGR=1')
# Process the response to extract the SMS content and sender information
if [[ $response == *'+CMGR:'* ]]; then
sms_index=$(echo "$response" | grep -b -o '+CMGR:' | cut -d: -f1)
sms_content=$(echo "$response" | tail -n +$((sms_index+1)) | sed '1,2d')
echo "Received SMS:"
echo "$sms_content"
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.