#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "ECE_STAFF_ROOM";
const char* password = "specnet@23";
String server = "http://api.thingspeak.com/update";
String apiKey = "65AZ09LAJJKJQ0D3";
WiFiClient client;
#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN,DHTTYPE);
float h;
float t;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting.");
while(WiFi.status() != WL_CONNECTED){
delay(1000);
Serial.print(".");
}
Serial.println(": Connected to WiFi!");
dht.begin();
}
void loop() {
h = dht.readHumidity();
t = dht.readTemperature();
HTTPClient http;
// Place your 10-digit roll number in the string below
String url = server + "?api_key=" + apiKey + "&field1=22261A0400" +
"&field2="+String(h) + "&field3="+ String(t);
http.begin(client,url);
int httpCode = http.GET();
if(httpCode > 0){
Serial.println("Data Sent Successfully");
}else{
Serial.println("Error sending data");
}
http.end();
delay(5000);
}
No comments:
Post a Comment