Implement XML reading output and update timestamp handling in sensor loop
This commit is contained in:
+25
-7
@@ -2,10 +2,13 @@
|
||||
#include <Adafruit_SHT4x.h>
|
||||
|
||||
Adafruit_SHT4x sht4 = Adafruit_SHT4x();
|
||||
uint32_t timestamp = millis();
|
||||
|
||||
void sendReadingXML(uint32_t timestamp, float temperature, float humidity, const char *id);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200); // zacni seriovou komunikaci s baudrate 115200
|
||||
Serial.begin(115200); // zacni seriovou komunikaci s baudrate 9600
|
||||
Serial.println("UART OK");
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT); // nastav ledku na desce jako vystup
|
||||
@@ -28,17 +31,32 @@ void loop()
|
||||
{
|
||||
sensors_event_t humidity, temp;
|
||||
|
||||
uint32_t timestamp = millis();
|
||||
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= ");
|
||||
Serial.print(temp.temperature);
|
||||
Serial.print(" humidity=");
|
||||
Serial.println(humidity.relative_humidity);
|
||||
sendReadingXML(timestamp, temp.temperature, humidity.relative_humidity, "SHT40");
|
||||
|
||||
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
delay(250); // wait for a second
|
||||
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
|
||||
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