diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..d8122a6 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,52 @@ +#include <Arduino.h> +#include <Wire.h> +#include <DallasTemperature.h> +#include <DHT.h> +#include <stdlib.h> + +// Pin setup +const int oneWirePin = 7; +const int dhtPin = 2; +#define DHTTYPE DHT22 + +#define BUFSIZE 32 + +OneWire oneWire(oneWirePin); +DallasTemperature sensors(&oneWire); +DHT dht(dhtPin, DHTTYPE); + +void setup () { + Serial.begin(9600); + dht.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; + + line += " t:1="; + dtostrf(t1, 5, 2, temp); + line += temp; + + line += " t:2="; + dtostrf(t2, 5, 2, temp); + line += temp; + + line += " h:1="; + dtostrf(h1, 5, 2, temp); + line += temp; + + + Serial.println(line); + delay(10000); +} |