#include <WiFi.h>
#include <FirebaseESP32.h>
#include "DHTesp.h"
// Provide the token generation process info.
// Provide the RTDB payload printing info and other helper functions.
// #include <addons/RTDBHelper.h>
/* 1. Define the WiFi credentials */
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define FIREBASE_HOST "tmanga-74156-default-rtdb.firebaseio.com"
#define FIREBASE_AUTH "Cl2IDszwbobLYz1b2TODG832WaxywRIxmoUbeh8c"
// Define Firebase Data object
FirebaseData fbdo;
const int DHT_PIN = 15;
DHTesp dhtSensor;
int value = 0;
int analogValue =0;
int flamelevel;
void setup()
{
Serial.begin(115200);
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();
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
// Comment or pass false value when WiFi reconnection will control by your code or third party library
Firebase.reconnectWiFi(true);
}
void loop()
{
value = digitalRead(4);
analogValue = analogRead(35);
flamelevel = map(analogValue, 0, 4096, 100, 0);
Serial.println(value);
Serial.println(flamelevel);
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Firebase.setInt(fbdo,"/devices/device_02/fire",value);
Firebase.setInt(fbdo,"/devices/device_02/flamelevel",flamelevel);
Firebase.setInt(fbdo,"/devices/device_02/temp",data.temperature);
Firebase.setInt(fbdo,"/devices/device_02/smoke",data.humidity);
delay(1000);
}