/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
// your code goes here
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCX0KfQ==
I2luY2x1ZGUgJmx0O0VTUDgyNjZXaUZpLmgmZ3Q7CiNpbmNsdWRlICZsdDtESFQuaCZndDsKCi8vIFdpRmkgJmFtcDsgVGhpbmdTcGVhayBDcmVkZW50aWFscwpjb25zdCBjaGFyKiBzc2lkID0gJnF1b3Q7WW91cl9XaUZpX05hbWUmcXVvdDs7ICAKY29uc3QgY2hhciogcGFzc3dvcmQgPSAmcXVvdDtZb3VyX1dpRmlfUGFzc3dvcmQmcXVvdDs7CmNvbnN0IGNoYXIqIHNlcnZlciA9ICZxdW90O2FwaS50aGluZ3NwZWFrLmNvbSZxdW90OzsKU3RyaW5nIGFwaUtleSA9ICZxdW90O1lvdXJfVGhpbmdTcGVha19BUElfS2V5JnF1b3Q7OwoKLy8gREhUMTEgU2Vuc29yIFNldHRpbmdzCiNkZWZpbmUgREhUUElOIEQ0ICAvLyBESFQxMSBjb25uZWN0ZWQgdG8gR1BJTzIKI2RlZmluZSBESFRUWVBFIERIVDExCkRIVCBkaHQoREhUUElOLCBESFRUWVBFKTsKCldpRmlDbGllbnQgY2xpZ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hbXA7ZmllbGQxPSZxdW90OyArIFN0cmluZyh0ZW1wZXJhdHVyZSkgKwogICAgICAgICAgICAgICAgICZxdW90OyZhbXA7ZmllbGQyPSZxdW90OyArIFN0cmluZyhodW1pZGl0eSk7CiAgICAKICAgIGNsaWVudC5wcmludChTdHJpbmcoJnF1b3Q7R0VUICZxdW90OykgKyB1cmwgKyAmcXVvdDsgSFRUUC8xLjFcclxuJnF1b3Q7ICsKICAgICAgICAgICAgICAgICAmcXVvdDtIb3N0OiAmcXVvdDsgKyBzZXJ2ZXIgKyAmcXVvdDtcclxuJnF1b3Q7ICsKICAgICAgICAgICAgICAgICAmcXVvdDtDb25uZWN0aW9uOiBjbG9zZVxyXG5cclxuJnF1b3Q7KTsKICAgIGNsaWVudC5zdG9wKCk7CiAgfQogIGRlbGF5KDE1MDAwKTsgIC8vIFNlbmQgZGF0YSBldmVyeSAxNSBzZWNvbmRzCn0=
#include <ESP8266WiFi.h>
#include <DHT.h>
// WiFi & ThingSpeak Credentials
const char* ssid = "Your_WiFi_Name";
const char* password = "Your_WiFi_Password";
const char* server = "api.thingspeak.com";
String apiKey = "Your_ThingSpeak_API_Key";
// DHT11 Sensor Settings
#define DHTPIN D4 // DHT11 connected to GPIO2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
WiFiClient client;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nConnected to WiFi");
dht.begin();
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print("°C | Humidity: ");
Serial.print(humidity);
Serial.println("%");
if (client.connect(server, 80)) {
String url = "/update?api_key=" + apiKey +
"&field1=" + String(temperature) +
"&field2=" + String(humidity);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + server + "\r\n" +
"Connection: close\r\n\r\n");
client.stop();
}
delay(15000); // Send data every 15 seconds
}