I'm currently using google geolocation to get location data to one nodemcu and sending it through serial to another arduinoArduino. The serial command I'm getting right now is,
1.450187T103.824745
1.450187T103.824745
I'm using the following code to parse it.
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
//if (c == '\n') { //looks for end of data packet marker
if (c == '\n') {
// Serial.println(readString); //prints string to serial port out
//do stuff
substring = readString.substring(0,8);
lati = substring;
loc = readString.indexOf("T");
substring = readString.substring(loc+1, loc+11);
longi = substring;
readString=""; //clears variable for new input
substring="";
}
else {
readString += c; //makes the string readString
}
}
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
//if (c == '\n') { //looks for end of data packet marker
if (c == '\n') {
// Serial.println(readString); //prints string to serial port out
//do stuff
substring = readString.substring(0,8);
lati = substring;
loc = readString.indexOf("T");
substring = readString.substring(loc+1, loc+11);
longi = substring;
readString=""; //clears variable for new input
substring="";
}
else {
readString += c; //makes the string readString
}
}
itIt works most of the time but sometimes I get 'T' inside the string as well. like this
lat=1.450146&longi=102464T103
lat=1.450146&longi=102464T103
What's wrong in my code?