Skip to content

Firebase Flux Asset

The Firebase Asset is a flux asset provided by Coreflux that enables seamless communication between Firebase Realtime Database and your MQTT broker. This guide will provide a comprehensive overview of the Firebase Asset, including its features, benefits, installation, configuration, and usage.

Introduction

What is Firebase?

Firebase is a platform developed by Google for creating mobile and web applications. It provides various services like Realtime Database, Authentication, Cloud Messaging, and many more.

Features and Benefits

  • Seamless Communication: Enables seamless communication between Firebase Realtime Database and your MQTT broker.
  • Data Synchronization: Synchronizes data between Firebase and MQTT topics.
  • Real-time Monitoring: Allows real-time monitoring of Firebase databases.
  • Secure Connection: Supports secure connections using Transport Layer Security (TLS).

Prerequisites

Before you install and configure the Firebase Asset, make sure you have the following prerequisites:

  • Basic understanding of the MQTT protocol.
  • Coreflux account.
  • Coreflux v1.2.
  • Coreflux MQTT Broker asset.
  • MQTT Client (such as MQTT Explorer).

Installation

Method 1: GUI

// Instructions for GUI installation

Method 2: Command-line

// Instructions for command-line installation

Configuration

To configure the Firebase Asset, you need to run only one command:

-assetConfigSave <guid> <configuration>
  • <guid>: A unique asset id that is generated during the installation. To get the asset guid, consult the $SYS/Coreflux/Assets topic.
  • <configuration>: The asset settings.

Parameters

MQTT Parameters

  • Port: MQTT broker port.
  • Address: MQTT broker IP Address.
  • IsAnonymous: Connect to MQTT broker as an anonymous client.
  • Username: MQTT client username.
  • Password: MQTT client password.
  • EnableTLS: Enables a secure connection between broker and client.
  • EnableDebugTopic: Enables a special topic that gives feedback on the connection state.
  • DebugTopic: Define the debug topic.

Firebase Parameters

  • User: Email of the user with access to the database. Found in the Authentication section.
  • Password: Password of the user with access to the database.
  • DatabaseURL: Found in the Realtime Database section of the Firebase console.
  • APIKey: An API key is a unique string that's used to route requests to your Firebase project.

Tags

  • Name: Unique Tag identifier.
  • WriteDirection: Chose the origin and destination of data. The options are: 0 - ToAll, 1 - ToMQTT, and 2 - ToFirebase.
  • MQTTTopic: Unique topic that will connect with the database node specified in "FirebaseChildNode" parameter.
  • MQTTQoS: Quality of service for the topic. Options are: AtMostOnce, AtLeastOnce, and ExactlyOnce.
  • MQTTRetain: Define to retain the message or not. Options are: true or false.
  • FirebaseChildNode: Unique database node that will connect with the topic specified in the "MQTTTopic".
  • WriteMode: Set the method for setting data on the database node and/or on the topic. Options are: 0 - IsPostJSONWithAutoKey, 1 - IsPostValueWithAutoKey, 2 - IsPutJSon, 3 - IsPutValue, 4 - IsGetJson, 5 - IsGetValue.
WriteMode - aditional details
  • IsPostJSONWithAutoKey: This option will generate a new child node in the Firebase Realtime Database (RTDB) with a new key, and the content will be in JSON format. This is useful when you want to add a new record without overwriting the existing data. Firebase automatically generates a unique key for each new child. For example, if you are posting the following JSON data: { "name": "John", "age": 30 }, Firebase will create a new child node with a unique key, and the child node's value will be the JSON data.

  • IsPostValueWithAutoKey: This option is similar to IsPostJSONWithAutoKey, but instead of posting JSON data, it posts a direct value. For example, if you are posting a value 30, Firebase will create a new child node with a unique key, and the child node's value will be 30.

  • IsPutJSON: This option will overwrite the specified child node in the RTDB with new JSON data. For example, if you specify a child node users/user1 and the new JSON data is { "name": "John", "age": 30 }, Firebase will overwrite the users/user1 child node with the new JSON data.

  • IsPutValue: This option is similar to IsPutJSON, but instead of posting JSON data, it posts a direct value. For example, if you specify a child node users/user1 and the new value is 30, Firebase will overwrite the users/user1 child node with the new value 30.

  • IsGetValue: This option will get the value of the specified child node from the RTDB and publish it to a specified MQTT topic. For example, if you specify a child node users/user1, the asset will get the value of users/user1 from the RTDB and publish it to the specified MQTT topic.

  • IsGetJSON: This option is similar to IsGetValue, but the value of the specified child node will be published to the specified MQTT topic in JSON format. For example, if you specify a child node users/user1, the asset will get the value of users/user1 from the RTDB and publish it to the specified MQTT topic in JSON format.

Example Configuration

{
  "MQTTParameters": {
    "Port": 1883,
    "Address": "127.0.0.1",
    "IsAnonymous": true,
    "Username": "",
    "Password": "",
    "EnableTLS": true,
    "EnableDebugTopic": true,
    "DebugTopic": "test/debugtopic"
  },
  "FirebaseParameters": {
    "User": "test@email.com",
    "Password": "benfica01##",
    "DatabaseURL": "https://test-project-d1fba-default-rtdb.europe-west1.firebasedatabase.app/",
    "APIKey": "AIz1gyCff1uR_6DZgWKQayTtjCtiaq0OI2t2c11"
  },
  "Tags": [
    {
      "Name": "SomeName",
      "WriteDirection": 2,
      "MQTTTopic": "source/topic/example",
      "MQTTQoS": 0,
      "MQTTRetain": false,
      "FirebaseChildNode": "somenode/example",
      "WriteMode": 0
    }
  ]
}

Running the Asset

To run the Firebase Asset, publish the “-R” (run) command with the asset guid to $SYS/Coreflux/Cloud/Command topic:

-R <guid>

And the asset is running!

Usage

Using the MQTT client, it is now possible to visualize the data replicated from Firebase to the MQTT broker and vice versa.

Next Steps

Now that the asset is configured, and data is flowing, you can store the data in the cloud using other Coreflux assets, or create a trigger when a certain value is reached using the Flux Documentation.

For more information and help, join our Discord community.

FAQ

General Questions

What is the Firebase Asset?

The Firebase Asset is a flux asset provided by Coreflux that enables seamless communication between Firebase Realtime Database and your MQTT broker. It allows you to synchronize data between Firebase and MQTT topics, monitor them in real-time, and easily integrate them with your IIoT projects.

What are the prerequisites for using the Firebase Asset?

Before you install and configure the Firebase Asset, make sure you have the following prerequisites: - Basic understanding of the MQTT protocol. - Coreflux account. - Coreflux v1.2. - Coreflux MQTT Broker asset. - MQTT Client (such as MQTT Explorer).

How do I install the Firebase Asset?

The Firebase Asset can be installed via GUI or command-line. Detailed installation instructions can be found in the Installation section of the Firebase Asset documentation.

Configuration Questions

How do I configure the Firebase Asset?

To configure the Firebase Asset, you need to run only one command:

-assetConfigSave <guid> <configuration>
The <guid> is a unique asset id that is generated during the installation. To get the asset guid, consult the $SYS/Coreflux/Assets topic. The <configuration> parameter is where you are able to set the asset settings. Detailed configuration instructions and an example configuration can be found in the Configuration section of the Firebase Asset documentation.

What are the parameters in the configuration?

The configuration consists of three main sections: MQTTParameters, FirebaseParameters, and Tags. - MQTTParameters are used to configure the connection between the client and the MQTT broker. - FirebaseParameters are used to configure the connection between the MQTT Broker and Firebase Realtime Database. - Tags is an array of "Tag", each containing parameters for a unique database node and MQTT topic connection.