Skip to content
Permalink
Browse files

Arduino ESP8266 to IFTTT

Used to send DHT data from ESP8266 to IFTTT to receive email and text through Maker API key
  • Loading branch information...
sborsay committed Sep 1, 2016
1 parent cfc018c commit 94f34e13f4e95b9dff42394b542e2bbbf959dc90
Showing with 116 additions and 0 deletions.
  1. +116 −0 IFTTT_ESP8266
@@ -0,0 +1,116 @@
/*
* This sketch is combined from ADAfruit DHT sensor and tdicola for dht.h library
* Along with some esp8266 NodeMCU specifics from teos009
*
* https://learn.adafruit.com/dht/overview
* https://gist.github.com/teos0009/acad7d1e54b97f4b2a88
*/

#include "ESP8266WiFi.h"
#include "DHT.h"
#define DHTPIN 2 // what digital pin we're connected to pin2 to D4 on esp board

// Uncomment whatever DHT sensor type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21
//#define DHTTYPE DHT22 // DHT 22

DHT dht(DHTPIN,DHTTYPE);
#define WEBSITE "maker.ifttt.com"


const char * MY_SSID = "<YOUR-SSID>";
const char * MY_PWD = "<WIFI-PASSWORD>";


//use these if you change REST Sting below
//const char * Event_Name = "<Your_Event_Name>";
//const char * Maker_Api_Key = "<Your_api_key>";



void setup()
{
Serial.begin(115200);
dht.begin();
Serial.print("Connecting to "+*MY_SSID);
WiFi.begin(MY_SSID, MY_PWD);

while (WiFi.status() != WL_CONNECTED) //not connected, ...waiting to connect
{
delay(1000);
Serial.print(".");
}

Serial.println("");
Serial.println("Credentials accepted! Connected to wifi\n ");
Serial.println("");
}


void loop()
{
// Wait a few seconds between measurements.
delay(2000);

float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f))
{
Serial.println("Failed to read from DHT sensor!");
return;
}

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F\n");
Serial.println ((String) Event_Name );


WiFiClient client;

if (client.connect(WEBSITE, 80))
{

Serial.println("WiFi Client connected ");

client.print(String("POST ") +
"/trigger/<Your_Event_Name>/with/key/<Maker_Api_Key>?value1="
+ (String) h
+ "&value2=" + (String) t
+ "&value3=" + (String) f
// + "&Value4=" + (String) hic
// + "&Value5=" + (String) hif

+ " HTTP/1.1\r\n"
+ "Host: " + WEBSITE + "\r\n"
+ "Connection: close\r\n\r\n"
);

delay(30000);
} //end client connect

else Serial.print("couldnt connect to IFTTT\n"); //if client connect failed

client.stop();
}

0 comments on commit 94f34e1

Please sign in to comment.
You can’t perform that action at this time.