GithubHelp home page GithubHelp logo

samorange1 / connect-esp32-to-firebase-via-gsm Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 8.0 24 KB

Send Sensor data to Firebase via GSM with ESP32+ GSM

License: MIT License

PHP 70.48% C++ 25.29% Python 4.23%

connect-esp32-to-firebase-via-gsm's Introduction

Connect-ESP32-to-Firebase-via-GSM

Connect ESP32+GSM (Sim800l) to Google Firebase to send sensor data.

Background

As Firebase only accepts HTTPS requests, it becomes a bit difficult to send sensor data to the Real-time Database with an ESP32 and a GSM Module. I did not find any resource for this when I was doing my project, so I am keeping this here for anyone who needs it in the future.

Hardware used

In this project, I develop an IoT application capable of sending data to the Firbase Real-Time database using GPRS and receiving the sent data using a Python script. We utilize the following components:

Further Requirements -

  • Create an account on Firebase for data collection.
  • Create an account on any website hosting service. We used 000WebHost a free web server, for hosting our PHP script along with the libraries.

Instructions

Libraries used:

  • TinyGSM: it's a simple library that works well with SIM800L

Steps:

  • Firstly, Add Project on Firebase and give a suitable name to it and Create Project.
  • Navigate to Project Overview and click Realtime Database. Then Create Database, select a preferable location for your database (doesn’t matter really) and enable Test mode.
  • Copy and save the database link (in a format: https://xxxxx-xxxx-xxxx-xxxx.firebaseio.com/)
  • Proceed onto the Project Settings and under Service Accounts click Database secrets show and copy the API KEY. This is required for authentication in sending and extracting the data.
  • Create an account on Website hosting platform. After signing up and setting a website, go to the folder public.html in the File manager and upload the files from the PHP server folder. This creates a PHP server that accepts an HTTP POST request and sends the data to Firebase.

    NOTE: Do not upload the folder, just the files inside it.

  • Make the necessary changes in the upload.php file to add the details of the database link (DEFAULT_URL)and the API key (DEFAULT_TOKEN). Also, keep in mind the structure of the database the $DEFAULT PATH defines the variable under which the database will record the value. You can add additional paths by adding /<variable_name>.
  • Create an Arduino script and copy the provided code. Do not forget to add the necessary details as indicated in the script.
  • Flash the code and run it, you will see an 8 on your real-time database.
  • You can additionally run the python script on a local machine to extract the data.

Additional Instructions

This will cover the use of Python script to extract the data from the database for processing. The library in use is a Python interface to the Firebase’s REST API.

  • Install the required library.
pip install python-firebase
  • Go to your project >>> click on the icon "</>" with the tag add firebase to your web app
  • Copy the information of the form :
 var firebaseConfig = {
    apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    authDomain: "xxxxx-xxxx.firebaseapp.com",
    databaseURL: "https://xxxxx-xxxxx-xxxxx-xxxxx.firebaseio.com",
    projectId: "xxxx-xxxx",
    storageBucket: "xxxx-xxxx.appspot.com",
    messagingSenderId: "xxxxxxxxxxxxxx",
    appId: "1:xxxxxxxxxxxx:web:xxxxxxxxxxxxxxxxx",
    measurementId: "xxxxxxxxxxxxxxxx"
  };
  • Then copy this relevent information to the python script as indicated in the script.
  • Once you extract the data you can convert it to the required data type/ structure to perform your analysis.
  • Additionally you can review this discussion on stackoverflow to understand the method.

Credits:

Madhav Rawal
Aryaman Patel

connect-esp32-to-firebase-via-gsm's People

Contributors

samorange1 avatar zark-zeugan avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

connect-esp32-to-firebase-via-gsm's Issues

I changed code and it gives 403 forbidden error

Hello, firstly thank you for your sharing this repo.
It worked with sending manuel datas to firebase.

But my problem is,
I'm using geolocation api and sending data to firebase, theese both service uses https so I couldn't connect with same Lilygo Sim800l. Tried your method, and actually its working witn defined datas. But when I tried to done something with variables , it returns 403 forbidden.

I'm trying to post json datas to my server, and my server makes request for me, after response, sending response to firebase. Its working wth postman and reqbin. It never fails. But with sim800l, it always returns 403 forbidden. Do you have any advice?

error Posting data

Hi,

I followed your code and managed to connect to server via Arduino, however when I try to post data I get a 400 Bad Request error.
Could you help, please?
sketch_jan13a.txt

#edit
Issue fixed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.