LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 07-19-2023, 12:34 AM   #1
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Rep: Reputation: Disabled
SierraWirelessAirPrime_MC7304_sms


Hi Folks,

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.

Thanks
 
Old 07-20-2023, 02:19 AM   #2
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
I'm doing this in 1 terminal:

Code:
echo -ne 'ATI\r\n' > /dev/ttyUSB0
echo -ne 'ATI\r\n' > /dev/ttyUSB1
echo -ne 'ATI\r\n' > /dev/ttyUSB2
and reading in another terminal from all possible variations:

Code:
tail -f /dev/ttyUSB0
tail -f /dev/ttyUSB1
tail -f /dev/ttyUSB2

Last edited by kzo81; 07-20-2023 at 02:26 AM.
 
Old 07-20-2023, 08:06 AM   #3
nehakwilas
LQ Newbie
 
Registered: Jul 2023
Location: india
Distribution: radhat
Posts: 7

Rep: Reputation: 1
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()
 
1 members found this post helpful.
Old 07-20-2023, 01:47 PM   #4
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
I see :-) but I dont have python on that device, is it doable in bash?
 
Old 07-20-2023, 03:12 PM   #5
nehakwilas
LQ Newbie
 
Registered: Jul 2023
Location: india
Distribution: radhat
Posts: 7

Rep: Reputation: 1
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
 
Old 07-20-2023, 03:13 PM   #6
nehakwilas
LQ Newbie
 
Registered: Jul 2023
Location: india
Distribution: radhat
Posts: 7

Rep: Reputation: 1
You can use the echo command to send AT commands to the modem and cat or tail to read the responses from the modem.
 
Old 07-20-2023, 03:14 PM   #7
nehakwilas
LQ Newbie
 
Registered: Jul 2023
Location: india
Distribution: radhat
Posts: 7

Rep: Reputation: 1
Save the file as sms_processing.sh with x permission
Try if this work to you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration