[Resolved] GPS Data into KML Wrapper SD File

Hello together,

i try to write Data in between lines of a predefined KML Wrapper

This is what the Wrapper i write to the file looks like:

if(kmlFile){
        kmlFile.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        kmlFile.println("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
        kmlFile.println("<Document><Style id=\"transBluePoly\"><LineStyle><color>7f00ffff</color><width>4</width></LineStyle><PolyStyle><color>7f00ff00</color></PolyStyle></Style><Placemark><styleUrl>#yellowPoly</styleUrl><LineString><extrude>1</extrude><tesselate>1</tesselate><altitudeMode>absolute</altitudeMode><coordinates>");
        kmlFile.println(" ");
        kmlFile.println("</coordinates></LineString></Placemark></Document></kml>");
        Serial.println("Wrapper written!");
        kmlFile.close();
      }else{
        Serial.println("File couldn't be opened.");

What i try to do is, to write into the 4. Line. So i seek() for the correct character what works fine so far. But when i begin to print(), it overwrites from that position instead of filling in. So i always overwrites the last GPS Data, what isnt so good for Track building and also destroys the Wrapper at the first write. :slight_smile:

Any suggestions appreciated.

Kind Regards
Dominik

DasBoeseblub:
Hello together,

i try to write Data in between lines of a predefined KML Wrapper

This is what the Wrapper i write to the file looks like:

if(kmlFile){

kmlFile.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
       kmlFile.println("<kml xmlns="http://www.opengis.net/kml/2.2\">");
       kmlFile.println("<Style id="transBluePoly">7f00ffff47f00ff00#yellowPoly11absolute");
       kmlFile.println(" ");
       kmlFile.println("");
       Serial.println("Wrapper written!");
       kmlFile.close();
     }else{
       Serial.println("File couldn't be opened.");




What i try to do is, to write into the 4. Line. So i seek() for the correct character what works fine so far. But when i begin to print(), it overwrites from that position instead of filling in. So i always overwrites the last GPS Data, what isnt so good for Track building and also destroys the Wrapper at the first write. :) 

Any suggestions appreciated. 

Kind Regards
Dominik

Ok,
This is my interpretation of your question:

  • You have a text datafile on a SdCard.
  • You want to insert some data into this existing text file.
  • You are using random access methods (file.seek()) to position the file pointer.
  • You are complaining that when you fill.seek() to a specific byte offset and println() from there you are overwriting existing data?

To achieve a text insertion into a data file you have to create space for your insertion. The two standard methods are:

  • Create a new file, copy all data from the existing file up to the insertion point, add the new info, continue copying the remainder of the 'old' data, close the 'new' file, delete the 'old' file, rename the 'new' file as the 'old' file.
  • make room in the existing file by extending the file, moving all the current data, then insert your new data.

Your choice on which one to use.

Chuck.

Hey chucktodd,

thanks for your suggestions. Point 1 of it gave me the clue how to solve it. I dont copy things around now but i write the higher portion of the wrapper now at the setup. Then i use sdfile.seek(sdfile.read()-) and then write the data + lower portion all the time. :slight_smile:

Cheers and thanks a lot