COVID19 and other Projects with program: ESP32 Dual Core Programming with Arduino, Keen Wi-Fi Video Doorbell, MicroPython on ESP32, ESP32 Based Webserver, Face Recognition, Fitness Band etc.., by K Anbazhagan

COVID19 and other Projects with program: ESP32 Dual Core Programming with Arduino, Keen Wi-Fi Video Doorbell, MicroPython on ESP32, ESP32 Based Webserver, Face Recognition, Fitness Band etc.., by K Anbazhagan

Author:K, Anbazhagan [K, Anbazhagan]
Language: eng
Format: epub
Published: 2020-05-27T16:00:00+00:00


Code

#include <WiFi.h>

#include <Wire.h>

#include "DHT.h"

// Uncomment one of the lines below for whatever DHT sensor type you're using!

#define DHTTYPE DHT11 // DHT 11

//DHT Sensor;

uint8_t DHTPin = D2;

DHT dht(DHTPin, DHTTYPE);

float Temperature;

float Humidity;

void send_event(const char *event);

const char* ssid = "Wi-Fi Name";

const char* password = "Password";

const char *host = "maker.ifttt.com";

const char *privateKey = "Private Key"; Enter the privte key that you copied from IFTTT Webhooks

WiFiServer server(80);

String header;

void setup() {

Serial.begin(115200);

pinMode(DHTPin, INPUT);

dht.begin();

Serial.print("Connecting to Wifi Network");

Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

}

Serial.println("");

Serial.println("Successfully connected to WiFi.");

Serial.println("IP address of ESP32 is : ");

Serial.println(WiFi.localIP());

server.begin();

Serial.println("Server started");

}

void loop()

{

Temperature = dht.readTemperature();

Humidity = dht.readHumidity();

WiFiClient client = server.available();

if (client)

{

Serial.println("Web Client connected ");

String request = client.readStringUntil('\r');

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println("Connection: close"); // the connection will be closed after completion of the response

client.println("Refresh: 10"); // update the page after 10 sec

client.println();

client.println("<!DOCTYPE HTML>");

client.println("<html>");

client.println("<style>html { font-family: Cairo; display: block; margin: 0px auto; text-align: center;color: #333333; background-color: ##f3ffee;}");

client.println("body{margin-top: 50px;}");

client.println("h1 {margin: 50px auto 30px; font-size: 50px; text-align: center;}");

client.println(".side_adjust{display: inline-block;vertical-align: middle;position: relative;}");

client.println(".text1{font-weight: 180; padding-left: 15px; font-size: 50px; width: 170px; text-align: left; color: #3498db;}");

client.println(".data1{font-weight: 180; padding-left: 70px; font-size: 50px;color: #3498db;}");

client.println(".text2{font-weight: 180;padding-left: 15px; font-size: 50px; width: 170px; text-align: left; color: #ff6600;}");

client.println(".data2{font-weight: 180; padding-left: 120px; font-size: 50px;color: #ff6600;}");

client.println(".data{padding: 10px;}");

client.println("</style>");

client.println("</head>");

client.println("<body>");

client.println("<div id=\"webpage\">");

client.println("<h1>ESP32 Interfacing with DHT11</h1>");

client.println("<div class=\"data\">");

client.println("<div class=\"side_adjust text1\">Humidity:</div>");

client.println("<div class=\"side_adjust data1\">");

client.print(Humidity);

client.println("<div class=\"side_adjust text1\">%</div>");

client.println("</div>");

client.println("<div class=\"data\">");

client.println("<div class=\"side_adjust text2\">Temperature:</div>");

client.println("<div class=\"side_adjust data2\">");

client.print(Temperature);

client.println("<div class=\"side_adjust text2\">*C</div>");

client.println("</div>");

client.println("</div>");

client.println("</body>");

client.println("</html>");

delay(4000);

if ( Temperature >= 20) {

send_event("temp_event");

}

}

}

void send_event(const char *event)

{

Serial.print("Connecting to ");

Serial.println(host);

// Use WiFiClient class to create TCP connections

WiFiClient client;

const int httpPort = 80;

if (!client.connect(host, httpPort)) {

Serial.println("Connection failed");

return;

}

// We now create a URI for the request

String url = "/trigger/";

url += event;

url += "/with/key/";

url += privateKey;

Serial.print("Requesting URL: ");

Serial.println(url);

// This will send the request to the server

client.print(String("GET ") + url + " HTTP/1.1\r\n" +

"Host: " + host + "\r\n" +

"Connection: close\r\n\r\n");

while(client.connected())

{

if(client.available())

{

String line = client.readStringUntil('\r');

Serial.print(line);

} else {

// No data yet, wait a bit

delay(50);

};

}

Serial.println();

Serial.println("closing connection");

client.stop();

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(56733)
What's Done in Darkness by Kayla Perrin(26765)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(20338)
De Souza H. Master the Age of Artificial Intelligences. The Basic Guide...2024 by Unknown(20160)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(20152)
The Fifty Shades Trilogy & Grey by E L James(19231)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19218)
Shot Through the Heart by Mercy Celeste(19078)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17258)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(17197)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(17038)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16960)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16589)
The Subtle Art of Not Giving a F*ck by Mark Manson(14548)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14281)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13928)
Scorched Earth by Nick Kyme(12917)
Drei Generationen auf dem Jakobsweg by Stein Pia(11115)
Suna by Ziefle Pia(11038)
Scythe by Neal Shusterman(10505)