Arduino “having11” Guy
Published © GPL3+

ESP8266 Temperature Monitor

Get an alert if your fridge's temperature rises above 40 F (very dangerous!).

EasyFull instructions provided1 hour6,226
ESP8266 Temperature Monitor

Things used in this project

Story

Read more

Schematics

Schematic

Connect as-is
Schematic bb 5pzmygjv44

Code

The Code

C/C++
Copy and Paste, enter in your credentials.
#include "DHT.h"

#define DHTPIN 2     // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE, 11);

TaskManager taskManager;

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

char ssid[] = "ssid" //SSID name
char wifiPassword[] = "wifi password"

char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

void setup() {
  if(taskManager.RestartedFromSleep()){
    //wake
    Serial.begin(9600);
    dht.begin();
    Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  }
  else{
    //normal boot
    Serial.begin(9600);
    dht.begin();
    Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  }
}

void loop() {
  Cayenne.loop();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Cayenne.virtualWrite(0, f);
  taskManager.EnterSleep(1000000 * 60 * 60 * 2); //Wait for 2 hours
}

CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

Credits

Arduino “having11” Guy

Arduino “having11” Guy

28 projects • 184 followers
IoT, Arduino, and Raspberry Pi. I can create designs, code, and build projects for only $22/hr. Just message me with your project request.
Contact

Comments