Well I managed to figure it out thanks to all of the great replies on this thread! Basically I had set up a situation where at least one of those conditional statements would always evaluate to true and reset my string builder. I changed the function to:
//this just reads data in one character at a time until we have a complete sentence
boolean checkforSentence()
{
char c;
while(mySerial.available())
{
last_data_received = millis() + 2000;
c = mySerial.read();
//Serial.print(c);
if(sentenceBegins && c == '\r') //we have a full sentence
{
sentenceBegins = false;
Serial.println(buffer);
return true;
}
if(sentenceBegins) //store characters to buffer
{
buffer[index] = c;
index++;
buffer[index] = '\0';
/*
we need something to segregate out the RMC and GGA sentences and ignore
everything else. Originally I was sending a command to the GPS to
only send the string that I was interested in, but for some reason the GPS
is not accepting my commands anymore. It happened pretty suddenly so f'
it. I will just ignore everything that I don't want to see.
*/
if(index==5)
{
if(data_index==true)
{
if(!(strcmp(buffer, "GPGGA") == 0))
{
sentenceBegins = false;
//Serial.println(buffer);
}
}
if(data_index==false)
{
if(!(strcmp(buffer, "GPRMC") == 0))
{
sentenceBegins = false;
//Serial.println(buffer);
}
}
}
}
if(c == '
which works great now!) //beginning of sentence...start saving to buffer
{
sentenceBegins = true;
index = 0;
}
}
return false;
}
which works great now!