Created
March 13, 2019 13:45
-
-
Save li2hub/fdb6d8341e22868ec2eb8e41deaa74f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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