Codes
Codes
#include <ESP8266WiFi.h>
String apiKey = “SMYE22OFDVE3OPXG”; // Enter your Write API key from ThingSpeak
Const char *ssid = “Hawkeyee”; // replace with your wifi ssid and wpa2 key
#define motorPin 4
WiFiClient client;
Void setup()
pinMode(D4,OUTPUT);
Serial.begin(115200);
Delay(10);
Dht.begin();
Serial.println(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, pass);
While (WiFi.status() != WL_CONNECTED)
Delay(500);
Serial.print(“.”);
Serial.println(“”);
Serial.println(“WiFi connected”);
Void loop()
Float h = dht.readHumidity();
Float t = dht.readTemperature();
If (isnan(h) || isnan(t))
Return;
If(t>30){
digitalWrite(D4,HIGH);
delay(10000);
digitalWrite(D4,LOW);
delay(1000);
Else{
//nothing
postStr +=”&field1=”;
postStr += String(t);
postStr +=”&field2=”;
postStr += String(h);
postStr += “\r\n\r\n”;
client.print(“Host: api.thingspeak.com\n”);
client.print(“Connection: close\n”);
client.print(“X-THINGSPEAKAPIKEY: “+apiKey+”\n”);
client.print(“Content-Type: application/x-www-form-urlencoded\n”);
client.print(“Content-Length: “);
client.print(postStr.length());
client.print(“\n\n”);
client.print(postStr);
Serial.print(“Temperature: “);
Serial.print(t);
Serial.print(h);
}
Client.stop();
Serial.println(“Waiting...”);
Delay(1000);