Skip to content
forked from Init-io/FireEsp

This library provides functionality for Firebase Authentication, Realtime Database, and Firestore operations using ESP8266/ESP32 boards. It includes methods for user authentication (sign up, sign in, reset password), database operations (put, update, get, remove), and more.

License

Notifications You must be signed in to change notification settings

ulver2812/FireEsp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


FireEsp - A C++ Firebase Library for Arduino

FireEsp is a lightweight C++ library that simplifies the integration of Firebase services into your Arduino projects. It provides classes to interact with Firebase Authentication, Realtime Database, and Server Configuration. This library is designed for ease of use and aims to make Firebase integration seamless for IoT and embedded projects using Arduino-compatible boards.

Features

  • Firebase Authentication: Sign up, sign in, reset passwords, verify email addresses, and delete users.
  • Firebase Realtime Database: Perform basic CRUD operations (create, read, update, delete) on Firebase's Realtime Database.
  • Server Configuration: Set and manage Firebase project details such as API key, auth domain, and database URL.
  • HTTP Requests: Send HTTP requests to Firebase's REST API to perform authentication and database operations.
  • Debugging Support: Easily switch between production and debugging modes with a configurable debug level, ensuring secure and efficient logging.

Requirements

  • Arduino IDE: To compile and upload code to your Arduino or compatible board.
  • Firebase Project: You need a Firebase project with Authentication and Realtime Database enabled.
  • Arduino-Compatible Board: This library is designed for use with any board that supports the Arduino IDE (e.g., ESP8266, ESP32).

Installation

Step 1: Download or Clone the Repository

You can download or clone the FireESP library to your local machine:

git clone https://github.com/Init-io/FireEsp.git

Step 2: Add the Library to Arduino IDE

  1. Open the Arduino IDE.
  2. Go to Sketch > Include Library > Add .ZIP Library....
  3. Select the FireESP folder you just downloaded or cloned.

Step 3: Include the Library in Your Sketch

In your Arduino sketch, include the necessary headers:

#include <FireEsp.h>

Usage

Firebase Configuration

Before using the library, you need to set up the Firebase server configuration with your project details. Replace the placeholders with your actual Firebase API key, authentication domain, and database URL.

FbServer server("YOUR_API_KEY", "YOUR_AUTH_DOMAIN", "YOUR_DATABASE_URL");
server.initialize();

Firebase Authentication

Sign Up

FbAuthentication auth(server);
bool success = auth.signUp("[email protected]", "password123");

Sign In

bool success = auth.signIn("[email protected]", "password123");

Reset Password

bool success = auth.resetPassword("[email protected]");

Verify Email

bool success = auth.verifyEmail(auth.getIdToken());

Delete User

bool success = auth.deleteUser(auth.getIdToken());

Firebase Database Operations

Put Data (String)

FbDatabase database(server);
bool success = database.put("/path/to/data", "key", "value", auth.getIdToken());

Put Data (Integer)

bool success = database.put("/path/to/data", "key", 123, auth.getIdToken());

Update Data (String)

bool success = database.update("/path/to/data", "key", "new_value", auth.getIdToken());

Get Data

String value = database.get("/path/to/data", auth.getIdToken());

Remove Data

bool success = database.remove("/path/to/data", auth.getIdToken());

Debugging Support

The library now supports flexible debugging configurations. By defining the DEBUG constant, you can easily switch between debugging and production modes, ensuring sensitive data is not printed in production.

Set Debug Level:

To enable debugging for Firebase server interactions, simply define the DEBUG constant before including the library:

#define DEBUG 1  // Set to 0 for production, 1 for debug
#include <FireEsp.h>
  • Level 0 (Production): No debugging output will be printed to the Serial Monitor.
  • Level 1 (Debugging): Prints detailed information about HTTP requests, responses, and errors for easier troubleshooting.

Example with Debugging:

#define DEBUG 1
#include <FireEsp.h>

FbServer server("YOUR_API_KEY", "YOUR_AUTH_DOMAIN", "YOUR_DATABASE_URL");
FbAuthentication auth(server);

void setup() {
  Serial.begin(115200);

  server.initialize();
  
  if (auth.signUp("[email protected]", "password123")) {
    Serial.println("User signed up!");
  }
  
  if (auth.signIn("[email protected]", "password123")) {
    Serial.println("User signed in!");
  }
}

void loop() {
  // Your code here
}

In debugging mode, you'll see detailed logs that include request headers, responses, and any errors encountered during sign-in, sign-up, or other operations.

Example

Here's an example Arduino sketch that demonstrates how to use the FireESP library:

#include <FireEsp.h>

FbServer server("YOUR_API_KEY", "YOUR_AUTH_DOMAIN", "YOUR_DATABASE_URL");
FbAuthentication auth(server);
FbDatabase database(server);

void setup() {
  Serial.begin(115200);

  server.initialize();
  
  if (auth.signUp("[email protected]", "password123")) {
    Serial.println("User signed up!");
  }
  
  if (auth.signIn("[email protected]", "password123")) {
    Serial.println("User signed in!");
  }

  database.put("/users/user1", "name", "John Doe", auth.getIdToken());
}

void loop() {
  // Your code here
}

Known Issues

  • Delayed Responses: Some users have reported that authentication requests may fail initially but work after retrying. This is due to delays in receiving responses from Firebase. A workaround is to introduce a delay between retries or adjust the HTTP client connection timeout.
  • WiFi Stability: Ensure stable WiFi connectivity, as network issues can affect communication with Firebase services.

License

This library is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please fork the repository, create a new branch, and submit a pull request with your changes.

Guidelines

  • Follow the coding style of the existing codebase.
  • Ensure that your changes do not break existing functionality.
  • Write tests if applicable and ensure they pass.

Acknowledgments

  • This library is built using the Arduino framework and Firebase's REST API.
  • Thanks to the Firebase team for providing excellent services that make it easy to integrate authentication and databases into projects.

Contact

For any issues or suggestions, please open an issue on the GitHub repository, or contact me directly at [[email protected]].


About

This library provides functionality for Firebase Authentication, Realtime Database, and Firestore operations using ESP8266/ESP32 boards. It includes methods for user authentication (sign up, sign in, reset password), database operations (put, update, get, remove), and more.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 99.3%
  • C 0.7%