tags:

views:

172

answers:

2
  1. I hava a GSM modem that disconnect after a while, maybe because of low signal. Am just wondering is there an AT command that can detect the disconnection and re-establish a reconnection.

  2. Is there a way in code (preferably python) i can detect the disconnection and re-establish a reconnection?

Gath

+1  A: 

Depending on what type of connection, circuit switched (CS) or packet switched (PS), the monitoring will be a little bit different. To detect a disconnect you can enable UR (unsolicited result) code AT+CPSB=1 to monitor PDP context activity (aka packet switched connections). For circuit switched calls you can monitor with the +CIEV: UR code enabled with AT+CMER=3,0,0,2.

To re-establish the connection you have to set up the connection again. For CS you will either have to know the phone number dialed, or you can use the special form of ATD, ATDL [1] which will dial the last dialed number. You can use ATDL for PS as well if the call was started with ATD (i.e. "ATD*99*....") which is quite common, but I do not think there is any way if started with AT+CGDATA for instance.

However, none of the above related to ATD matters, because it is not what you want. For CS you might set up a call from your python script, but then so what? After receiving CONNECT all the data traffic would be coming on the serial connection that your python script are using. And for PS the connection will not even finish successfully unless the phone receives PPP traffic from the PC as part of connection establishment. Do you intend your python script to supply that?

What you really want is to trigger your PC to try to connect again, whether this is standard operating system dial up networking or some special application launching it. So monitor the modem with a python script and then take appropriate action on the PC side to re-establish the connection.

[1] Side note to ATDL: notice that if you want to repeat the last voice call you should still terminate with a semicolon, i.e. ATDL;, otherwise you would start a data call.

hlovdal
I think that PDP context is only revelant for GPRS connection not for GSM.
luc
What is the difference between Circuit switched and Packet Switched? and how can the AT command come into play in re-establishing connection?
gath
To me GSM also implies GPRS (and I would even assume "GSM modem" to possibly mean UMTS or LTE as well, even not it strictly speaking is not the same as the original GSM standard), so do not quite understand what difference you are thinking about. And PDP context applies to GPRS, UMTS packed switched traffice and LTE.
hlovdal
CS is occupying the line all the time, PS will only send/receive when there is traffic. See http://en.wikipedia.org/wiki/Circuit_switching and http://en.wikipedia.org/wiki/Packet_switching.
hlovdal
A: 

You can try to check the signal strength on a regular basis with AT+CSQ. If the signal goes under a given threshold consider that you are disconnected and force a new connection.

You can try the very nice pyserial http://pyserial.sourceforge.net/ Python library to send the AT commands to the modem.

I hope it helps

luc