diff options
-rw-r--r-- | src/main.cpp | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/main.cpp b/src/main.cpp index d8122a6..85fe3fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include <DallasTemperature.h> #include <DHT.h> #include <stdlib.h> +#include <inttypes.h> // Pin setup const int oneWirePin = 7; @@ -18,35 +19,42 @@ DHT dht(dhtPin, DHTTYPE); void setup () { Serial.begin(9600); dht.begin(); + sensors.begin(); } -void loop () { - sensors.requestTemperatures(); - - float t1 = sensors.getTempCByIndex(0); - - float t2 = dht.readTemperature(); - float h1 = dht.readHumidity(); - - char temp[BUFSIZE]; - // format: <timestamp|0> t:1=<temp> t:2=<temp> h:1=<humidity> - String line = ""; - line += 0; +void print_float2serial(float val) { + char buf[BUFSIZE]; + dtostrf(val, 5, 2, buf); + Serial.print(buf); +} +void print_value(char* type, uint8_t id, float val) { + Serial.print(" "); + Serial.print(type); + Serial.print(":"); + Serial.print(id); + Serial.print("="); + print_float2serial(val); +} - line += " t:1="; - dtostrf(t1, 5, 2, temp); - line += temp; +void loop () { + sensors.requestTemperatures(); - line += " t:2="; - dtostrf(t2, 5, 2, temp); - line += temp; + uint8_t devcounter = 0; - line += " h:1="; - dtostrf(h1, 5, 2, temp); - line += temp; + // output format: <timestamp|0> t:1=<temp> t:2=<temp> h:1=<humidity> + Serial.print("0"); + for (uint8_t i = 0; i < sensors.getDeviceCount(); ++i) { + float temp = sensors.getTempCByIndex(i); + print_value("t", devcounter++, temp); + } + float t1 = dht.readTemperature(); + float h1 = dht.readHumidity(); - Serial.println(line); + print_value("t", devcounter, t1); + print_value("h", devcounter, h1); + devcounter++; + Serial.println(); delay(10000); } |