Skip to content

Instantly share code, notes, and snippets.

@li2hub
Created March 13, 2019 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save li2hub/fdb6d8341e22868ec2eb8e41deaa74f9 to your computer and use it in GitHub Desktop.
Save li2hub/fdb6d8341e22868ec2eb8e41deaa74f9 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
from time import sleep
from firebase import firebase
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 4
firebase = firebase.FirebaseApplication('https://YOUR_FIREBASE_URL.firebaseio.com/', None)
firebase.put("/", "/temp", "0.00")
firebase.put("/", "/humidity", "0.00")
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
str_temp = ' {0:0.2f} *C '.format(temperature)
str_hum = ' {0:0.2f} %'.format(humidity)
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature,humidity))
firebase.put("/","/temp",str_temp)
firebase.put("/","/humidity",str_hum)
else:
print('Failed to get reading. Try again!')
sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment