"Chatting" with serial modem

Caporegime
Joined
18 Oct 2002
Posts
29,493
Location
Back in East London
I've got a serial GPRS modem on /dev/ttyUSB0. It works great with wvdial, hardware is fine etc. etc. but as the systems we are going to be rolling out will be using multiple modems, each with a different telephone network, each modem will have differing username/password combinations amongst other parameters.

Now, the sharp witted of you may also note they are USB modems converted to serial devices - this is where the problem is sprung. If, for example, a device dies, or is disconnected for whatever reason - the other modems will "shift" along the device chain, so /dev/ttyUSB1 will become /dev/ttyUSB0 - which when used with wvdial will not work - incorrect username/password.

So - I've been tasked with finding out how to interrogate the modem into fessing up which network it will be connecting to. (i.e. which chip ID does the sim within hold) but I can't find anything anywhere that is going to let me run a series of terminal (using bash, btw) commands to do said interrogation.

Does anyone know how I can communicate with this modem?
 
Cheers, I've found the cu command and can (kind of) talk to the device. I will be using a script of some description to interogate, but needed to find out how to talk to it first. ow I just to some how coax the device into talking back to me :rolleyes:
 
right.. am I being thick here or summat?

I've tried this:

Code:
root@blah # echo 'AT+CSGN' > /dev/ttyUSB0
and get nothing, but the light blinks to indicate it received something.

I've also used cu:
Code:
root@blah # cu -z /dev/ttyUSB0
  cu: No System Found
root@blah # cu -l /dev/ttyUSB0
Connected.
~+AT+CSGN
and again get nothing.. I'm getting lost now :/

It's not just the AT+CSGN that does the above, anything does. Init string also.
 
right.. gtkterm can talk to it.. I can get the IMEI number, BUT it's not in a useful place as I can't retrieve it as a variable etc.

and yes, I realised I was using AT+CSGN instead of AT+CGSN.
 
I'll give it a go, thanks.

EDIT: No joy unfortunately.. this is frustrating now. I can't even find the code for gtkterm/wvdial to see what method they use.
 
Last edited:
At chuffing last!

I had a sneaky suspicion a while ago that it was not interpreting \n.. so finally remembered to change it and it now works; here is an example:
Code:
#!/bin/bash
for i in $( ls /dev/ttyUSB* )
do
        exec 5<$i
        echo -en "AT+CIMI\r" > $i
        echo ' ' > $i
        while 0<&5 read line
        do
                if [ ${line:0:5} = '23410' ]
                then
                        echo "Device ${i} is provided by O2"
                        break
                fi
                if [ ${line:0:5} = '23430' ]
                then
                        echo "Device ${i} is provided by T-Mobile"
                        break
                fi
        done
done
In place of the echo's I'll be creating symlinks to /dev/modems/o2 or t-mobile folders. My word.. it's taken me a week to sort this out :\
 
Back
Top Bottom