The main problem is that you are using delay(). The TinyGPS example program is quite fragile, and when combined with two SoftwareSerial ports and delays, it just isn't going to work.
A secondary problem will (eventually) be String. Using character arrays and the C-string routines like strcpy and strcat is very efficient. Also, they will not cause random hangs after hours or days, like String.
A third problem is using SoftwareSerial. It is very inefficient and disables interrupts for long periods of time. Instead, please try NeoSWSerial. If you could use pins 8 & 9, I would recommend AltSoftSerial for the GPS device. It is even better.
Here is a version of your sketch that uses NeoGPS, NeoSWSerial, and does not use String:
#include "NMEAGPS.h"
#include <NeoSWSerial.h>
#define RXPIN 4
#define TXPIN 5
NMEAGPS gps;
gps_fix fix;
NeoSWSerial gps_port(RXPIN, TXPIN);
// Uncomment one of these at a time.
NeoSWSerial SIM900(2,3); // use this for really sending a message
//HardwareSerial & SIM900 = Serial; // use this for testing... SIM900 commands visible on Serial Monitor
void setup()
{
Serial.begin( 9600 );
Serial.println( F("unixbox911 test") );
SIM900 .begin( 9600 );
gps_port.begin( 9600 );
}
void loop()
{
while (gps.available( gps_port )) {
fix = gps.read();
doSomeWork( fix );
}
} // loop
void doSomeWork( gps_fix & fix )
{
if (fix.valid.location) {
// Only do this when the GPS has a good lat/lon
char message[40];
strcpy_P( message, (const char *) F("lat=") );
dtostrf( fix.latitude (), 4, 6, &message[ strlen(message) ] );
strcat_P( message, (const char *) F("&lon=") );
dtostrf( fix.longitude(), 4, 6, &message[ strlen(message) ] );
Serial.println(message);
Serial.println();
Serial.print( F("Connected Sats ::: ") );
if (fix.valid.satellites)
Serial.println( fix.satellites );
Serial.println();
Serial.println(message);
Serial.println();
SIM900.listen();
SIM900INIT(message);
SIM900STOP();
gps_port.listen();
}
}
void SIM900INIT( char msg[] )
{
SIM900.println( F("AT+SAPBR=3,1,\"Contype\",\"GPRS\"") );
delay(1000);
SIM900.println( F("AT+SAPBR=3,1,\"APN\",\"bsnlnet\"") );
delay(1000);
SIM900.println( F("AT+SAPBR=1,1") );
delay(3500);
SIM900.println( F("AT+SAPBR=2,1") );
delay(3500);
SIM900.println( F("AT+HTTPTERM") );
delay(1000);
SIM900.println( F("AT+HTTPINIT") );
delay(1000);
SIM900.println( F("AT+HTTPPARA=\"CID\",1") );
delay(1000);
SIM900.println( F("AT+HTTPPARA=\"URL\",\"hxxp://hostname.tld/record\"") );
delay(1000);
SIM900.println( F("AT+HTTPPARA=\"CONTENT\",\"application/x-www-form-urlencoded\"") );
delay(1000);
SIM900.print ( F( "AT+HTTPDATA=") );
SIM900.print ( strlen(msg) );
SIM900.println( F(",2000") );
delay(1000);
Serial.println( SIM900.println(msg) );
delay(1000);
Serial.println(SIM900.println( F("AT+HTTPACTION=1") ));
delay(5000);
}
void SIM900STOP()
{
SIM900.println("AT+HTTPTERM");
delay(1000);
}
void ShowSerialData()
{
while(SIM900.available()!=0)
Serial.write(SIM900.read());
}
Your original sketch used 14,798 bytes of program storage space, and 1,316 bytes of RAM. This version uses only 11,104 bytes of program storage space, and 462 bytes of RAM.
I would also suggest reading the NeoGPS Troubleshooting section. It describes many common problems, including yours. The delays were preventing it from receiving the GPS data correctly: the input buffer was overflowing.
Cheers,
/dev