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

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

Similar projects you might like

ESP8266 NodeMCU WiFi IoT Garage Door Opener Relay with Cayen
Easy
  • 56
  • 3

In this project, we will use an ESP8266 with Cayenne to control a Garage Door Opener.

Safe City: A Device to Keep You Safe
Easy
  • 630
  • 6

Full instructions

The device will keep you safe. Just have to click a button and your precise location will be shared.

Web-Based Universal Remote for Under $4 (Probably)
Easy
  • 1,600
  • 9

Don't buy a universal remote, make one. It's cheaper, funner, universal-er, kind of, and you get to learn the ESP8266, kind of.

Arduino UNO Home Automation using Bluetooth HC05 module
Easy
  • 13
  • 1

Protip

Home Automation Attributes: Turning ON/OFF light bulb (AC 220V). Automatically Turning the Led ON/OFF depending on light intensity.

Biometric-Based Student Attendance System
Easy
  • 521
  • 9

This is a fun an easy DIY project that enables you automatically capture students attendance bio-metrically via fingerprint.

NodeMCU, Dweet.io & Freeboard.io
Easy
  • 8
  • 1

A simple IoT test to monitor analog values of a potentiometer & a thumbstick using Dweet.io & Freeboard.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog