Go Down

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

PaulS

Pictures of code are not next to useless. They are so far less than useless.

Post your code AS TEXT.

The XML you appear to get from the server is NOT well formed. You should fix that issue FIRST.
The art of getting good answers lies in asking good questions.

dito

#34
Jun 04, 2018, 03:16 am Last Edit: Jun 04, 2018, 03:34 am by dito
how to receive xml request from x100c fingerprint with ethershield,
example using pascal:


i try thi code :
Code: [Select]

#include <SPI.h>
#include <Ethernet.h>
#include <XMLWriter.h>

XMLWriter XML(&Serial);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(10,45,1,7);  // IP Fingerprint x100c
IPAddress ip(10,45,1,6);      // IP Arduino

EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Ethernet.begin(mac, ip);
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
  
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    
    XML.header();
    XML.tagOpen("GetAttLog");
    XML.writeNode("ArfComkey xsi:type=\"xsd:integer\"","0");
    XML.tagOpen("Arg");
    XML.writeNode("PIN xsi:type=\"xsd:integer\"","ALL");
    XML.tagClose();
    XML.tagClose();
    
    String method = "GET /iWsService\r\n";
      method += "HTTP/1.1\r\n";
      method += "Host: 192.168.10.1\r\n";
      method += "Connection: Close\r\n";
      method += "<GetAttLog><ArgComKey xsi:type=\"xsd:integer\">0</ArgComKey><Arg><PIN xsi:type=\"xsd:integer\">All</PIN></Arg></GetAttLog>";
      
    String content = String (method);
    Serial.println(content);
    
    // Make a HTTP request:
    client.println("GET /iWsService HTTP/1.1");
    client.println("content-type: text/xml");
    client.println("content-length: 128");
    
    client.println("<GetAttLog><ArgComKey xsi:type=\"xsd:integer\">0</ArgComKey><Arg><PIN xsi:type=\"xsd:integer\">All</PIN></Arg></GetAttLog>");

    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }

}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
  
}


im stuck parse and execute xml comand from finger print,
and im try but not show .

and show my serial monitor..
Code: [Select]

connecting...
connected
<?xml version="1.0" encoding="UTF-8">
<GetAttLog>
  <ArfComkey xsi:type="xsd:integer">0</ArfComkey xsi:t>
  <Arg>
    <PIN xsi:type="xsd:integer">ALL</PIN xsi:type="x>
  </Arg>
</GetAttLog>
GET /iWsService
HTTP/1.1
Host: 192.168.10.1
Connection: Close
<GetAttLog><ArgComKey xsi:type="xsd:integer">0</ArgComKey><Arg><PIN xsi:type="xsd:integer">All</PIN></Arg></GetAttLog>
HTTP/1.0 200 OK
Server: ZK Web Server
Pragma: no-cache
Cache-control: no-cache
Content-Type: text/xml
Connection: close


disconnecting.



Go Up