#include <WiFi.h>
#include "ThingSpeak.h"
#include "DHT.h"
const char* WIFI_NAME = "Wokwi-GUEST";
const char* WIFI_PASSWORD = "";
const int myChannelNumber = 2500275;
const char* myApiKey = "C54LMKLCB3IXDMT6";
const char* server = "api.thingspeak.com";
DHT dht(27, DHT22);
WiFiClient client;
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED){
delay(1000);
Serial.println("Wifi not connected");
}
Serial.println("Wifi connected ! Data Sent");
Serial.println("Local IP: " + String(WiFi.localIP()));
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
ThingSpeak.setField(1,h);
ThingSpeak.setField(2,t);
ThingSpeak.writeFields(myChannelNumber,myApiKey);
Serial.print("Temperature : \t");
Serial.println(t);
Serial.print("Humidity : \t");
Serial.println(h);
delay(3000);
}