Go Down

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

beic

Really want to use this Library, but how can I stream the output to String?

Thank you!  ;)
..:: Maybe Noob for Arduino, but Geek for VB6 ::..

robtillaart

// copy of github issue

You can use this class

Code: (experimental) [Select]
//
//    FILE: PrintString.h
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: Class that captures prints into a String
//    DATE: 2017-12-07
//     URL:
//
// Released to the public domain
//

#ifndef PrintString_h
#define PrintString_h

#include "Arduino.h"
#include "Print.h"

#define PRINTSTRING_VERSION "0.1.0"

class PrintString: public Print
{
public:
  PrintString() {};
  
  size_t write(uint8_t c)
  {
    buffer += (char)c;
    return 1;
  }
  
  void clear()
  {
    buffer = "";
  }
 
  String getString() { return buffer; }

private:
  String buffer;
};
#endif
// -- END OF FILE --


and use like this

Code: [Select]
//
//    FILE: printString.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.0.1
// PURPOSE: demo experimental
//
// HISTORY:

#include "PrintString.h"

#include "XMLWriter.h"

PrintString ps;
XMLWriter XML(&ps);
char buffer[24];

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

  ps.println("Hello World");
  ps.println(3.14159265, 4);
  Serial.println(ps.getString());

  ps.clear();
  ps.println(3.14159265, 4);
  ps.println("Hello World");
  Serial.println(ps.getString());

  ps.clear();

  XML.header();
  XML.comment("Weather in Nebraska");
  XML.tagOpen("Data");
  XML.writeNode("Date", "20131106");
  XML.writeNode("Time", "11:42");
  XML.writeNode("Temp", "23.4");
  XML.writeNode("Humi", "50%");
  XML.writeNode("Rain", "10mm");
  XML.writeNode("Sun", "40");
  XML.tagClose();

  Serial.println(ps.getString());
 
  Serial.println("done...");
}

void loop()
{}
Rob Tillaart

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

robtillaart

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
Late answer, don't know it is relevant

Yes you can store these in an XML in a very similar way as in the examples of the library.
If you still need help, post your code you have- and yes I do expect some serious code after a year :)
Rob Tillaart

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

Go Up