From 2e49dcff5f0615ff7f166382cf6c1038c8643a60 Mon Sep 17 00:00:00 2001 From: Elena of Valhalla'' Grandi Date: Sun, 3 May 2015 20:14:02 +0200 Subject: Fix client.connect and publish also humidity --- arduino/data_collect/data_collect.ino | 22 ++++++++++++++-------- 1 file 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 #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); } -- cgit v1.2.3