Thanks very much for your reply Paul.
I have removed the code that I thought would poll every 10 seconds. I understand it would be difficult to control. I also see now that my while statement to try find GPS lines was useless. I have taken an example off sparkfun that uses the TinyGPS library, and basically changed the variable types to global to make the data available to the GSM's loop. This is the code I have so far:
void setup()
{
Serial.begin(115200);
cell.begin(9600);
uart_gps.begin(4800);
Serial.println("Setup Complete");
}
float latitude, longitude, alt, spd, crs;
int year;
byte month, day, hour, minute, second, hundredths;
char c;
String line, SenderNumber, SenderMessage;
void loop()
{
// while (cell.available())
// {
// c = cell.read();
// Serial.println(c, BYTE);
// delay(10);
// }
while(uart_gps.available())
{
int c = uart_gps.read();
if(gps.encode(c))
{
getgps(gps);
uart_gps.flush();
}
}
// Serial.println();
// Serial.print(latitude, 5);
// Serial.print(' ');
// Serial.println(longitude, 5);
}
void getgps(TinyGPS &gps)
{
gps.f_get_position(&latitude, &longitude);
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
alt = gps.f_altitude();
crs = gps.f_course();
spd = gps.f_speed_kmph();
}
The GPS code works and returns the values needed after it's while loop. When I add in the other while loop for the GSM data, the variables dont get populated which shows me the 'uart_gps.available()' isnt returning true. Really cluessless here, at the moment I am just doing trial and error and it's not working for me.
The GSM code I made earlier works, but as you pointed out I don't think it's the right way to do it. This while loop here works well without the GPS while loop:
if (cell.available() > 0)
{
c = cell.read();
while ((c != '\n') && (c != '\r')) //look for new lines from SM5100
{
line = line + c;
c = cell.read();
}
if (line == "+SIND: 4")
{
cell.println("AT+CNMI=3,3,0,0");
delay(20);
cell.println("AT+CMGF=1");
delay(20);
cell.println("AT+CMGD=1,4");
delay(1000);
}
if (line.substring(0,4) == "+CMT")
{
SenderNumber = ("0" + line.substring(10,19));
line = "";
}
if ((line.substring(0,4) == "#LOC")) //#LOC is sms command from sender
{
SenderMessage = (line);
line = "";
int flag = 0;
}
line = "";
}
Thanks again Paul.