Implement XML reading output and update timestamp handling in sensor loop
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
<reading time="10" id="SHT40">
|
||||||
|
<temp unit="C">
|
||||||
|
23.45
|
||||||
|
</temp>
|
||||||
|
<humidity unit="%">
|
||||||
|
48.12
|
||||||
|
</humidity>
|
||||||
|
</reading>
|
||||||
+25
-7
@@ -2,10 +2,13 @@
|
|||||||
#include <Adafruit_SHT4x.h>
|
#include <Adafruit_SHT4x.h>
|
||||||
|
|
||||||
Adafruit_SHT4x sht4 = Adafruit_SHT4x();
|
Adafruit_SHT4x sht4 = Adafruit_SHT4x();
|
||||||
|
uint32_t timestamp = millis();
|
||||||
|
|
||||||
|
void sendReadingXML(uint32_t timestamp, float temperature, float humidity, const char *id);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200); // zacni seriovou komunikaci s baudrate 115200
|
Serial.begin(115200); // zacni seriovou komunikaci s baudrate 9600
|
||||||
Serial.println("UART OK");
|
Serial.println("UART OK");
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT); // nastav ledku na desce jako vystup
|
pinMode(LED_BUILTIN, OUTPUT); // nastav ledku na desce jako vystup
|
||||||
@@ -28,17 +31,32 @@ void loop()
|
|||||||
{
|
{
|
||||||
sensors_event_t humidity, temp;
|
sensors_event_t humidity, temp;
|
||||||
|
|
||||||
uint32_t timestamp = millis();
|
|
||||||
sht4.getEvent(&humidity, &temp); // cteni ze senzoru
|
sht4.getEvent(&humidity, &temp); // cteni ze senzoru
|
||||||
timestamp = millis() - timestamp; // ziskani delky cteni ze senzoru
|
timestamp = millis(); // pocet milisekund od spusteni procesoru
|
||||||
|
|
||||||
Serial.print("temp= ");
|
sendReadingXML(timestamp, temp.temperature, humidity.relative_humidity, "SHT40");
|
||||||
Serial.print(temp.temperature);
|
|
||||||
Serial.print(" humidity=");
|
|
||||||
Serial.println(humidity.relative_humidity);
|
|
||||||
|
|
||||||
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
|
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||||
delay(250); // wait for a second
|
delay(250); // wait for a second
|
||||||
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
|
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
|
||||||
delay(250); // wait for a second
|
delay(250); // wait for a second
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendReadingXML(uint32_t timestamp, float temperature, float humidity, const char *id)
|
||||||
|
{
|
||||||
|
Serial.print("<reading time=\"");
|
||||||
|
Serial.print(timestamp);
|
||||||
|
Serial.print("\" id=\"");
|
||||||
|
Serial.print(id);
|
||||||
|
Serial.println("\">");
|
||||||
|
|
||||||
|
Serial.print(" <temp unit=\"C\">");
|
||||||
|
Serial.print(temperature, 2);
|
||||||
|
Serial.println("</temp>");
|
||||||
|
|
||||||
|
Serial.print(" <humidity unit=\"%\">");
|
||||||
|
Serial.print(humidity, 2);
|
||||||
|
Serial.println("</humidity>");
|
||||||
|
|
||||||
|
Serial.println("</reading>");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user