Skip to main content
Fixed syntax highlighting, capitalization.
Source Link
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

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?

I'm currently using google geolocation to get location data to one nodemcu and sending it through serial to another arduino. The serial command I'm getting right now is,

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
    }
  }

it works most of the time but sometimes I get 'T' inside the string as well. like this

lat=1.450146&longi=102464T103

What's wrong in my code?

I'm currently using google geolocation to get location data to one nodemcu and sending it through serial to another Arduino. The serial command I'm getting right now is,

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
    }
  }

It works most of the time but sometimes I get 'T' inside the string as well. like this

lat=1.450146&longi=102464T103

What's wrong in my code?

added 678 characters in body
Source Link
Nisal
  • 15
  • 7

I'm currently using google geolocation to get location data to one nodemcu and sending it through serial to another arduino. The serial command I'm getting right now is,

H11.450187T103.824745 
H1.450044T103

I'm using the following code to parse it.

 if (Serial.824895available())  {
H1.450203T103    char c = Serial.824736read();  //gets one byte from serial buffer
H1    //if (c == '\n') {  //looks for end of data packet marker
    if (c == '\n') {
     // Serial.450214T103println(readString); //prints string to serial port out
      //do stuff      
      substring = readString.824692substring(0,8);
      lati = substring;
H1      loc = readString.450164T103indexOf("T");
      substring = readString.824675substring(loc+1, loc+11);
     longi = substring;
       readString=""; //clears variable for new input
      substring=""; 

    }  
    else {     
      readString += c; //makes the string readString
    }
  }

How doit works most of the time but sometimes I break thisget 'T' inside the string into substrings so that I can use values after H for latitude and values after T for longitudeas well. like this

lat=1.450146&longi=102464T103

What's wrong in my code?

I'm currently using google geolocation to get location data to one nodemcu and sending it through serial to another arduino. The serial command I'm getting right now is,

H1.450187T103.824745 
H1.450044T103.824895 
H1.450203T103.824736 
H1.450214T103.824692 
H1.450164T103.824675 

How do I break this string into substrings so that I can use values after H for latitude and values after T for longitude?

I'm currently using google geolocation to get location data to one nodemcu and sending it through serial to another arduino. The serial command I'm getting right now is,

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
    }
  }

it works most of the time but sometimes I get 'T' inside the string as well. like this

lat=1.450146&longi=102464T103

What's wrong in my code?

Source Link
Nisal
  • 15
  • 7

Parsing Arduino Receiving Strings

I'm currently using google geolocation to get location data to one nodemcu and sending it through serial to another arduino. The serial command I'm getting right now is,

H1.450187T103.824745 
H1.450044T103.824895 
H1.450203T103.824736 
H1.450214T103.824692 
H1.450164T103.824675 

How do I break this string into substrings so that I can use values after H for latitude and values after T for longitude?