I don't know what I am doing wrong, but a byte value seems to disappear.
I have the following code that reads the Serial for GPS data.
I then parse this data.
I use a if...else if...else statement to check if the GPS data is Valid.
If it is Valid, I will then write the time and date to the RTC.
The below log shows that I parse the data correctly.
However, as soon as I try to print the data within the if...else if...else statement, I loose the first "Hours Byte:"
code:
void GetGPS(){
// MANAGES THE CHARACTERS RECEIVED BY GPS
while (serGPS.available()) {
GPS_info_char=serGPS.read();
if (GPS_info_char == '
Log:
GNRMC,134008.000,A,2545.7844,S,02813.1639,E,1.23,357.00,270218,,,A,VV
Time String: 134008.000
Hours Byte: 13
Minutes Byte: 40
Seconds Byte: 8
Day Byte: 27
Month Byte: 2
Year Byte: 18
GOT VALID
Hours Byte: 0
Minutes Byte: 40
Seconds Byte: 8
Day Byte: 27
Month Byte: 2
Year Byte: 18
){ // start of message
message_started=true;
received_char=0;
}else if (GPS_info_char == '*'){ // end of message
for (i=0; i<received_char; i++){
// Serial.write(GPS_info_buffer[i]); // writes the message once it has been completely received
// GNRMC,064509.000,A,2545.7696,S,02813.1923,E,0.28,149.40,230218,,,A,V
// GPRMC,064602.000,V,,,,,0.00,149.40,230218,,,N,V
strcpy(tempGPS, GPS_info_buffer);
Serial.println(tempGPS);
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(tempGPS,","); // get the first part - the string
strcpy(GPSHeader, strtokIndx); // copy it to GPSHeader
strtokIndx = strtok(NULL, ",");
strcpy(GPSTime, strtokIndx); // copy to GPSTime
String GPSNowTime(GPSTime);
Serial.print("Time String: ");
Serial.println(GPSNowTime);
hours = GPSNowTime.substring(0,2).toInt();
Serial.print("Hours Byte: ");
Serial.println(hours);
minutes = GPSNowTime.substring(2, 4).toInt();
Serial.print("Minutes Byte: ");
Serial.println(minutes);
seconds = GPSNowTime.substring(4, 6).toInt();
Serial.print("Seconds Byte: ");
Serial.println(seconds);
strtokIndx = strtok(NULL, ",");
strcpy(GPSValid, strtokIndx); // copy to GPSValid
String Valid(GPSValid);
strtokIndx = strtok(NULL, ",");
strcpy(GPSLat, strtokIndx); // copy to GPSLat
// Serial.println(GPSLat);
strtokIndx = strtok(NULL, ",");
strcpy(GPSNS, strtokIndx); // copy to GPSNS
// Serial.println(GPSNS);
strtokIndx = strtok(NULL, ",");
strcpy(GPSLon, strtokIndx); // copy to GPSLon
// Serial.println(GPSLon);
strtokIndx = strtok(NULL, ",");
strcpy(GPSEW, strtokIndx); // copy it to GPSEW
// Serial.println(GPSEW);
strtokIndx = strtok(NULL, ",");
strcpy(GPSSpeed, strtokIndx); // copy to GPSSpeed
// Serial.println(GPSSpeed);
strtokIndx = strtok(NULL, ",");
strcpy(GPSTrack, strtokIndx); // copy to GPSTrack
// Serial.println(GPSTrack);
strtokIndx = strtok(NULL, ",");
strcpy(GPSDate, strtokIndx); // copy to GPSDate
// Serial.println(GPSDate);
String GPSNowDate(GPSDate);
day = GPSNowDate.substring(0, 2).toInt();
Serial.print("Day Byte: ");
Serial.println(day);
month = GPSNowDate.substring(2, 4).toInt();
Serial.print("Month Byte: ");
Serial.println(month);
year = GPSNowDate.substring(4, 6).toInt();
Serial.print("Year Byte: ");
Serial.println(year);
// }
if (Valid == "A")
{
Serial.println();
Serial.println("GOT VALID");
Serial.print("Hours Byte: ");
Serial.println(hours);
Serial.print("Minutes Byte: ");
Serial.println(minutes);
Serial.print("Seconds Byte: ");
Serial.println(seconds);
Serial.print("Day Byte: ");
Serial.println(day);
Serial.print("Month Byte: ");
Serial.println(month);
Serial.print("Year Byte: ");
Serial.println(year);
Serial.println();
}
else if (Valid == "V")
{
Serial.println();
Serial.println("NOT VALID");
Serial.println();
}
else
{
// Do Nothing
}
}
Serial.println();
message_started=false; // ready for the new message
}
else if (message_started==true){ // the message has already started and I got a new character
if (received_char<=GPS_INFO_BUFFER_SIZE){ // to avoid buffer overflow
GPS_info_buffer[received_char]=GPS_info_char;
received_char++;
}else{ // resets everything (overflow happened)
message_started=false;
received_char=0;
}
}
}
}
Log:
§DISCOURSE_HOISTED_CODE_1§