ESP32 DHT22 IFTTT

Auteur avatarSid | Dernière modification 15/01/2023 par Disisid

Pas encore d'image

Send DHT22 temperature and humidity values to a google sheet through ESP32 and Webhooks
Difficulté
Moyen
Durée
1 heure(s)
Catégories
Électronique
Coût
0 USD ($)

Introduction

ESP32 connected to DHT22, to read temperature and humidity

Matériaux

Outils

Étape 1 - Install Thonny or Other Python IDLE




Étape 2 - Setup Circuit

+ 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



Étape 3 - Source Code for thonny

import network
import urequests as requests
from machine import Pin
from dht import DHT22
from time import sleep
wifi_ssid = "WIFI NAME"
wifi_password = "WIFI PASS"


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)




Commentaires

Draft