I have been using TinyGPS++ to extract specific fields from different sentences (Mikal calls these custom fields). Was working fine till I wanted to test a field's value by a logical comparison.
In the example below I want the "Data Valid" field. This is the 2nd field in the $GPRMC sentence (counting starts from after the sentence identifier. The value will be "V" if the sentence data is NOT valid, "A" if it IS valid. It is simple to get the field's value and print it, but testing it doesn't work for me.
Here, I compare the value against "V". If equal I want to print "fish"; if not equal print "cat". The value is "V" (I print it) but I get "cat", so the comparison returns false.
Am I misunderstanding the data types in play? Mikal's example doesn't speciify the data type of the returned custom field.
Thanks,
John.
/*
* To test the custom field extract feature of TinyGPS++
*/
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps;
SoftwareSerial ss(4, 3);//RX TX //GPS communicates thru software serial
TinyGPSCustom validField(gps, "GPRMC", 2); //defining where the field is to be found--
//2nd field of "GPRMC" sentence
void setup() {
ss.begin(9600); //the GPS connection
Serial.begin(9600); //monitor
}
void loop() {
byte incomingByte;
smartDelay(1000); //read the GPS output and parse it thru TinyGPS++ "encode"
//EXTRACT A CUSTOM FIELD
Serial.println();
Serial.print("validField:");
Serial.println(validField.value()); //gets the field I want & sends to mnonitor
if (validField.value() == "V") //is it "V"?
Serial.println("fish"); //yes -- print "fish"
else
Serial.println("cat"); //no -- print "cat"
Serial.println();
}
static void smartDelay(unsigned long ms)
/*
* Mikal's procedure for reading and parsing the GPS output
*/
{
unsigned long start = millis();
byte incomingByte;
do
{
while (ss.available()){
incomingByte = ss.read(); //read a byte
Serial.write(incomingByte); //display it
gps.encode(incomingByte); //encode it
}
}
while (millis() - start < ms); //wait till timeout
}
Monitor output: