-
-
Save maxpromer/f0a88708a0cb4823fef8a65389260645 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
#include <ESP8266WiFi.h> | |
#include <FirebaseArduino.h> | |
#include <DHT.h> | |
// Config Firebase | |
#define FIREBASE_HOST "ledesp-86d37.firebaseio.com" | |
#define FIREBASE_AUTH "<YOUR KEY>" | |
// Config connect WiFi | |
#define WIFI_SSID "<YOUR WIFI NAME>" | |
#define WIFI_PASSWORD "<YOUR WIFI PASSWORD>" | |
// Config DHT | |
#define DHTPIN 4 | |
#define DHTTYPE DHT11 | |
DHT dht(DHTPIN, DHTTYPE); | |
void setup() { | |
Serial.begin(9600); | |
WiFi.mode(WIFI_STA); | |
// connect to wifi. | |
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); | |
Serial.print("connecting"); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
Serial.println(); | |
Serial.print("connected: "); | |
Serial.println(WiFi.localIP()); | |
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); | |
dht.begin(); | |
} | |
void loop() { | |
// Read temp & Humidity for DHT22 | |
float h = dht.readHumidity(); | |
float t = dht.readTemperature(); | |
if (isnan(h) || isnan(t)) { | |
Serial.println("Failed to read from DHT sensor!"); | |
delay(500); | |
return; | |
} | |
StaticJsonBuffer<200> jsonBuffer; | |
JsonObject& root = jsonBuffer.createObject(); | |
root["temperature"] = t; | |
root["humidity"] = h; | |
// append a new value to /logDHT | |
String name = Firebase.push("logDHT", root); | |
// handle error | |
if (Firebase.failed()) { | |
Serial.print("pushing /logDHT failed:"); | |
Serial.println(Firebase.error()); | |
return; | |
} | |
Serial.print("pushed: /logDHT/"); | |
Serial.println(name); | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment