Firebase, 0G (Sigfox) & IoT

Here is everything you need, to bring IoT data to your App running on Firebase.

Ngesa Marvin 10x
IoT/5G Extreme Ideas Lab
6 min readApr 1, 2020

--

Prerequisites

This tutorial assumes you already:

Sigfox & 0G

SIGFOX is a leading provider of dedicated connectivity for the Internet of Things. They provide a two-way communication service through a global radio network.

It is the first global 0G network — a low-power wide area network (LPWAN), which interconnects low-bandwidth, battery powered devices with low bit rates over long ranges.

Liquid Telecom, a leading communications and solutions provider in 13 African Countries, operates the network in Kenya.

Warefab

Warefab Konnect is the first Kenyan designed Sigfox developer kit that offers a practical and cost effective solution for makers seeking to add SigFox connectivity to their projects with minimal previous experience in networking.

The kit has multiple sensors onboard including a GPS receiver and an extension port that allows users to extend the capability of the kit e.g adding more sensors or actuators.

Firebase

So what is Firebase?

Firebase is Google’s client side application development platform, with a mission to help app developers of all sizes (large or small) succeed with their products.

It accomplishes this by taking common problems that occur during a product’s lifecycle, and making them easier to solve, be it by providing more information about your products, or providing tools to handle complex problems like security or network connectivity when storing data.

To get started, go to the Firebase Console. You should see something like the screenshot above.

Firebase Functions

These are serverless event driven code. They enable you to write your own backend (server side code) and specify when they should get executed. While running your backend code, you don't have to manage the servers or worry about security updates.

These code are event driven, meaning that they will be running upon certain events.

Event Sources

Creating a REST Endpoint with Cloud Functions

To manage, view, and deploy Firebase projects we will install Firebase CLI .

Install Firebase CLI by running this command npm install -g firebase-tools

After that, runfirebase login to sign into Firebase using Google account. You will also be able to connect your local machine to Firebase and access your Firebase projects.

Then you will get the following response:

Now we are going to create a project. To generate a firebase cloud function project, run firebase init function.

It will generate the project, after which you should see below on the console.

Go back to firebase console and create your firebase project by following the three steps. You may disable Google Analytics for now

On the terminal select “Use existing project” and install all the dependencies. The tool gives you an option to install dependencies with npm. It is safe to decline if you want to manage dependencies in another way.

I am going use Javascript to write Cloud Functions and ESLint to catch probable bugs.

Once you have installed dependencies you should see several changes in you files. Run firebase init function.

Go to index js file and you will find code example of cloud functions.

We want our firebase Cloud functions handling incoming http post req for Warefab Konnect devkit and log the data on the console.

Parse the Sigfox Payload

SIGFOX does not understand or transform the payload being transmitted through the network. Manufacturers pack messages, payload in different ways/data formats and it is only them who knows how it is structured. Here is guide on the warfab v1 devkit payload structure.

Write a module to decode the received data and import it as decoded.

Firebase Realtime Database

To save the decoded data to Firebase Database, we need to require firebase admin tools and initialize it.

We can then save the decoded messagesunder the reference messages

Deploy the function

To deploy to the Firebase project, run the following command from your project directory firebase deploy.

Integrating Sigfox IoT network with Firebase

Sigfox Cloud is the central hub where messages and information from your devices are stored. You must integrate Sigfox Cloud in order to retrieve and use the data from your devices.

Architecture diagram

Two methods are available: The Callback API and the REST API. Each serves a purpose for communicating between Sigfox Cloud and your server. In this post, we are going to use Callbacks to retrieve devices’ messages and send them to Firebase Real Time Database

Configure sigfox backend to trigger Firebase HTTP Cloud functions

The configuration of callbacks is done in the Sigfox backend device type page.
The callbacks are triggered when a new device message is received or when a device communication loss has been detected.

Ensure that you can see messages sent by your device in your Sigfox backend, in Device > Messages.

Sigfox messages example

If you can see messages sent by your device, you can proceed to the next step.

Click on “callbacks” and then “New”

Choose the “custom callback”

Change the “Data Type ” and “Channel” as indicated then add your cloud Function URL endpoint at the “URL Pattern”.

Change the Content type to json and ensure you have data in the body as shown.

Testing the integration

Sending data from a Warefab Sigfox device

The integration should now be configured in both Firebase Cloud Functions and the Sigfox backend.

Firebase Realtime Database

App

If you found this helpful, click the 👏. Follow this publication for more tutorials on The Internet of Things.

NB-If you have any IoT concepts you’d like explained in a post, any question, comment, or suggestions, please let me know. I’ll get back to as many as I can.

--

--

Ngesa Marvin 10x
IoT/5G Extreme Ideas Lab

Electronic Engineer. Engineering Manager. AI Innovator, Intel. Grew @LiquidInTech, Deep Learning Abantu. Wabi -Sabi. #AI #Cloud #5G Freak. Opinions are my own