Little script with minicom


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Little script with minicom
# 15  
Old 04-19-2012
Quote:
Originally Posted by enaud
I have doing a script :
This is a script you already had? Did it ever work? Smilie

Quote:
Originally Posted by enaud
but i not have a control!
What do you mean?

Quote:
Originally Posted by enaud
Sorry but i not undstand this string:
exec 3<&1 >"$modem" <"$modem"

you can explain me, thank!
You see you do "</dev/ttyUSB3 >/dev/ttyUSB3" after each chat. By using exec, we basically permanently redirect. First though we copy the current stdout to 3 so we can use it later to print messages. So in this way, the modem is not open/closed between programs, which I found may cause problems with some things ...

Your script doesn't use chat to it's ability. It doesn't check response. To avoid quoting issues, place this in a separate file (ie: omnitel.chat)
Code:
ABORT    'NO CARRIER'
ABORT    ERROR
''       AT+CREG?
OK       'AT!PADSETUP=1,2,82.91.28.127,0,9940,0,1'
OK       'AT+CGDCONT=1,"IP","web.omnitel.it"'
OK       'AT!PADCONN=1'
CONNECT  '\c'

Then your shell code would be easier
Code:
modem=/dev/ttyUSB3
file=/home/giuseppe/Scrivania/imsi.txt
chat_script=/home/giuseppe/Scrivania/omnitel.chat

exec 3<&1 >"$modem" <"$modem"
stty 115200 clocal ...etc...
if chat -v -s -f "${chat_script}"; then
    echo "error setup modem" >&2
    exit 1
fi
cat "$file"
echo "done" >&3


Last edited by neutronscott; 04-19-2012 at 09:17 PM.. Reason: fix chat script
# 16  
Old 04-19-2012
My script work.. tomorrow i test your.
what is in your script stty etc... ? I need 115200 8n1
# 17  
Old 04-19-2012
Quote:
Originally Posted by enaud
My script work.. tomorrow i test your.
what is in your script stty etc... ? I need 115200 8n1
I've never encountered the options not already set for 8N1, usually just putting the speed is enough and maybe setting flow control. "stty 115200 raw" seems to set it up OK. I connected my cell phone and tried the script and it work.
# 18  
Old 04-20-2012
Ok.. I have this error with your script
Code:
root@ubuntu:~/Desktop/SCRIPTMODEM# sh modem2.sh
stty: /dev/ttyUSB3: unable to perform all requested operations
abort on (NO CARRIER)
abort on (ERROR)
send (AT+CREG?^M)
expect (OK)
^M
+CREG: 0,1^M
^M
OK

-- got it

Code:
send (AT!PADSETUP=1,2,82.91.28.127,0,9940,0,1^M)
expect (OK)
^M
^M
OK

-- got it

Code:
send (AT+CGDCONT=1,"IP","web.omnitel.it"^M)
expect (OK)
^M
^M
OK

-- got it

Code:
send (AT!PADCONN=1^M)
expect (CONNECT)
^M
^M
OK^M
^M
CONNECT

-- got it

Code:
send ()
error setup modem

but i need a script like this
fore example:

Code:
IF not exist /dev/ttyUSB3 echo "MODEM NOT CONNECTED" and exit
ELSE (exist /dev/ttyUSB3) {
AT+CREG?
if ouput is different from +creg: 0,1 then echo "MODEM NOT REGISTRED" and redo at+creg
AT!PADCONN=1
if output is different from CONNECTED 1,0 then "IMPOSSIBLE OPEN A SOCKET" and redo at!PADCONN=1
}

how i can do?

PLS THANKS

Last edited by methyl; 04-20-2012 at 12:19 PM.. Reason: please be bothered to use code tags
# 19  
Old 04-20-2012
learn shell scripting...

also i had an error, this line needs negated with a ! before command:
Code:
if ! chat -v -s -f "${chat_script}"; then

You can test if /dev/ttyUSB3 exists with [ -e "$modem" ]
You can use individual chat commands like you did before, in an if condition.

Code:
send_expect() {
    chat -v -f 'ABORT ERROR' '' "$@" ''
}

die() {
    echo "$@" >&2
    exit 1
}

if ! [ -e "$modem" ]; then
    die 'Modem not connected'
fi

if ! send_expect 'AT+CREG?' '+CREG: 0,1'; then
    die 'Modem not registered'
fi

if ! send_expect 'AT!PADCONN=1' 'CONNECT'; then
    die 'Unable to open socket'
fi


Last edited by methyl; 04-20-2012 at 12:21 PM.. Reason: more code tags for readablity
# 20  
Old 04-20-2012
Thanks but i not undstand where put this function.
This is my new script but not work
i have an error on stty:standard input: unable to perform all requested operations

Code:
#! bin/sh

modem=/dev/ttyUSB3
file=/home/giuseppe/Desktop/SCRIPTMODEM/imsi.txt
chat_script=/home/giuseppe/Desktop/SCRIPTMODEM/omnitel.chat

exec 3<&1 >"$modem" <"$modem"

stty 115200 clocal
if ! chat -v -s -f "${chat_script}"; then
    echo "error setup modem" >&2
    exit 1
fi

die() {
    echo "$@" >&2
    exit 1
}
send_expect() {
    chat -v -f 'ABORT ERROR' '' "$@" ''
}

if ! [ -e "$modem" ]; then
    die 'Modem not connected'
fi

if ! send_expect 'AT+CREG?' '+CREG: 0,1'; then
    die 'Modem not registered'
fi

if ! send_expect 'AT!PADCONN=1' 'CONNECT'; then
    die 'Unable to open socket'
fi

cat"$file"
echo "done" >&3

you can write complete script pls?
thanks

---------- Post updated at 10:33 AM ---------- Previous update was at 08:23 AM ----------

i have do a new script following you:

Code:
#! /bin/bash
exec 2>error

cat /dev/ttyUSB3 /home/giuseppe/Desktop/SCRIPTMODEM/imsi.txt &
sleep 1

# CONTROLLO MODEM CONNESSO
if ! [ -e /dev/ttyUSB3 ]; then
    echo 'Modem non connesso'
    exit 0
fi

if ! chat -V -f 'ABORT ERROR' '' "$@" '' 'AT' 'OK' > /dev/ttyUSB3 < /dev/ttyUSB3; then
    echo "$@" 'ERRORE AT 1'
fi

sleep 2
killall cat
exit 0

but i view always ERRORE AT1.

Smilie

Last edited by enaud; 04-20-2012 at 12:34 PM.. Reason: changed PHP tags to CODE tags for readability because this is not PHP code.
# 21  
Old 04-20-2012
@enaud
Please post:
Code:
uname -a

(blotting anything confidential like mackine names with X's).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Alternatives to minicom During Remote Access?

Hey All, I am trying to find something similar to minicom, but it needs the ability to be ran during a remote dialup session on the remote device's side. If I dial into the remote server (*using minicom) and then try to run minicom on the remote server I get the following: # minicom... (20 Replies)
Discussion started by: mrm5102
20 Replies

2. SCO

Minicom

hello is there a copy of minicom or equivalent for unixware 7? thanks (3 Replies)
Discussion started by: deus-programmer
3 Replies

3. Shell Programming and Scripting

Expect script not working in crontab with minicom

Hi All, I am testing expect script in command prompt without issue, but in crontab it is not working, i check the output error as below: #cat /var/log/testexp.log spawn minicom -C /var/log/minicom1.log No cursor motion capability (cm) AT+COPS=? I am new in scripting, together... (1 Reply)
Discussion started by: elingtey
1 Replies

4. Shell Programming and Scripting

Help with minicom script

I'm a fairly new user to Linux based systems and am still a little uncomfortable with using the command interface. I'm trying to get my feet wet but have unfortunately hit a wall and am actually not even sure what I am trying to accomplish is at all possible. Basically, I am trying to use a... (0 Replies)
Discussion started by: nrdk00
0 Replies

5. Shell Programming and Scripting

Exiting from Minicom on a shell script

This is what I've tried: #!/bin/sh send sh send showifs send exit ! killall minicom My problem is that for some reason when I do this it doesn't give me the results of the prior commands sent like showifs So I suspect my syntax is wrong. (1 Reply)
Discussion started by: uradunce
1 Replies

6. Shell Programming and Scripting

minicom works, but stty does not

Hi all, I have some trouble getting stty to talk to some serial/usb converter. Getting minicom to work was however quite simple after I entered the following settings in addition to its standard-setup: pu port /dev/ttyUSB0 pu baudrate 19200 pu bits 8 pu... (3 Replies)
Discussion started by: pa-trick
3 Replies

7. Shell Programming and Scripting

expect minicom

Hi, I am new to using minicom. I want how to write a expect script for minicom login? I wrote a code but its not acting what iam expecting. here I have my code: #!/usr/bin/expect set fd fconfigure $fd spawn -open $fd spawn minicom expect “enter:” send "\n" send "\n" ... (3 Replies)
Discussion started by: vanid
3 Replies

8. Shell Programming and Scripting

running scripts in minicom

Hi, I am new to use minicom. I want script to run on minicom with username and password as automated.(Expect). please could anyone suggest the sample code for it. Thanks in advance (2 Replies)
Discussion started by: vanid
2 Replies

9. UNIX for Dummies Questions & Answers

Minicom Scripting

Does anyone have a working minicom script they would care to post as I can't get the scripting working and the scriptdemo and unixlogin sample scripts are on my system either. Thanx, I (2 Replies)
Discussion started by: ianf
2 Replies

10. UNIX for Dummies Questions & Answers

linux - minicom

hello. i'm attempting to use minicom in linux, but i'm having some difficulties. When i type in "minicom", the application opens up. It says 'starting minicom/finding modem'(something like that). However, once it actually starts, I can't do anything. No matter what I type in, it doesn't work. ... (2 Replies)
Discussion started by: kickboxer
2 Replies
Login or Register to Ask a Question