Go Down

Topic: simple XMLwriter library for Arduino (Read 4448 times) previous topic - next topic

robtillaart

#15
May 21, 2015, 08:40 pm Last Edit: May 21, 2015, 09:16 pm by robtillaart
A minimal KML file like this should be not too difficult

source KML - http://www-user.uni-bremen.de/koelling/kml.html -

Code: (simple kml file) [Select]

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
  <Document>
  <Placemark>
   <name>my office</name>
   <LookAt>
      <longitude>8.853193712983327</longitude>
      <latitude>53.10919982492059</latitude>
      <range>500000</range><tilt>0</tilt><heading>0</heading>
   </LookAt>
   <Point>
     <coordinates>8.853193712983327,53.10919982492059,10</coordinates>
   </Point>
  </Placemark>
 </Document>
</kml>


how does your KML file look like?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

#16
May 21, 2015, 09:17 pm Last Edit: May 21, 2015, 09:21 pm by robtillaart
some time later, a simple KMLWriter

Code: (experimental) [Select]

//
//    FILE: KMLWriterTest.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: simple KML writer
//    DATE: 2015-05-21
//     URL:
//
// Released to the public domain
//

#include <XMLWriter.h>

XMLWriter KML(&Serial);

char buffer[24];

void setup()
{
  Serial.begin(115200);

  KMLTest();
}

void loop()
{
}

void KMLTest()
{
  KML.setIndentSize(2);

  KML.comment("KMLWriterTest.ino\nThis is a demo of the XMLWriter lib for Arduino", MULTILINE); // == true (default == false)

  KML.header();
  KML.tagStart("kml");
  KML.tagField("xmlns", "http://earth.google.com/kml/2.0");
  KML.tagEnd(NEWLINE, NOSLASH);

  KML.tagOpen("Document");
  KML.tagOpen("Placemark");
  KML.writeNode("name", "MyOffice");

  // should be a function
  KML.tagOpen("LookAt");
  KML.writeNode("longitude", "8.853193712983327");
  KML.writeNode("latitude", "53.10919982492059");
  KML.writeNode("range", "500000");
  KML.writeNode("tilt", "0");
  KML.writeNode("heading", "0");
  KML.tagClose();

  // should be a function
  KML.tagOpen("Point");
  KML.writeNode("coordinates", "8.853193712983327,53.10919982492059,10");
  KML.tagClose();

  KML.tagClose();  // Placemark
  KML.tagClose();  // Document

  KML.tagStart("/kml");
  KML.tagEnd(NEWLINE, NOSLASH);
}

/* output
<!--
KMLWriterTest.ino
This is a demo of the XMLWriter lib for Arduino
 -->
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
  <Placemark>
    <name>MyOffice</name>
    <LookAt>
      <longitude>8.853193712983327</longitude>
      <latitude>53.10919982492059</latitude>
      <range>500000</range>
      <tilt>0</tilt>
      <heading>0</heading>
    </LookAt>
    <Point>
      <coordinates>8.853193712983327,53.10919982492059,10</coordinate>
    </Point>
  </Placemark>
</Document>
</kml>
*/



Sketch uses 3,392 bytes (10%) of program storage space. Maximum is 32,256 bytes.
Global variables use 640 bytes (31%) of dynamic memory, leaving 1,408 bytes for local variables. Maximum is 2,048 bytes.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

popescu_eduard

what if I want to put temperature in my mapping?

robtillaart

Then you can do that in a similar way, likee

KML.writeNode("Celsius", "25");
or
KML.writeNode("Fahrenheit", "82");


I do not know if KML has a predefined temperature syntax
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

upgraded to 0.1.04 - https://github.com/RobTillaart/Arduino/tree/master/libraries/XMLWriter -

+ refactored to use less RAM
+ added KML example above to the examples

Used the F() macro to move const char arrays to FLASH, but it did not improve always. For single chars using no F() was more memory efficient except in one case. Need to dive in that one sometime.

When compiling the new KML example the 0.1.04 lib added 40 bytes FLASH to gain 70 bytes RAM with respect to the 0.1.03 version.

As always comments remarks welcome.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

#20
May 23, 2015, 07:22 pm Last Edit: May 23, 2015, 07:48 pm by robtillaart
Error in the XML Writer class for writing KML files. The MAX TAG SIZE is hard coded to 10 while the coordinates tag needs 12. I'll update the class asap.

Done,  the latest version is now 0.1.05

update: fixed an order issue in the KMLWriterTest sketch too
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

KML tutorial - https://developers.google.com/kml/documentation/kml_tut -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

popescu_eduard

#22
May 28, 2015, 04:32 pm Last Edit: May 28, 2015, 04:55 pm by popescu_eduard
Then you can do that in a similar way, likee

KML.writeNode("Celsius", "25");
or
KML.writeNode("Fahrenheit", "82");


I do not know if KML has a predefined temperature syntax

maybe <celsius> </celsius> tags should do it?

Go Up