summaryrefslogtreecommitdiff
path: root/cricket.ino
diff options
context:
space:
mode:
Diffstat (limited to 'cricket.ino')
-rw-r--r--cricket.ino18
1 files changed, 12 insertions, 6 deletions
diff --git a/cricket.ino b/cricket.ino
index 46430f0..0166db5 100644
--- a/cricket.ino
+++ b/cricket.ino
@@ -8,8 +8,8 @@
#define WIFI_PASS "PASS"
WiFiClient wifiClient;
-#define MQTT_ID "ID"
-#define MQTT_BROKER "BROKER"
+#define MQTT_ID "cricket1"
+#define MQTT_BROKER "192.168.0.59"
PubSubClient mqttClient(wifiClient);
#define DHTPIN 5 //Pin D1
@@ -64,17 +64,21 @@ void connectMqtt() {
void loop() {
delay(1500);
- float h = analogRead(ANALOG_PIN);
+ float m = analogRead(ANALOG_PIN);
+ float h = dht.readHumidity();
float t = dht.readTemperature();
char t_msg[20];
char h_msg[20];
+ char m_msg[20];
// Check if any reads failed and exit early (to try again).
- if (isnan(h) || isnan(t)) {
+ if (isnan(h) || isnan(t) || isnan(m)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Moisture: ");
+ Serial.print(m);
+ Serial.print(" Humidity: ");
Serial.print(h);
Serial.print(" Temperature: ");
Serial.println(t);
@@ -83,7 +87,9 @@ void loop() {
connectMqtt();
}
dtostrf(t, 1, 2, t_msg);
- mqttClient.publish("temperature", t_msg);
+ mqttClient.publish("cricket1/temperature", t_msg);
dtostrf(h, 1, 2, h_msg);
- mqttClient.publish("moisture", h_msg);
+ mqttClient.publish("cricket1/humidity", h_msg);
+ dtostrf(m, 1, 2, m_msg);
+ mqttClient.publish("cricket1/moisture", m_msg);
}