diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2015-03-28 18:15:01 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2015-03-28 18:15:01 +0100 |
commit | 71d0f75ef6af70b4f8b7b72f777ef54e14d5df21 (patch) | |
tree | 114fdb912b6dae2b391e0d2955581323a449d425 /arduino/data_collect | |
parent | 4e7c4573108720d9c62b6f528b8ae910a750b4a9 (diff) |
Start support for DHT
Diffstat (limited to 'arduino/data_collect')
-rw-r--r-- | arduino/data_collect/data_collect.ino | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/arduino/data_collect/data_collect.ino b/arduino/data_collect/data_collect.ino index c8013b9..27a44e3 100644 --- a/arduino/data_collect/data_collect.ino +++ b/arduino/data_collect/data_collect.ino @@ -1,9 +1,15 @@ #include <SPI.h> #include <Ethernet.h> #include <PubSubClient.h> +#include "DHT.h" #define TOPIC "data/here/temperature" +#define DHTPIN 2 +#define DHTTYPE DHT22 + +DHT dht(DHTPIN, DHTTYPE); + byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; byte server[] = { 192, 168, 1, 33 }; byte ip[] = { 192, 168, 1, 72 }; @@ -13,13 +19,21 @@ PubSubClient client(server, 1883, 0, ethClient); void setup() { Ethernet.begin(mac, ip); - + dht.begin(); + Serial.begin(9600); } void loop() { - client.loop(); + //client.loop(); + float t = dht.readTemperature(); + float h = dht.readHumidity(); + //String temp = String(t); + Serial.println(t); + char temp[6]; + dtostrf(t, 5, 2, temp); + Serial.print(temp); if (client.connect("arduinoClient")) { - client.publish(TOPIC,"12"); + client.publish(TOPIC,temp); } delay(5000); } |