so i want to make an IOT door lock with esp8266(v3) based on Firebase Database, and controlled with app (its for school project)
when i insert the code and then run it, it kinda works just for the connecting to the WiFi.
and here's the code
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
#define ssid "cyanol"
#define password "alterios"
#define DATABASE_URL "https://doorlockiotalter-default-rtdb.asia-southeast1.firebasedatabase.app/"
#define API_KEY " PJ2tAgUF22gWTKIP7yIoXCSO0EE0RJoX75ECLqmo"
FirebaseData fbdo;
int RELAYPIN_1 = 14;
void setup() {
Serial.begin(115200);
WiFi.begin (ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
Serial.println ("connecting...");
}
Serial.println();
Serial.print("connected to IP:");
Serial.println(WiFi.localIP());
pinMode(RELAYPIN_1, OUTPUT);
Firebase.begin(DATABASE_URL, API_KEY);
}
void loop() {
if (Firebase.get(fbdo, "/Relay"))
{
if (fbdo.dataType() == "string") {
String relay1 = fbdo.stringData();
if (relay1 == "1") {
Firebase.setString(fbdo, "/Condition", "UNLOCKED");
digitalWrite(RELAYPIN_1, HIGH);
Serial.println("relay activated");
delay(5500);
Firebase.setString(fbdo, "/Condition", "LOCKED");
Firebase.setString(fbdo, "/Relay", "0");
digitalWrite(RELAYPIN_1, LOW);
Serial.println("relay deactivated");
}
else if (relay1 == "0") {
Firebase.setString(fbdo, "/Condition", "LOCKED");
digitalWrite(RELAYPIN_1, LOW);
Serial.println("relay deactivated");
}
}
}
}
P.S Sorry for bad english