Last active
August 12, 2020 02:30
-
-
Save fataelislami/c2834e4485040a8c2ce4317c7a504165 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 "FirebaseESP32.h" | |
#include <WiFi.h> | |
#include "DHT.h" | |
#define DHTPIN 2 | |
#define DHTTYPE DHT11 | |
#define FIREBASE_HOST "iot-smarthelm.firebaseio.com" | |
#define FIREBASE_AUTH "isi disini" | |
#define WIFI_SSID "GROWLAB" | |
#define WIFI_PASSWORD "cigadungno20" | |
DHT dht(DHTPIN, DHTTYPE); | |
//Define FirebaseESP32 data object | |
FirebaseData firebaseData; | |
FirebaseJson json; | |
String fireStatus=""; | |
void setup() | |
{ | |
Serial.begin(115200); | |
// dht.begin(); | |
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); | |
Serial.print("Connecting to Wi-Fi"); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
Serial.print("."); | |
delay(300); | |
} | |
Serial.println(); | |
Serial.print("Connected with IP: "); | |
Serial.println(WiFi.localIP()); | |
Serial.println(); | |
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); | |
Firebase.reconnectWiFi(true); | |
//Set database read timeout to 1 minute (max 15 minutes) | |
Firebase.setReadTimeout(firebaseData, 1000 * 60); | |
//tiny, small, medium, large and unlimited. | |
//Size and its write timeout e.g. tiny (1s), small (10s), medium (30s) and large (60s). | |
Firebase.setwriteSizeLimit(firebaseData, "tiny"); | |
/* | |
This option allows get and delete functions (PUT and DELETE HTTP requests) works for device connected behind the | |
Firewall that allows only GET and POST requests. | |
Firebase.enableClassicRequest(firebaseData, true); | |
*/ | |
//String path = "/data"; | |
Serial.println("------------------------------------"); | |
Serial.println("Connected..."); | |
} | |
void loop(){ | |
// ini untuk write data | |
//String data = "OFF"; | |
//json.set("/data", data); | |
// Firebase.updateNode(firebaseData,"/Sensor",json); | |
if(Firebase.getString(firebaseData,"/Sensor/status")){ | |
String status=firebaseData.stringData(); | |
if(status=="ON"){ | |
float t = dht.readTemperature(); | |
float h = dht.readHumidity(); | |
Serial.print("Suhu Saat Ini : "); | |
Serial.println(t); | |
json.set("/suhu", t); | |
Firebase.updateNode(firebaseData,"/Sensor",json); | |
}else{ | |
Serial.println("Request OFF"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment