Difference between revisions of "ESP32 DHT22 IFTTT"

Line 1: Line 1:
 
{{Tuto Details
 
{{Tuto Details
 
|Main_Picture=ESP32___DHT22___IFTTT_IMG_3898.png
 
|Main_Picture=ESP32___DHT22___IFTTT_IMG_3898.png
|Main_Picture_annotation={"version":"2.4.6","objects":[{"type":"image","version":"2.4.6","originX":"left","originY":"top","left":-1185,"top":-813,"width":3024,"height":4032,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,"scaleX":0.26,"scaleY":0.26,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"crossOrigin":"","cropX":0,"cropY":0,"src":"https://wikifab.org/images/d/db/ESP32_DHT22_IFTTT_IMG_3898.png","filters":[]}],"height":450,"width":600}
+
|Main_Picture_annotation={"version":"2.4.6","objects":[{"type":"image","version":"2.4.6","originX":"left","originY":"top","left":-6,"top":-232,"width":960,"height":1280,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,"scaleX":0.64,"scaleY":0.64,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"crossOrigin":"","cropX":0,"cropY":0,"src":"https://wikifab.org/images/d/db/ESP32_DHT22_IFTTT_IMG_3898.png","filters":[]}],"height":449.40711462450594,"width":600}
 
|Description=<translate>Send DHT22 temperature and humidity values to a google sheet through ESP32 and Webhooks</translate>
 
|Description=<translate>Send DHT22 temperature and humidity values to a google sheet through ESP32 and Webhooks</translate>
 
|Area=Electronics
 
|Area=Electronics

Revision as of 18:14, 14 January 2023

Author avatarSid | Last edit 15/01/2023 by Disisid

Introduction

ESP32 connected to DHT22, to read temperature and humidity. Use IFTTT to create a webhook applet and write the DHT22 measured values to a google sheets document

Materials

Tools

Step 1 - Install Thonny or Other Python IDLE

You will need a Python IDE such as Thonny for this project. You can use any IDE, but for this project, we are using Thonny. To install and use Thonny:




Step 2 - Setup Circuit

This is how your circuit should look like. You will need the ESP32 microcontroller, DHT22 temp/humidity module, breadboard and jumper wires.

  • + pin on DHT22 to VCC on ESP
  • out pin on DHT22 to GPIO pin 15 on ESP(can change depending on code)
  • - pin on DHT22 to GND on ESP



Step 3 - Setup IFTTT

Go to https://ifttt.com/join

Sign up and create an account using the appropriate options






Step 4 - Create a new applet

First, click create in the upper right hand corner






Step 5 - Set up Applet

Then, hit Add next to IF THIS




Step 6 - Select webhooks

Once you are on "choose a service", type in Webhooks in the search bar and click Webhooks




Step 7 - Select request type

On webhooks, select receive a web request




Step 8 - Set up Webhooks Account

- If you already have a webhooks account, skip this step


Otherwise, click the connect button and follow the steps on their website to create a webhooks account




Step 9 - Name event for trigger

Name the event for the trigger esp32 (it is case sensitive so be careful)




Step 10 - Set up reaction

Once the trigger is set up, click Add next to Then That




Step 11 - Select google sheets

In the search bar, search sheets and click google sheets




Step 12 - Set up sheets

Select Add row to spreadsheet




Step 13 - Connect to sheets

Click the Connect button




Step 14 - Sign in using gmail

Use your gmail to sign in to sheets




Step 15 - Configure spreadsheet

Select all the values you want returned to the spreadsheet, along with the path the sheet has to follow in your drive.


For this project, we are returning Temperature and Humidity values from the DHT22, so we will select Value1 and Value2



Step 16 - Finish applet

Once you have finished all the previous steps, hit continue on the applet page




Step 17 - Name applet

Rename the applet to an appropriate name




Step 18 - Get API key

Select the Webhooks icon on the finished page




Step 19 - Go to documentation

Click documentation on the webhooks page




Step 20 - Copy API key

Once you get onto this page, copy the api key and URL to paste into the code in Thonny




Step 21 - Source Code for thonny (insert api key and URL from previous step)

import network
import urequests as requests
from machine import Pin
from dht import DHT22
from time import sleep
#Replace the values below with the correct WIFI SSID and Password
wifi_ssid = "WIFI NAME"
wifi_password = "WIFI PASS"

#This is the webhook URL with API Key from IFTTT

webhook_url = "https://maker.ifttt.com/trigger/esp32/with/key/<insert api key here>"


sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)

if sta_if.isconnected() == False:
    sta_if.connect(wifi_ssid, wifi_password)

while sta_if.isconnected() == False:
    #sta_if = network.WLAN(network.STA_IF)
    #sta_if.active(True)
    #sta_if.connect(wifi_ssid, wifi_password)
    sleep(1)
    print(".", end = "")

dht22 = DHT22(Pin(15))

while True:
    dht22.measure()
    temperature = dht22.temperature()
    humidity = dht22.humidity()
    temp = temperature * 9/5 + 32
    url = webhook_url + "?value1=" +  str(temp) + " F" + "&value2=" + str(humidity) + "%"
    try:
        r = requests.get(url)
        print(r.text)
    except Exception as e:
        print(e, "error")
    sleep(30)




Step 22 - View output in spreadsheet

Go to whichever path you set the spreadsheet to in your drive




Comments

Draft