2013-11-06 16:32:29 -05:00
|
|
|
//
|
|
|
|
// FILE: XMLWriterTest.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: make a simple XML generating lib
|
|
|
|
// DATE: 2013-11-06
|
2020-05-25 03:58:04 -04:00
|
|
|
// URL: https://github.com/RobTillaart/XMLWriter
|
2021-12-29 10:27:03 -05:00
|
|
|
|
2013-11-06 16:32:29 -05:00
|
|
|
|
|
|
|
#include <XMLWriter.h>
|
|
|
|
|
|
|
|
XMLWriter XML(&Serial);
|
|
|
|
|
|
|
|
char buffer[24];
|
|
|
|
|
2021-11-11 14:36:58 -05:00
|
|
|
|
2013-11-06 16:32:29 -05:00
|
|
|
void setup()
|
|
|
|
{
|
2013-11-07 14:02:40 -05:00
|
|
|
Serial.begin(115200);
|
2013-11-06 16:32:29 -05:00
|
|
|
|
2020-05-25 03:58:04 -04:00
|
|
|
uint32_t start = micros();
|
|
|
|
XML.setConfig(0); // comment this line to see difference
|
|
|
|
|
2013-11-07 14:02:40 -05:00
|
|
|
XML.header();
|
2015-03-07 18:11:56 -05:00
|
|
|
XML.comment("XMLWriterTest.ino\nThis is a demo of a simple XML lib for Arduino", true);
|
2020-05-25 03:58:04 -04:00
|
|
|
// XML.newLine(0);
|
2013-11-07 14:02:40 -05:00
|
|
|
XML.tagOpen("Arduino", "42");
|
2013-11-06 16:32:29 -05:00
|
|
|
|
2013-11-07 14:02:40 -05:00
|
|
|
XML.tagOpen("Ports");
|
|
|
|
AnalogPorts("before");
|
|
|
|
DigitalPorts();
|
|
|
|
AnalogPorts("after");
|
|
|
|
XML.tagClose();
|
2013-11-06 16:32:29 -05:00
|
|
|
|
2013-11-07 14:02:40 -05:00
|
|
|
Weather();
|
|
|
|
Weather2();
|
2015-03-07 18:11:56 -05:00
|
|
|
DataTypes();
|
2013-11-06 16:32:29 -05:00
|
|
|
|
2013-11-07 14:02:40 -05:00
|
|
|
XML.tagClose();
|
2021-11-11 14:36:58 -05:00
|
|
|
XML.flush();
|
2020-05-25 03:58:04 -04:00
|
|
|
uint32_t stop = micros();
|
|
|
|
Serial.println(stop - start);
|
|
|
|
Serial.println("done...");
|
2013-11-06 16:32:29 -05:00
|
|
|
}
|
|
|
|
|
2021-11-11 14:36:58 -05:00
|
|
|
|
2013-11-07 14:02:40 -05:00
|
|
|
void Weather2()
|
2013-11-06 16:32:29 -05:00
|
|
|
{
|
2013-11-07 14:02:40 -05:00
|
|
|
XML.comment("The weather in South Africa");
|
2020-05-25 03:58:04 -04:00
|
|
|
for (int i = 0; i < 10; i++)
|
2013-11-07 14:02:40 -05:00
|
|
|
{
|
|
|
|
XML.tagStart("Weather");
|
|
|
|
XML.tagField("Date", "20131106");
|
|
|
|
XML.tagField("Time", "1:42");
|
|
|
|
XML.tagField("Temp", "23.4");
|
|
|
|
XML.tagField("Humi", "50%");
|
|
|
|
XML.tagField("Rain", "10mm");
|
|
|
|
XML.tagField("Sun", "40");
|
|
|
|
XML.tagEnd();
|
|
|
|
}
|
2013-11-06 16:32:29 -05:00
|
|
|
}
|
|
|
|
|
2021-11-11 14:36:58 -05:00
|
|
|
|
2013-11-07 14:02:40 -05:00
|
|
|
void Weather()
|
2013-11-06 16:32:29 -05:00
|
|
|
{
|
2013-11-07 14:02:40 -05:00
|
|
|
XML.comment("The weather in Nebraska");
|
|
|
|
XML.tagOpen("Weather");
|
|
|
|
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();
|
2013-11-06 16:32:29 -05:00
|
|
|
}
|
|
|
|
|
2021-11-11 14:36:58 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
// casting to keep some compilers happy
|
2017-07-26 17:20:49 -04:00
|
|
|
void AnalogPorts(const char* name)
|
2013-11-06 16:32:29 -05:00
|
|
|
{
|
2013-11-07 14:02:40 -05:00
|
|
|
XML.comment("The analog ports are multiplexed");
|
|
|
|
XML.tagOpen("Analog", name);
|
|
|
|
XML.writeNode("Analog0", itoa(analogRead(A0), buffer, 10));
|
2021-01-29 06:31:58 -05:00
|
|
|
XML.writeNode("Analog1", (uint16_t) analogRead(A1));
|
|
|
|
XML.writeNode("Analog2", (double) (5.0*analogRead(A2))/1023); // default nr decimals = 2
|
|
|
|
XML.writeNode("Analog3", (double) (5.0*analogRead(A2))/1023, (uint8_t)3);
|
2013-11-07 14:02:40 -05:00
|
|
|
XML.tagClose();
|
2013-11-06 16:32:29 -05:00
|
|
|
}
|
|
|
|
|
2021-11-11 14:36:58 -05:00
|
|
|
|
2013-11-07 14:02:40 -05:00
|
|
|
void DigitalPorts()
|
|
|
|
{
|
|
|
|
XML.comment("The digital ports are not multiplexed");
|
|
|
|
XML.tagOpen("Digital");
|
|
|
|
XML.writeNode("D1", itoa(digitalRead(1), buffer, 10));
|
2021-01-29 06:31:58 -05:00
|
|
|
XML.writeNode("D13", (uint8_t)digitalRead(13));
|
2013-11-07 14:02:40 -05:00
|
|
|
XML.tagClose();
|
|
|
|
}
|
|
|
|
|
2021-11-11 14:36:58 -05:00
|
|
|
|
2015-03-07 18:11:56 -05:00
|
|
|
void DataTypes()
|
2013-11-06 16:32:29 -05:00
|
|
|
{
|
2015-03-07 18:11:56 -05:00
|
|
|
XML.comment("Testing dataTypes I");
|
|
|
|
XML.tagOpen("Datatypes");
|
2020-05-25 03:58:04 -04:00
|
|
|
XML.writeNode("BoolT", 1 == 1);
|
|
|
|
XML.writeNode("BoolF", 1 == 0);
|
2015-03-07 18:11:56 -05:00
|
|
|
XML.writeNode("BIN", 42, BIN);
|
|
|
|
XML.writeNode("DEC", 42, DEC);
|
|
|
|
XML.writeNode("HEX", 42, HEX);
|
|
|
|
XML.writeNode("OCT", 42, OCT);
|
|
|
|
XML.tagClose();
|
2020-05-25 03:58:04 -04:00
|
|
|
|
2015-03-07 18:11:56 -05:00
|
|
|
XML.comment("Testing dataTypes II");
|
2020-05-25 03:58:04 -04:00
|
|
|
for (int i = 0; i < 3; i++)
|
2015-03-07 18:11:56 -05:00
|
|
|
{
|
|
|
|
XML.tagStart("dataTypes");
|
2020-05-25 03:58:04 -04:00
|
|
|
XML.tagField("BoolT", 1 == 1);
|
|
|
|
XML.tagField("BoolF", 1 == 0);
|
2015-03-07 18:11:56 -05:00
|
|
|
int x = analogRead(A0);
|
|
|
|
XML.tagField("BIN", x, BIN);
|
|
|
|
XML.tagField("DEC", x, DEC);
|
|
|
|
XML.tagField("HEX", x, HEX);
|
|
|
|
XML.tagField("OCT", x, OCT);
|
|
|
|
XML.tagEnd();
|
|
|
|
}
|
2013-11-06 16:32:29 -05:00
|
|
|
}
|
2013-11-07 14:02:40 -05:00
|
|
|
|
2021-11-11 14:36:58 -05:00
|
|
|
|
2015-03-07 18:11:56 -05:00
|
|
|
void loop()
|
|
|
|
{
|
2020-05-25 03:58:04 -04:00
|
|
|
}
|
|
|
|
|
2021-11-11 14:36:58 -05:00
|
|
|
|
2020-05-25 03:58:04 -04:00
|
|
|
// -- END OF FILE --
|
2021-11-11 14:36:58 -05:00
|
|
|
|