1

Need to connect my arduino uno board with gsm/gprs solution to a firebase database in order to store real time data from water quality sensors. sensors are all connected and the gsm module is working fine. But couldn't find a way to connect the solution to a firebase. I appreciate if anyone can help because I'm a beginner to this field and storing data in firebase is compulsory in order to retrieve them in the web app and the mobile app.How can I connect this arduino board with gsm module sim 900 to the firebase?

Nivarthana
  • 11
  • 1
  • 3

2 Answers2

0

Use Firebase Functions to set up an https callable. And in the POST you add a key (So nobody else can use your function), and the data you want to read/write. https://firebase.google.com/docs/functions/database-events

Mr. Arbitrary
  • 932
  • 11
  • 25
0

You can configure first the firebase functions service, this allow to send information to firebase and store, just as above answer, the problem basic is SIM900+ARDUINO cannot handle a https protocol and firebase only allows that.

Whit functions by firebase you can solve this.

Don't forget before

npm i express
const functions = require("firebase-functions");
var admin = require("firebase-admin");
const express = require("express");

// Your credentials from firebase configurations
var serviceAccount = require("./credentials.json");

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "HERE_YOUR_FIREBASE_URL"
});

const app = express()

const db = admin.firestore()

const collect = db.collection('YOUR_COLLECTION').doc('YOUR_DOCUMENT')



// 'data_id' have my data from SIM900, and I captured by URL to save
app.get('/data/:data_id', async (req, res) => {
    const date = new Date()
    const tempMap = new Map()
    try {
        tempMap.set(date.getTime(), req.params.data_id)
        await collect.update(Object.fromEntries(tempMap))
        return res.status(200).json()
    } catch (e) {
        return res.status(500).send(e)
    }
});

exports.app = functions.https.onRequest(app)

This simple process permit you get access to Firebase using SIM900