The use of the ESP8266 in the world of IoT

User avatar
By tetratora
#95832 Hello, im new with this kind of stuff so i dont understand whats going on.

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.
Image
and here's the code
Code: Select all#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 :D
User avatar
By AcmeUK
#95860 It looks as though you are not passing enough parameters for the firebase connect. Have a look at THIS

You will see that DATABASE_URL and API_KEY are passed as a "parameter pair" and that USER_EMAIL and USER_PASSWORD need to be passed as a second "parameter pair".

Note also that the author identifies this problem:-
due to reasons I do not know, firebase library I downloaded from Library manager was not working so I had to download it from GitHub, https://github.com/adesolasamuel/Firebase-ESP8266