MQTT Firebase, a Coreflux Flux Asset

Paulo Mota
Coreflux Blog
Published in
7 min readAug 8, 2022

1. The Purpose of this Flux Asset

Coreflux’s MQTT Firebase is an asset centered around creating a bridge between your local (or not local) MQTT data with a cloud-based Firebase database. This effectively enables the start of a cloud pipeline, that you can afterwards supplement with a series of automated functionality.

2. Firebase

As their banner above well explains, Firebase is Google’s app development platform, that provides a series of services to store, manage and process your data.

3. Preparation

The first step to use Firebase is to create your account there.

3.1. Create a new Firebase project

After creating an account and logging-in, you will be greeted by a list of your current open projects (which of course will be empty if you’re new to Firebase). The first step to kick-off the process is pressing the “Add project” button.

You will be prompted to input a name for the new project. After doing so, Firebase will ask you to choose if you wish to enable Google Analytics… please read the respective features and configuration options if you wish to do so (for a quick-start, you can choose not to enable it, it won’t be necessary at this point).

3.2. Enable Authentication Methods

Now that your new project is initiated, you will now have a new screen with a series of functionalities to explore.

To move our ongoing process forward, press the first element on the list, named “Authentication”:

This functionality allows you to define how new users may sign-up and sign-in to this project. This is important, because this is the element that defines who can access your database, and what specific data they can access. Once you press the “Get Started” button, a series of options will be provided:

For now, we are going with the most obvious (but not least powerful) option, which is the Email/Password option. Choose the respective option, to open the following screen where you can enable the toggle for this method.

Save your changes. You now have a proper method for account creation enabled.

NOTE: While you still don’t have your code prepared to allow your users to add themselves, you can go to the “Users” tab to manage/add/delete users manually.

This process has now unlocked behind the scenes the ability to consult your Web API Key, which is what we’re going to do next.

3.3. Get Web API Key

With Authentication properly provided, you can now navigate to the details page. To the right of the Project Overview button, on the top left, you’ll find a gearbox icon that expands into a set of options. Select “Project Settings”.

This will give you access to a screen with a series of details on your project. From these, you’ll now want to copy the “Web API Key” value, and paste it somewhere safe for future reference when we’re installing the Coreflux asset.

3.4. Get Realtime-Database address

Almost done. Now that we have a valid API Key, it is time to setup our Realtime-Database.

On the left panel of the Firebase page, you’ll noticed a set of tabs. Expanding the BUILD one will reveal many new options. You’ll now want to click the one called, you guessed it, “Realtime Database”.

Press “Create Database”. You will be prompted to select from a dropdown menu where you want your data to be stored. The only relevant impact of this choice is that the closest you and/or your clients are to the server, the faster requested/sent data will travel back and forth. In most cases, the difference is negligible, especially considering cloud processing times, but keep this in mind. After you choose, press “Next”.

Finally, but not least importantly, you’ll be asked to choose the starting Security Rules. These rules define what can be done right off the bat. For now, choose “Start in test mode”, which will temporarily allow any user to read and/or write from the RTDB (these settings will be written with a rule to be active only for 30 days, after which they will default to closed… you can change them at any time, though). Press “Enable”, wait a few seconds, and voilá, you now have a fully functional and (for the moment) quite empty database.

Direct your attention to the header, pictured below at the bottom, which contains the full address of your database.

Copy it, like you did with the API Key, paste it on your notes, and let’s move on to Coreflux.

4. Installation

  • Once you press “Install”, you will be presented with the asset configuration window:
  • Configure your MQTT Broker address and port to match the settings you are using (the corresponding broker should be running when your start the Telegram asset).
  • On the Firebase-specific boxes shown below, write or paste the information gathered on the account/project creation process. On the first field, paste the Web API Key you retrieved from the Project Settings page. On the second field, paste the full address retrieved from the Realtime-Database page. And on the third and fourth fields, the username and password of the project’s admin account (which may either be yours or of a specific account you created for that purpose, the only requirement is that it has enough privileges to complete required actions).
  • After installation, the instance window for this asset installation will display the “Standby” status
  • For proper functioning the asset must be configured (see chapter 5).
  • To begin execution of the MQTT Firebase Flux Asset, press the Play button, and if successful, the instance status will change to “Running”.
  • If for some reason the inputted configuration fails to execute (or permission to run is not confirmed by the system), the asset will try to enter a run state but return to a halted state when failing to do so, displaying an error popup (on the GUI Hub) or message (on the command-line Hub). If the asset is running, but you’re not seeing responses on Telegram, see chapter 7 for possible Troubleshooting.

5. Configuring the Tags

  • Before the asset is actually usable, you will need to configure the topics you wish to work with. On Coreflux versions below 1.2.0, this will be done through the asset’s XML file. Navigate to Coreflux’s installation folder, and locate the appropriate asset folder within the “instances” folder.
  • Open it. The XML section to alter is the following (on chapter 5, below, you will find an extensive explanation of how to carry out this configuration properly).
  • Once the asset is properly configured, save the file and return to the Coreflux Hub window.

5.1. Tags: Write Direction (writable)

  • ToAll: Write in both directions, from/to MQTT and Firebase
  • ToMqtt: Write only from from Firebase to MQTT
  • ToFirebase: Write only from MQTT to Firebase

5.2. Tags: Value Type (ValType)

  • isPutValue: This will perform a PUT operation with a raw value (for example an INT or a BOOL), thus writing from the MQTT to Firebase and replacing the content already in the target object with the new input received
  • isPutJSon: This will perform a PUT operation with a JSON structure, thus writing from the MQTT to Firebase and replacing the content already in the target object with the new input received
  • isPostJSONWithAutoKey: This will perform a POST operation with a JSON structure, thus incrementing to what already exists in the target destination, attributing an automatically generated unique key to the new value as an identifier
  • isPostValueWithAutoKey: This will perform a POST operation with a raw value (for example an INT or a BOOL), thus incrementing to what already exists in the target destination, attributing an automatically generated unique key to the new value as an identifier
  • isGetJson: This will perform a GET operation, thus retrieving a JSON structure
  • isGetValue: This will perform a GET operation, thus retrieving a raw value (for example an INT or a BOOL)

5.3. Source/Destination MQTT Topic (mqttTopic)

This is the topic that will be used by the asset either as a source or a destination of MQTT data, depending on if you’re writing or reading from it.

5.4. Source/Destination Firebase Path (FirebaseChildNode)

This is the topic that will be used by the asset either as a source or a destination of Firebase data, depending on if you’re writing or reading from it.

6. Troubleshooting

6.1. Unable to read/write on Firebase’s RTDB

  • Check your Realtime-Database rules. These should allow the specific user to either read or write (according to what is intended), either in general or on specific folders.

--

--

Paulo Mota
Coreflux Blog

Cognition and behaviour in increasingly technological societies