Go Down

Topic: simple XMLwriter library for Arduino (Read 16489 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?

ma_partha

How can we use this library to edit an existing XML file?

PaulS

Quote
How can we use this library to edit an existing XML file?
Read the current file. Parse it. Save the data. Write a new file.
The art of getting good answers lies in asking good questions.

robtillaart

How can we use this library to edit an existing XML file?
This library only helps with the writing part, not the reading part.
Rob Tillaart

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

TravisH

Hi there,

Love the library, I have just started to use it as I am working on a pan tilt panorama robot and will likely use the library to create an XML file which will speed the import process up fairly significantly.

I had two questions for you, the first was in a test I am outputting to serial and will eventually move this to an SD card, but I notice some of the tags are being cut off, e.g.

Code: [Select]
<cameraOrientation>landscape</cameraOrientati>
      <stabilizationDelay>250</stabilizationDe>


I was also hoping you might be able to help me, I understand the tagStart, but I am a bit lost at how I can have a tag start + field as essentially a node, apologies if I have not explained this very well but the XML scheme below might help a bit?

Code: [Select]

<shoot>
          <pict id="[int]" bracket="[int]">
              [dateTime]
              <position pitch="[float]" yaw="[float]" roll="[float]"/>
          </pict>
          ...
      </shoot>


Many thanks for your help!

robtillaart

@TravisH
Sorry for late response, too busy to track the forum.

Q1:

<cameraOrientation>landscape</cameraOrientati>
      <stabilizationDelay>250</stabilizationDe>

You should edit the XMLWRITER_MAXTAGSIZE in the .h file to be the length of the longest string + 1.
20 should work, but note it allocates the memory for XMLWRITER_MAXLEVEL strings in advance.

The other question we have discussed on github - https://github.com/RobTillaart/Arduino/issues/35
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.06 - https://github.com/RobTillaart/Arduino/tree/master/libraries/XMLWriter -

+ added functions to manipulate layout more low level
+ added XMLWriterDemo01 to show these functions
+ added sample output (as comparison)
+ fixed small error
+ removed XMLWRITER_EXTENDED #ifdef

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)

monaalhumud

Dear robtillaart ;

thank you for your contribuation about the xmlwriter ...

but i have some questions

can i insert the ehealth sensors readings coming from ehealth shield compalete kit .. connected to arduino -- and the arduino connected with the computer through USB cable..

can i get the sensors data (such as Blood pressure and Spo2)
and store the readings in XML file .. using XMLWriter... ?? and how ??



best regards







Go Up