Things used in this project

Schematics

Schematic
Connect as-is
Schematic bb 5pzmygjv44

Code

The CodeC/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

Download
Arduino “having11” Guy
24 projects • 153 followers
I love creating cloud solutions that can interact with hardware along with using Arduino boards and Raspberry Pis to create new projects.
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog