user15052: Preamble:
I have a sim908 shield and I'm trying to send some data periodically to a server using AT commands.
For every command, I wait for the response to check if everything is working.
Actually the sketch works but, often, I noticed errors during http request.
State of the art:
Here it is the sequence of AT commands (not the entire code) into the loop:
1) Check the Network Registration and, if necessary, wait 
AT+CREG?

2) Set params for GPRS connection (no user or password required)
AT+SAPBR=3,1,"Contype","GPRS"
AT+SAPBR=3,1,"APN","web.omnitel.it"

3) Get current bearer
AT+SAPBR=2,1

4) If bearer == 0,0,0,0 (not assigned) get a new bearer
AT+SAPBR=1,1

5) Init HTTP
AT+HTTPINIT

6) Set CID and URL
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","www.someurl.com/service.php?p1=1&p2=2"

7) Execute the HTTP command (POST)
AT+HTTPACTION=1

8) Close HTTP connection
AT+HTTPTERM

Question:
Why HTTP init (step 5) or HTTP posting (step 7) often fails? What is wrong in this procedure? I'm missing something? There is a way to make the procedure more stable?
Thank you in advance :)
Important update:
If occurs an error during sending data via HTTP, is a great idea to renew the bearer (step 4)
Answers to the comments:
a) Shield has an antenna and it works. If I try to disconnect the antenna, code still  search the network (step 1) untill I reconnect the antenna.
b) Some times I have this error initializing HTTP (step 5):

AT+HTTPINIT
+CME ERROR: 3

Some times I have only "OK" as response posting data (step 7) instead of:

+HTTPACTION:1,200,xxx

Or this response:

+HTTPACTION:1,600,0

c) I have error at step 4 (AT+SAPBR=1,1) only if I execute the command when I have yet a bearer. The error in this case is:

AT+SAPBR=1,1
+CME ERROR: 3

For this reason I do a check (step 3)

user8033: You mention two different error messages.
1. AT+HTTPINIT fail
You get +CME ERROR 3. Which means "operation not allowed".
This can be due to an improperly closed HTTP setup.
If you get this error (or just always do before setting up), call AT+HTTPTERM to be sure that it's closed.
2. AT+HTTPACTION=1
I notice you're trying to do a POSTmessage, while your variables are in the URL (which is GET style afaik).
I've found a source that states you need to call AT+HTTPDATA with apropriate values.

Tell the module that you will be sending 192 bytes of data and it can timeout after 10 seconds of inactivity. 

After that, the device will say DOWNLOAD, and you can send the POST body.

After this command you get the DOWNLOAD URC then you can type in 192 bytes of data within 10 seconds. The typed data is filled in a local buffer of the module and is not yet posted to the server. In the post body is the multi part form data which contains the necessary headers and data to post a file with name data.txt with 10 bytes of data.
  AT+HTTPDATA=192,10000

And after that you can send the POST message.

Execute the HTTP POST command so that the buffer contents are POST to
  the server AT+HTTPACTION=1 OK

You will get a return message that states the HTTP code (200 'OK') and the amount of bytes received in the return message.

+HTTPACTION:1,200,141
  This URC means that the data was successfully posted to the server and received 141 bytes of data.
  which is the server response to your HTTP POST

You can use AT+HTTPREAD to receive these bytes.

The below command tells the module that we want to read the received data AT+HTTPREAD The below is the data
  received from the server
  +HTTPREAD:141 Successfully dumped 0 post variables. View it at http://www.posttestserver.com/data/2015/10/07/07.41.291690063480 Post
  body was 0 chars long. OK

(Scroll a fair bit down in the source, the first part is on HTTP GET: http://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands)
You could also omit this by using HTTP GET since it's somewhat easier.
If all else fails, you can set up a TCP IP connection with the GSM module and manually set up the HTTP GET/POST message.

15052: <p><strong>Preamble</strong>:</p>

<p>I have a <code>sim908</code> shield and I'm trying to send some data periodically to a server using <code>AT commands</code>.
For every command, I wait for the response to check if everything is working.
Actually the sketch works but, often, I noticed errors during http request.</p>

<p><strong>State of the art</strong>:</p>

<p>Here it is the sequence of AT commands (not the entire code) into the loop:</p>

<p>1) Check the Network Registration and, if necessary, wait </p>

<pre><code>AT+CREG?
</code></pre>

<p>2) Set params for GPRS connection (no user or password required)</p>

<pre><code>AT+SAPBR=3,1,"Contype","GPRS"
AT+SAPBR=3,1,"APN","web.omnitel.it"
</code></pre>

<p>3) Get current bearer</p>

<pre><code>AT+SAPBR=2,1
</code></pre>

<p>4) If bearer == 0,0,0,0 (not assigned) get a new bearer</p>

<pre><code>AT+SAPBR=1,1
</code></pre>

<p>5) Init HTTP</p>

<pre><code>AT+HTTPINIT
</code></pre>

<p>6) Set CID and URL</p>

<pre><code>AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","www.someurl.com/service.php?p1=1&amp;p2=2"
</code></pre>

<p>7) Execute the HTTP command (POST)</p>

<pre><code>AT+HTTPACTION=1
</code></pre>

<p>8) Close HTTP connection</p>

<pre><code>AT+HTTPTERM
</code></pre>

<p><strong>Question</strong>:</p>

<p>Why HTTP init (step 5) or HTTP posting (step 7) often fails? What is wrong in this procedure? I'm missing something? There is a way to make the procedure more stable?</p>

<p>Thank you in advance :)</p>

<p><strong>Important update</strong>:</p>

<p>If occurs an error during sending data via HTTP, is a great idea to renew the bearer (step 4)</p>

<p><strong>Answers to the comments</strong>:</p>

<p><strong>a)</strong> Shield has an antenna and it works. If I try to disconnect the antenna, code still  search the network (step 1) untill I reconnect the antenna.</p>

<p><strong>b)</strong> Some times I have this error initializing HTTP (step 5):</p>

<blockquote>
  <p>AT+HTTPINIT</p>
  
  <p>+CME ERROR: 3</p>
</blockquote>

<p>Some times I have only "OK" as response posting data (step 7) instead of:</p>

<blockquote>
  <p>+HTTPACTION:1,200,xxx</p>
</blockquote>

<p>Or this response:</p>

<blockquote>
  <p>+HTTPACTION:1,600,0</p>
</blockquote>

<p><strong>c)</strong> I have error at step 4 (AT+SAPBR=1,1) only if I execute the command when I have yet a bearer. The error in this case is:</p>

<blockquote>
  <p>AT+SAPBR=1,1</p>
  
  <p>+CME ERROR: 3</p>
</blockquote>

<p>For this reason I do a check (step 3)</p>
 8033: <p>You mention two different error messages.</p>

<p><strong>1. AT+HTTPINIT fail</strong></p>

<p>You get +CME ERROR 3. Which means "operation not allowed".</p>

<p>This can be due to an improperly closed HTTP setup.
If you get this error (or just always do before setting up), call <code>AT+HTTPTERM</code> to be sure that it's closed.</p>

<p><strong>2. AT+HTTPACTION=1</strong></p>

<p>I notice you're trying to do a <code>POST</code>message, while your variables are in the URL (which is <code>GET</code> style afaik).</p>

<p>I've found a source that states you need to call <code>AT+HTTPDATA</code> with apropriate values.</p>

<blockquote>
  <p>Tell the module that you will be sending 192 bytes of data and it can timeout after 10 seconds of inactivity. </p>
</blockquote>

<p>After that, the device will say <code>DOWNLOAD</code>, and you can send the <code>POST</code> body.</p>

<blockquote>
  <p>After this command you get the DOWNLOAD URC then you can type in 192 bytes of data within 10 seconds. The typed data is filled in a local buffer of the module and is not yet posted to the server. In the post body is the multi part form data which contains the necessary headers and data to post a file with name data.txt with 10 bytes of data.
  <code>AT+HTTPDATA=192,10000</code></p>
</blockquote>

<p>And after that you can send the <code>POST</code> message.</p>

<blockquote>
  <p>Execute the HTTP POST command so that the buffer contents are POST to
  the server <code>AT+HTTPACTION=1 OK</code></p>
</blockquote>

<p>You will get a return message that states the HTTP code (200 'OK') and the amount of bytes received in the return message.</p>

<blockquote>
  <p><code>+HTTPACTION:1,200,141</code>
  This URC means that the data was successfully posted to the server and received 141 bytes of data.
  which is the server response to your HTTP POST</p>
</blockquote>

<p>You can use <code>AT+HTTPREAD</code> to receive these bytes.</p>

<blockquote>
  <p>The below command tells the module that we want to read the received data AT+HTTPREAD The below is the data
  received from the server
  +HTTPREAD:141 Successfully dumped 0 post variables. View it at <a href="http://www.posttestserver.com/data/2015/10/07/07.41.291690063480" rel="nofollow">http://www.posttestserver.com/data/2015/10/07/07.41.291690063480</a> Post
  body was 0 chars long. OK</p>
</blockquote>

<p>(Scroll a fair bit down in the source, the first part is on <code>HTTP GET</code>: <a href="http://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands" rel="nofollow">http://www.raviyp.com/embedded/194-sim900-gprs-http-at-commands</a>)</p>

<p>You could also omit this by using <code>HTTP GET</code> since it's somewhat easier.</p>

<p>If all else fails, you can set up a <code>TCP IP</code> connection with the GSM module and manually set up the HTTP GET/POST message.</p>
