Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <DHT.h>
- #include <IFTTTMaker.h>
- #include <ESP8266WiFi.h>
- #include <WiFiClientSecure.h>
- #define DHTTYPE DHT11
- #define DHTPIN 14 // The signal pin f the DHT11, in this case 14, which corresponds to D5
- #define EVENT_NAME "THE NAME OF THE IFTTT Event"
- #define KEY "YOUR IFTTT API KEY GOES HERE..."
- float temperature, humidity;
- const char ssid[] = "YOUR WIFI SSID";
- const char password[] = "YOUR WIFI PASSWORD";
- DHT dht(DHTPIN, DHTTYPE, 11); // Defining the DHT11
- WiFiClientSecure client; // Defining the client
- IFTTTMaker ifttt(KEY, client); // Defining the use of IFTTT
- void setup() {
- dht.begin();
- humidity = dht.readHumidity(); // Reads the humidity from the sensor and stores it in a variable
- temperature = dht.readTemperature(); // Reads the temperature from the sensor and stores it in a variable
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- WiFi.disconnect();
- delay(100);
- Serial.print("Connecting Wifi: ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- Serial.print(".");
- delay(500);
- }
- Serial.println("");
- Serial.println("WiFi connected");
- }
- void loop() {
- humidity = dht.readHumidity();
- temperature = dht.readTemperature();
- // You need to paste the variables containing the sensor data, which need to be converted to String type.
- if (ifttt.triggerEvent(EVENT_NAME, (String)temperature, (String)humidity) {
- Serial.println("Sent!");
- }
- else {
- Serial.println("Failed!");
- }
- delay(3600000 * 6); // Amount of time between e-mails, in miliseconds // 3 600 000 miliseconds = 1 hour // 1 hour * 6 = 6 hours
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement