serial.write output GPS sentence formation and concatenation

PaulS,

I started this project with the more familiar Serial.print(); and Serial.println(); statements. That is where I realized that there was a problem. When I use this method I get the same output that I get with the

Serial << Veh_ID << NMEA1 << "\n";

I think that I do understand how it is overloaded and found the technique here in the forum in a posting that appeared to be well vetted.

Just to make sure that Serial.print(); works. Here is a version of the code using that as a method:

// Program to receive GPS data from Adafruit Ultimate GPS receiver and format it for output on a serial radio link
// ie XBee to a receiving station running GooPs GPS tracking software (http://goopstechnologies.com/)
//
// Project is intended to allow a user at a central location to locate several vehicles equipped with GPS receivers.

//Make sure to install the adafruit GPS library from GitHub - adafruit/Adafruit_GPS: An interrupt-based GPS Arduino library for no-parsing-required use
//template inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }

#include <Adafruit_GPS.h> //Load the GPS Library. Make sure you have installed the library form the adafruit site above
#include <SoftwareSerial.h> //Load the Software Serial Library. This library in effect gives the arduino additional serial ports
#include <Streaming.h>

// GPS Baud Rate is 9600
#define GPSBAUD 9600
#define RXPIN 3
#define TXPIN 2

SoftwareSerial mySerial(RXPIN, TXPIN); //Initialize SoftwareSerial, and tell it you will be connecting through pins 2 and 3

Adafruit_GPS GPS(&mySerial); //Create GPS object

String NMEA1; //We will use this variable to hold our first NMEA sentence
String NMEA2; //We will use this variable to hold our second NMEA sentence

const char Veh_ID[] = "joe@joescar:";

// const String Veh_ID = "joe@joescar:";

char c; //Used to read the characters spewing from the GPS module

void setup() {
Serial.begin(9600); //Turn on the Serial Monitor
GPS.begin(9600); //Turn GPS on at baud rate of 9600
GPS.sendCommand("$PGCMD,33,0*6D"); // Turn Off GPS Antenna Update
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Tell GPS we want only $GPRMC and $GPGGA NMEA sentences
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
delay(1000); //Pause
}

void loop() // run over and over again
{
readGPS(); //This is a function we define below which reads two NMEA sentences from GPS
}

void readGPS(){ //This function will read and remember two NMEA sentences from GPS
clearGPS(); //Serial port probably has old or corrupt data, so begin by clearing it all out

// Get first NMEA data sentance
while(!GPS.newNMEAreceived()) { //Keep reading characters in this loop until a good NMEA sentence is received
c = GPS.read(); //read a character from the GPS
}

GPS.parse(GPS.lastNMEA()); //Once you get a good NMEA, parse it

NMEA1 = GPS.lastNMEA(); //Once parsed, save NMEA sentence into NMEA1

// Get second NMEA data sentance
while(!GPS.newNMEAreceived()) { //Go out and get the second NMEA sentence, should be different type than the first one read above.
c = GPS.read();
}

GPS.parse(GPS.lastNMEA());

NMEA2 = GPS.lastNMEA();

// Send Vehicle ID and NEMA data out of serail port
// Serial << Veh_ID;
// Serial << Veh_ID << NMEA1 << "\n";
// Serial << Veh_ID << NMEA2 << "\n";

// Serial << Veh_ID << NMEA1;
// Serial << Veh_ID << NMEA2;

// Serial << NMEA1;
// Serial << NMEA2;

// Serial << "joe@joescar" << NMEA1;

Serial.print(Veh_ID);
Serial.print(NMEA1);
Serial.println();
Serial.print(Veh_ID);
Serial.print(NMEA2);
Serial.println();

// Serial << "joe@joescar" << NMEA2;

}

void clearGPS() { //Since between GPS reads, we still have data streaming in, we need to clear the old data by reading a few sentences, and discarding these
while(!GPS.newNMEAreceived()) {
c = GPS.read();
}

GPS.parse(GPS.lastNMEA());

while(!GPS.newNMEAreceived()) {
c = GPS.read();
}

GPS.parse(GPS.lastNMEA());

}