summaryrefslogtreecommitdiff
path: root/arduino
diff options
context:
space:
mode:
Diffstat (limited to 'arduino')
-rw-r--r--arduino/data_collect/data_collect.ino22
1 files changed, 14 insertions, 8 deletions
diff --git a/arduino/data_collect/data_collect.ino b/arduino/data_collect/data_collect.ino
index 27a44e3..482c9a3 100644
--- a/arduino/data_collect/data_collect.ino
+++ b/arduino/data_collect/data_collect.ino
@@ -3,7 +3,9 @@
#include <PubSubClient.h>
#include "DHT.h"
-#define TOPIC "data/here/temperature"
+#define TOPIC_T "data/here/temperature"
+#define TOPIC_H "data/here/humidity"
+#define TOPIC_A "data/here/available"
#define DHTPIN 2
#define DHTTYPE DHT22
@@ -21,19 +23,23 @@ void setup() {
Ethernet.begin(mac, ip);
dht.begin();
Serial.begin(9600);
+ if (client.connect("arduinoClient")) {
+ client.publish(TOPIC_A,"1");
+ }
}
void loop() {
- //client.loop();
float t = dht.readTemperature();
float h = dht.readHumidity();
- //String temp = String(t);
- Serial.println(t);
+ //Serial.println(t);
+ //Serial.println(h);
char temp[6];
dtostrf(t, 5, 2, temp);
- Serial.print(temp);
- if (client.connect("arduinoClient")) {
- client.publish(TOPIC,temp);
- }
+ //Serial.println(temp);
+ char hum[6];
+ dtostrf(h, 5, 2, hum);
+ //Serial.println(hum);
+ client.publish(TOPIC_T,temp);
+ client.publish(TOPIC_H,hum);
delay(5000);
}