"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?
 
I have some C here that was written for us to talk to mobile phone modems to get text messages from the phone.

AT commands can query the phone/modem for information - this is the route you should take. Knock something up in a language of your choice that will interrogate the phone and interpret the answer to return you something you can then run with for the rest of your script.

For Nokia GSM devices, to get the IMEI number you would send AT+CGSN and the phone would reply with the unique 19-character IMEI number. Deciphering this for your purposes shouldn't be too hard!
 
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 don't have a handy modem to try stuff on and I cant mess with the one I do have because its in a production environment, but couldn't you cat /dev/ttyUSB0 to a file to see if you can get at the responses that way? Just add an && cat /dev/ttyUSB0 > testfile to the end of the echo line?

I have just done an outside broadcast so I am tired and probably not thinking straight but its got to be worth a shot?
 
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:
I have sent some code to you in an email that might help you :) If I find the time later on I will have a chat with the modem and see what it says!
 
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