Arduino loop of ESP8266 board that measure temperature, humidity and soilmoisture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() | |
{ | |
if ( firstTime || (millis() - lastTime > SECONDS_BETWEEN_MEASUREMENTS*1000) ) | |
{ | |
firstTime = false; | |
lastTime = millis(); | |
if (!mqttClient.connected()) | |
{ | |
connectToWiFiAndBroker(); | |
} | |
mqttClient.loop(); | |
float h_indoor = dht_indoor.readHumidity(); | |
float t_indoor = dht_indoor.readTemperature(); | |
publishFloatValue(h_indoor,"Home/GroundFloor/Humidity"); | |
publishFloatValue(t_indoor,"Home/GroundFloor/Temperature"); | |
int moistureWarning = digitalRead(14); | |
if (moistureWarning == 1) | |
{ | |
mqttClient.publish("Home/GroundFloor/PlantStatus", "Please water the plant!"); | |
} | |
else | |
{ | |
mqttClient.publish("Home/GroundFloor/PlantStatus", "Plant is ok!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment