In order to make my dialog with the modem bulletproof, I would like to query for the 'attached' state after I do a AT+CGATT=1 and before I do an AT#CONNECTIONSTART. If I do a #CONNECTIONSTART too soon, I get a #CME ERROR.

I would recommend using the unsolicited responses from the modem.

You can set the following:


When you turn the unit on you should receive a +WIND: 4 response. This response means that the modem is ready to process all AT commands.

Then after you get a +WIND: 4, you can do an AT+CGATT=1 to do an attach. You should get a response similar to the below:

+CGREG: 1 ( or 5 )

If you want to check and make sure that the attach went through, and you are registered on the GPRS network, send 'AT+CGATT?' and it should return "+CGATT: 1" if it is attached. If not, then it will return "+CGATT: 0". Then you can also send 'AT+CGREG?' to check the GPRS registration. You should receive "+CGREG: 1,1" or "+CGREG: 1,5" which should mean that you are registered.

Once the modem is attached and you know that the GPRS registration status is good, that normally means that the modem should be ready for the #CONNECTIONSTART command.