dht sensor
dht sensor
h>
#include <ESP8266HTTPClient.h>
#include "DHT.h"
#define DHTPIN D3
#define DHTTYPE DHT11
// Replace with your network credentials
const char* ssid = "IITH-Guest-PWD-IITH@2024";
const char* password = "IITH@2024";
int ir= D1;
int led = D0;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
Serial.println(F("DHTxx test!"));
dht.begin();
pinMode(ir,INPUT);
pinMode(led, OUTPUT);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
delay(2000);
int value = digitalRead(ir);
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("temp and humid--");
Serial.print(h);
Serial.print("---");
Serial.println(t);
if (WiFi.status() == WL_CONNECTED) {
// Create a WiFi client object
WiFiClient wifiClient;
// Make HTTP GET request
HTTPClient http;
const char* baseUrl ="http://172.16.66.40:3000/setTempHumidity?temp=";
String url = String(baseUrl) + t ;
url = url + "&humidity="+ h;
http.begin(wifiClient, url);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("HTTP response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println("Response payload:");
Serial.println(payload);
if(payload == "0"){
digitalWrite(led,HIGH);
}
if(payload == "1"){
digitalWrite(led,LOW);
}
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
Serial.print("Error message: ");
Serial.println(http.errorToString(httpResponseCode).c_str());
}
http.end(); // Close HTTP connection
}
delay(5000);
}