The following project was developed to collect the humidity and the temperature using the DHT22 sensor and Raspberry Pi v3 and store these data on the Firebase database.
The following instructions should work with any types of projects, since the basic idea has pretty much the same logic.
- Raspberry Pi v3 model B, running Raspbian 4.9.35-v7.
- DHT22 sensor with 3 pins: GND, 5V and Data.
- sudo apt-get update
- sudo apt-get install python-dev
- wget https://bootstrap.pypa.io/get-pip.py
- sudo python get-pip OR sudo apt-get install python-pip (new Raspian versions)
- sudo pip install pyrebase
- I also had to download some files for the DHT22 sensor from github: https://github.com/adafruit/Adafruit_Python_DHT
If you are done with the previous steps, you are now ready to start writing the python script. Take a look at the following link for the pyrebase: https://github.com/thisbejim/Pyrebase.
# This code should be used with every script that you will be using to connect to the Firebase database.
import pyrebase
from firebase import firebase
config = {
# You can get all these info from the firebase website. It's associated with your account.
"apiKey": "apiKey",
"authDomain": "projectId.firebaseapp.com",
"databaseURL": "https://databaseName.firebaseio.com",
"storageBucket": "projectId.appspot.com"
}
firebase = pyrebase.initialize_app(config)
.
.
.
.