Power Cycling the modem

HI there

I have tried to power cycle the modem when it is connected to GPRS. The minute I remove and replace power, the modem detaches itself from the GPRS network. This is evident because when I enter the command AT+CGREG?, the reply from the modem is +CGREG:0,0.

May you please help me regarding this.Can I power cycle the modem with code?


That sounds like perfectly normal behaviour, and exactly as should be expected!

Of course turning the modem off will detach it from the network - it will stop all its activity!

IF you want it to re-attach, you must re-issue the commands that you previously used to attach it!

This is exactly the same as if you switched your phone off in the middle of a call - you would have to re-dial the call after you turned the phone back on!

Think about it: when the modem is off, nothing is running; code that is not running cannot do anything - including turning the power back on again!

However, you can issue AT+CFUN=1 to restart the modem without power-cycling…


I remove and replace power from the modem by unplugging and replugging the power cable,I issue the command that I use to attach the modem to the GPRS network but it returns with an error. I even issued the command AT+CFUN=1 but it does not really help me because when i issue that command, it replies with an OK but after issuing this command then issuing my at command to attach to the network, the modem still returns an error.

I created these at commands to attach the modem to the GPRS network.

I am issuing these commands from the terminal emulator. During all this the Remote Task Monitor is running. I need to power cycle the modem because the specification for the software I am developing requires this.



So you need to fix the cause of that error!

Use AT+CMEE=1 to get the full error codes (remember to save this setting with AT&W)

What, exactly, does your specification actually require?

As already noted, it is impossible to have the embedded application cycle the power!
But, if you just need the application to restart & recover after a power cycle - that is an entirely different matter!

Hi there

Basically, I do need the application to restart and recover after a power cycle. The last used APN must be connected with immediate power up.

I have set my CMEE to1. It shows me the error that is already in the code, this error is due to that the modem is already connected to the GPRS network and I am trying to reconnect it to this same network whilst it is still connected to it.It is not the error that it sends after I power off/on the modem then use my at commands to re attach the modem to the GPRS network.

Any help would be appreciated



AT+CFUN=1 resets the modem.
If the modem is still responding to AT commands, then AT+CFUN=1 should be equally effective, and avoids the power-cycle.

if that’s not sufficient, and you need a real, hard, power cycle, then that will have to be controlled externally - as already explained.

maybe you should also consider trying to find the actual cause of the loss of communication, and fix that - rather than just power-cycling…?

eg, maybe your GPRS provider puts a maximum time limit on a single GPRS session; or maybe they time-out the session after a period of inactivity…

Why use a modem at the server?

GPRS gives you a TCP/IP connection - doesn’t your server already have an internet connection that you could use?

If the modem is still responding to AT commands, then AT+CFUN=1 should be equally effective.

Which modem - are we talking about the “remote” one now?

So that just needs to be part of your application - as far as the application is concerned, it cannot tell if it is starting due to a power-cycle, or starting after its first switch-on.

If your application does need to restart - which should be a last resort after trying all other recovery mechanisms - there is an ADL API call to do it…

I think I understand a little bit of what you are telling me. A TGX machine is a ticket selling machine which has a modem (in this case wavecoms Q2687) inside it.This modem sends data (tickets sold) to another modem “Globesurfer” which is connected to the server.I don’t know why we use the modem on the server but the TGX upgrades its software upgrades via this server and reports for the different machines are obtained from this server.

The remote modem (globesurfer) was losing connectivity too many times that it was difficult for the TGX to download upgrades etc, they came up with the idea of power cycling to keep the remote modem connected always. This is done with external hardware of course but software monitors a particular pin on the RS232 port then the status of this pin determines the power cycling.

The Q2687 also loses connection at times, so I guess the power cycling option comes up.

After issuing the command AT+CFUN=1, the modem does respond to at commands like ATI3,AT which are general commands that the modem knows already and always has an answer for. In this application, I used adl_atCmdSubscribe, to create my own at command. When I issue this command, the modem attaches itself to the GPRS network and an APN. I then issue another command that connects the modem to an IP. Both commands are created by me.

After issuing AT+CFUN =1, the modem does not recognise these commands that I subscribed to only. It sends error for these only and not the ATi3s and all.

Since the response to these commands is an error, it means i have to restart the application all together. Also the error that is shown is already in the code signalling that i cannot connect to GPRS network when I am already connected to it.

How in my application can I make the modem reattach itself to the GPRS network automatically after removing power and replacing power to it?? Is this the part where I use the “last resort” which is the adl_api, or I can just add it to my code???

Again,what code must I put in my application for the modem to recognise that it power was removed and replaced on it.

I am really clueless in all this and the forum is my only hope to go forward.



Is the Q2687 used as just a “dumb” modem, or is there an Open-AT application running within it?

IF it’s just a “dumb” modem, then the TGX must have its own processor to control it - and that processor can, of course, fully control power-cycling the Q2687.

That is not a solution - that’s just a “band-aid”
They are addressing the symptoms without fixing the underlying cause!
They should really look at proper ways to detect comms loss and recover properly!

All radio links are inherently liable to losing connection - therefore the application needs to be designed to specifically cope with such conditions.

And there are the issues with service providers imposing time limits and timeouts.

Again, power-cycling should be your last resort - you should be investigating proper recovery mechanisms before resorting to that!

see also: viewtopic.php?f=16&t=3174&p=11800#p11800

the Q2687 is being used as a “dumb” modem for now. We tell it to connect and to do anything.

We are developing code to minimise the code for the TGX machine so that it does not have to tell the modem to connect and and to reconnect each time the network fails or each time it does not connect properly.

I think the reason which led to power cycling was that a lot of data was lost which was required for subsidies.

Anyway, why am I getting an error when I use the AT commands that I created after removing the power or resetting the modem with AT+CFUN=1? Is this because my commands are subscribed to?? I have not unsubscribed to them though in my code.

Kind Regards,


An Open-AT application cannot use “custom” commands created by that application.

If the application needs to use the functionality, then you have to call the handler directly, or similar

You guys, it seems you are conducting what it is called a “parallel discussion”. I guess that contrary to awneil I understand the problem gugulethu has, but I have to ask some questions to make sure (in fact, you are providing too many irrelevant details, and this makes your story confuse).

My understanding is that you attach the modem to the GPRS network, then a power down occurs. After this, you can’t re-attach to the GPRS network when the Wavecom boots-up. So now the questions:

  1. did I correctly understand your problem?
  2. if yes, what is your network provider?

What I suspect, and this is what we have seen too on some networks (notably from Swisscom CH) is that a sudden modem reset or power down, without previously de-registering the module from the GSM network (both GSM and GPRS), may lead to the impossibility to reconnect after boot-up. This is in our opinion a bug of the GSM network, and not from the mobile equipment (ME). We have not found a solution to this problem, for now the sole remedy is to call the hot line of Swisscom and ask them to reset the SIM card from their network. We are still investigating this issue and possible remedies. For now we modified the software to de-register before resets, but we are powerless against power failures, because they happen out of our control.

Let me know if this fits your problem. If true, then you have no solution to the problem except to complain to your network provider. Or if possible, be warned before a power down will happen and de-register from the network shortly before.


Yes, it is always Good Practice to detach cleanly from the network before resetting or powering-down.

You can use AT+CFUN=0 to detach cleanly before powering-off; and AT+CFUN=1 will detach & restart.

Hence I would tend to agree with you that it is a network bug to lock-out a SIM in such circumstances.

However, note that networks can notice devices which repeatededly restart without properly detaching, and may “blacklist” them as potentially faulty.
Hence it is important to detach cleanly if at all possible.

Hi there

If I store my custom at commands that I created specifically to attach the modem to the GPRS network in the flash. Will they work when I use them after losing power to the modem then having the power on again.


You didn’t answer Lix whether he has correctly understood your problem. It would, at least, be polite to acknowledge his input.
Also, his understanding of your problem is totally different to mine; so, if he’s right, then I’m wrong - and you need to listen to him!

Or her.

There is no other way to store them!

There is no way to create “temporary” (or “volatile”) custom AT commands.

Yes, that is the whole point of Open-AT - once the application is loaded into the module and started, it remains there and will (re)start every time the module (re)starts

In our case a power fail is a rare event, may happen once a year or so in normal circumstances, so this should not be a problem. However, if this leads to a hangup on the network, this is not good. We are working with Swisscom towards a solution; in fact, we suspect they made a software upgrade to their systems sometimes end of 2008, because we did not have this issue although we have many devices on their network since 2006.

“Him” is correct :wink:

My apologies Lix for not responding to your question.

I am afraid you did not fully understand my problem. I seemingly had two problems in one basically.

At my company, we power cycle the modem to always get a connection because we had a problem with one of our modems losing connection one too many times. My major problem was that, I could not re-attach my modem to the GPRS network each time the power was removed. I created my own custom at commands to attach the modem to the GPRS network and after removing power, they did not work whereas other at commands worked after power was removed.

I was supposed to store these commands in flash so that they worked when power was removed and replaced.


First of all maybe better solution will be to monitor if GPRS connection is active. For example send some NOOP packet every few seconds or minutes to make sure if everything works fine. You can run timer in your application and check if in past few minutes your wavecom terminal have received any data. If not you can start restarting procedure. You can then close GPRS connection and then establish it again. It is I think much safer and much more stable solution.

If you have problem with your own created AT commands, maybe better will be to start connection automatically after power is back. You can then avoid sending at commands by external device. Maybe this could resolve your problem.
Nevertheless it is quite strange that after reboot yours commands are not working. Maybe, if it is possible, paste some parts of code to make sure that you are doing everything correct. Sometimes it is easier to analyse code than read the description. :smiley:
If it is not possible write down the full scenario, how your application is working, in what part of your code the error occurs, how you are establishing the connection. This should clarify description.

Thank you all for the advice

If anyone has sample code for for monitoring the GPRS connection, please post it. :slight_smile: