Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Arduino loop of ESP8266 board that measure temperature, humidity and soilmoisture
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