Send AT command with a Script

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Send AT command with a Script

15,505 Views
enaud
Contributor III

Hi all,
How to write a script for send AT commands to modem?
I can use only Screen because LTIB Failed when I select Minicom package

Is possible run a script that open Screen and after write AT command like:

AT+CGREG
AT!PADCONF?1
....etc..

I will also do a check on the answers that I receive:

if [response from AT+CGREG] != 'ok'
echo 'ERROR'
else
echo 'no error'

PS: I can install minicom on my board manually without LTIB?


thanks for your help
Regards

Labels (1)
0 Kudos
6 Replies

4,522 Views
enaud
Contributor III

how can control answer of modem?

i must do a little script that send AT command at ttyUSB3 on 
my iMX53 and control his answers for example: 

- Set serial port ttyUSB3 115200 8N1 

- if ttyUSB3 not exist print "MODEM NOT CONNECTED": 

if ! [ -e /dev/ttyUSB3 ]; then 
echo 'MODEM NOT CONNECTED' 
exit 0 
fi 

send AT -> the answer must be OK 
else print "ERROR AT number 1" and resend AT and if 
response is still different from OK then Print "ERROR AT 
number 2" and exit from script. 

If response precedent is OK then do the same thing for 
'AT!PADSETUP=1,2,82.91.28.127,0,9940,0,1' --> the answer 
must be ok and else resend command and etc... 

If response precedent is OK then do the same thing for 
'AT!PADCONN=1' --> the answer must be ok and else resend 
command and etc... 

If is ALL OK print "MODEM CONNECT TO SOCKET" 

I saw on the network many script but i have problem with use 
of stty /dev/ttyUSB3 115200 because i have this error: stty: 
/dev/ttyUSB3: 
unable to perform all requested operations 

I' ve doing a little script but i not have control of his answers: 


#! /bin/sh 

cat /dev/ttyUSB3 /home/giuseppe/Scrivania/imsi.txt & 
sleep 1 
# stty ispeed 115200 ospeed 115200 -echo not work! 
# echo AT > /dev/ttyUSB3 not work! 
chat -V -s '' 'AT+creg?' '' > /dev/ttyUSB3 < /dev/ttyUSB3 
sleep 2 
chat -V -s '' 'AT' '' > /dev/ttyUSB3 < /dev/ttyUSB3 
sleep 2 
chat -V -s '' 'AT!PADSETUP=1,2,82.91.28.127,0,9940,0,1' '' > 
/dev/ 
ttyUSB3 < /dev/ttyUSB3 
sleep 2 
chat -V -s '' 'AT+CGDCONT=1,"IP","web.omnitel.it"' '' > 
/dev/ttyUSB3 
< /dev/ttyUSB3 
sleep 2 
chat -V -s '' 'AT!PADCONN=1' '' > /dev/ttyUSB3 < 
/dev/ttyUSB3 
sleep 10 
killall cat 
exit 0 


In short i need controll his answers 

I hope that you help me... 
THANKS for help!!
0 Kudos

4,522 Views
enaud
Contributor III

I think that i have resolved with this script:
#! /bin/sh

cat /dev/ttyUSB3 /home/giuseppe/Scrivania/imsi.txt &
sleep 1
# stty ispeed 115200 ospeed 115200 -echo
# echo AT > /dev/ttyUSB3
chat -V -s '' 'AT+creg?' '' > /dev/ttyUSB3 < /dev/ttyUSB3
sleep 2
chat -V -s '' 'AT' '' > /dev/ttyUSB3 < /dev/ttyUSB3
sleep 2
killall cat
exit 0

what do you think?

and now how i can read answers and put in variables?

thanks

0 Kudos

4,522 Views
G_rio
Contributor III

nice, congratulation

Post your solution to help another users

0 Kudos

4,522 Views
enaud
Contributor III

i've resolved

0 Kudos

4,522 Views
enaud
Contributor III

I need a script that i launched from the shell of the board iMX53 sending a series of AT commands to the modem that is connected to ttyUSB3. I only have "screen" installed on the board because minicomgives problems ... For example:

#! / bin / bash
Screen / dev/ttyUSB3 115200
send command AT + cgreg
sleep 2
$ Answer = read answer1
send command AT + cgreg
sleep 2
$ Answer = read Answer2


what is pppd? can you give me scrpt?

thanks

0 Kudos

4,522 Views
G_rio
Contributor III
Hello enaud, I dont know what do you want to do, but if you are trying to use 3g, look pppd i have a script to connect but isnt with me now.
0 Kudos