Arduino Uno+SparkFun cellular shield+SM5100B


I’m new to this domain, I have little knowledge about C programming language.
I have an Arduino Uno bord a SparkFun cellular shiled+SM5100B and an GPS Sparkfun Shild with EM406 GPS module.
What i want to do is to capture gps data and than to send it to a TCP server throught GPRS.
I have red this tutorial:

Brriefly the logic of the program is:

-wait for +SIND 4 message that means the module is registered on the network, and ready to communicate
-setup PDP context (AT+CGDCONT=1,“IP”,“APN Name” and compare the result with “OK” string.
-Configure remote host and port (AT+SDATACONF=1,“”, 8181 and compare the result whit “OK” string
-Start a TCP connection

The first problem is how to capture, store and process the response from GSM?
This is my sketch:

#include <TinyGPS.h>
#include <SoftwareSerial.h>

char GSM_Msg[70];
int c,n;

SoftwareSerial GSM(2,3);
SoftwareSerial GPS(4,5);

void setup ()

 Serial.print("Starting GSM component");
   for (n=0;n++;n<=c)
 }while(char(!='4'); //wait for 4 from "+SIND: 4" message 

void loop()


The problem is that GSM_Msg char array is empty.

Where is my mistake?

Spit-balling here, but two things pop out at me:

  1. The documentation for SoftwareSerial states that it can’t run two serial connections simultaneously–it’ll simply ignore one of them. You’ve got two declared in your program, so that might cause it. (I suspect this is at least a good part of the reason why people here generally recommend using NewSoftSerial instead of SoftwareSerial.)

  2. The documentation for states: “This function waits for a character to arrive, reads it, and returns the character read. Data that arrives at other times is lost.” This sort of sounds like it’ll read the first character and then discard the rest. I’m not sure I’m interpreting that accurately, though.

For one thing the syntax of your for statement:

for (n = 0, n + + n <= c)

is incorrect. Did you mean this?

for(n=0; n<=c; n++) //semicolons separate, not commas
// test is second, not third
// no spaces in n++

for(n=0; n<=C; n++)

Also, the end conditions should be ‘less than’ not ‘less than or equal’, i.e.

for(n=0; n<c; n++)

A 70 character buffer should be enough to hold a message expected to contain 10 characters, but it’s good practice to protect against buffer overflow anyway.

Also note that your message buffer is not null-terminated, so any attempt to treat the contents as a string could lead to trouble.

@PeterH: the rx buffer is defined as 64 bits max on SoftwareSerial library. But my main problem is that after the do while cycle if i m trying to read the gsm_msg char array, this is empty. On the other hand in same code if i replace the gsm_msg[n] whit Serial.print(char(; it's works.