Hello Everyone.
I'm trying to build a Home automation app to control my nodemcu 8266 and read DHT22 Sensor.
i succeded to control my relays but i searched alot to learn how to read the sensor data without using firebase or thingspeak and did not find applicable ways instead of using the firebase or thingspeak.
is that applicable to read the DHT data without internet?
thats my code for nodemcu
{
//Viral Science www.youtube.com/c/viralscience www.viralsciencecreativity.com
//Web Server App Control Home Automation
#include <ESP8266WiFi.h>
WiFiClient client;
WiFiServer server(80);
/* WIFI settings /
const char ssid = ""; //WIFI SSID
const char password = "****"; //WIFI PASSWORD
/* data received from application */
String data ="";
/* define L298N or L293D motor control pins */
int Relay1 = 16; //D6
int Relay2 = 5; //D0
int Relay3 = 4; //D2
int Relay4 = 0; //D1
int Relay5 = 2; //D6
int Relay6 = 14; //D0
int Relay7 = 12; //D2
int Relay8 = 13; //D1
void setup()
{
/* initialize motor control pins as output /
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Relay5, OUTPUT);
pinMode(Relay6, OUTPUT);
pinMode(Relay7, OUTPUT);
pinMode(Relay8, OUTPUT);
digitalWrite(Relay1,LOW);
digitalWrite(Relay2,LOW);
digitalWrite(Relay3,LOW);
digitalWrite(Relay4,LOW);
digitalWrite(Relay5,LOW);
digitalWrite(Relay6,LOW);
digitalWrite(Relay7,LOW);
digitalWrite(Relay8,LOW);
/ start server communication */
Serial.begin(115200);
connectWiFi();
server.begin();
}
void loop()
{
/* If the server available, run the "checkClient" function /
client = server.available();
if (!client) return;
data = checkClient ();
Serial.print(data);
/*********************** Run function according to incoming data from application *************************/
if (data == "Relay1ON")
{
digitalWrite(Relay1,HIGH);
}
else if (data == "Relay1OFF")
{
digitalWrite(Relay1,LOW);
}
else if (data == "Relay2ON")
{
digitalWrite(Relay2,HIGH);
}
else if (data == "Relay2OFF")
{
digitalWrite(Relay2,LOW);
}
else if (data == "Relay3ON")
{
digitalWrite(Relay3,HIGH);
}
else if (data == "Relay3OFF")
{
digitalWrite(Relay3,LOW);
}
else if (data == "Relay4ON")
{
digitalWrite(Relay4,HIGH);
}
else if (data == "Relay4OFF")
{
digitalWrite(Relay4,LOW);
}
else if (data == "Relay5ON")
{
digitalWrite(Relay5,HIGH);
}
else if (data == "Relay5OFF")
{
digitalWrite(Relay5,LOW);
}
else if (data == "Relay6ON")
{
digitalWrite(Relay6,HIGH);
}
else if (data == "Relay6OFF")
{
digitalWrite(Relay6,LOW);
}
else if (data == "Relay7ON")
{
digitalWrite(Relay7,HIGH);
}
else if (data == "Relay7OFF")
{
digitalWrite(Relay7,LOW);
}
else if (data == "Relay8ON")
{
digitalWrite(Relay8,HIGH);
}
else if (data == "Relay8OFF")
{
digitalWrite(Relay8,LOW);
}
}
void connectWiFi()
{
Serial.println("Connecting to WIFI");
WiFi.begin(ssid, password);
while ((!(WiFi.status() == WL_CONNECTED)))
{
delay(300);
Serial.print("..");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("NodeMCU Local IP is : ");
Serial.print((WiFi.localIP()));
}
/********************************** RECEIVE DATA FROM the APP ******************************************/
String checkClient (void)
{
while(!client.available()) delay(1);
String request = client.readStringUntil('\r');
request.remove(0, 5);
request.remove(request.length()-9,9);
return request;
}