Lab3 Firebase HandsOn
Lab3 Firebase HandsOn
Descrip on
This lab introduces students to the basics of Firebase Cloud. Students will set up an ESP32
microcontroller with a single sensor (DHT11) to publish data to Firebase. This foundational
exercise will help students understand data flow in IoT systems and the role of cloud storage in
monitoring data.
Requirements
Hardware: ESP32 microcontroller, DHT11 sensor (temperature and humidity).
Software:
o Arduino IDE
o Firebase Cloud account
o Wi-Fi connection
Click here
Click here
Click here
Click here
Click here
Click here
Create new real time dataset
Get URL and Key to write in the real time dataset
Create and Configure a Firebase Client on ESP32 card
Use the following sketch to send random temperature and humidity values.
#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <Firebase_ESP_Client.h>
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();
/* Sign up */
if (Firebase.signUp(&config, &auth,"","")){
Serial.println("ok");
signupOK = true;
}
else{
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see
addons/TokenHelper.h
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
}
void loop(){
if (Firebase.ready() && signupOK && (millis() - sendDataPrevMillis > 15000 ||
sendDataPrevMillis == 0)){
sendDataPrevMillis = millis();
Serial.println("Firebase is ready data not sent yet");
// Write an Int number on the database path test/int
if (Firebase.RTDB.setFloat(&fbdo, "temperature/float", 0.01 +
random(0,100))){
Serial.println("PASSED");
Serial.println("PATH: " + fbdo.dataPath());
Serial.println("TYPE: " + fbdo.dataType());
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
count++;