0% found this document useful (0 votes)
15 views48 pages

iot lab

Uploaded by

Sņap SĘlva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views48 pages

iot lab

Uploaded by

Sņap SĘlva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Ex.

No : 01
Date : To Study various IoT Protocols – 6LowPAN, IPv4/IPv6,
Wifi , Bluetooth, MQTT

AIM:

To study various IOT protocol- 6 LowPAN, IPv4/IPv6, Wifi, Bluetooth, MQTT.

6LowPAN:

6LoWPAN stands for IPv6 over Low-power Wireless Personal Area Networks. It is a
standard protocol for realizing IPv6 communication on wireless networks composed of low power
wireless modules. 6LoWPAN specification contains packet compression and other optimization
mechanisms to enable the efficient transmission of IPv6 packets on a network with limited power
resources and reliability, which makes efficient IPv6 communication over low-power wireless
networks possible.

IPv4 / IPv6:

IPv4 :

The IPv4 address is a 32-bit number that uniquely identifies a network interface on a machine.
An IPv4 address is typically written in decimal digits, formatted as fou8-bit fields that are separated by
periods. Each 8-bit field represents a byte of the IPv4 address.

IPv6 :

IP v6 was developed by Internet Engineering Task Force(IETF)to deal with the problem of IP
v4 exhaustion. IP v6 is a 128-bits address having an address space of 2^128, which is way bigger than
IPv4. In IPv6 we use Colon-Hexa representation. There are 8 groups and each group represents 2
Bytes.
WiFi:

Wi-Fi is a wireless technology used to connect computers, tablets, smartphone and other
devices to the internet. Wi-Fi is the radio signal sent from a wire router to a nearby device, which
translates the signal into data you can see and use. The device transmits a radio signal back to the
router, which connects to the internet by wire or cable.

Bluetooth:

Bluetooth is a short-range wireless communication network that allows devices such as


mobile phones, computers, and peripherals to transmit data or voice wirelessly over a short
distance. The purpose of Bluetooth is to replace the cables that normally connect devices, while
still keeping the communications between them secure
MQTT:

Message queuing telemetry support (MQTT) is defined as a low bandwidth consumption


machine-to-machine protocol that helps IoT devices communicate with each other, with minimal code
requirements and network footprint.

RESULT:

The topic me clearly understood and learned successfully.


Ex.No : 02 IoT Application Development Using sensors and actuators
(temperature sensor, light sensor, infrared sensor )
Date :

AIM :

To develop IoT Application Using sensors and actuators (temperature sensor, light sensor,
infrared sensor)

REQUIREMENTS:

1. Arduino UNO Board

2. Temperature sensor

3. Female to male cable

CONNECTION:

• Power to 5V

• Vout to A1

• GND to GND

PROCEDURE:

STEP 1: Set up the Arduino and temperature sensor, light sensor, infrared sensor

connect pin followed by the respective connections.

STEP 2: Start the Arduino IDE and put your code.

STEP 3: Next select correct board and port set the band rate (9600).

STEP 4: Finally compile your code and upload the code into Arduino board.

STEP 5: See your output in the serial monitor.


PROGRAM :

float temp;

int tempPin = 0;

void setup() {

Serial.begin(9600);

void loop() {

temp = analogRead(tempPin);

temp = temp * 0.48828125;

Serial.print("TEMPERATURE = ");

Serial.print(temp); // display temperature value

Serial.print("*C");

Serial.println();

delay(1000);

}
DIAGRAM:

OUTPUT :
LIGHT SENSOR :

REQUIREMENT :

1. Arduino UNO board

2. Light sensor

3. Female to male cable

CONNECTION :

• VCC - 5v
• GND – GND
• OUT – Digital or analog pin

PROGRAM :

void setup() {

Serial.begin(9600);

void loop() {

int analogValue = analogRead(A0);

Serial.print("Analog reading: ");

Serial.print(analogValue); // the raw analog reading

if (analogValue < 10) {

Serial.println(" - Dark");

} else if (analogValue < 200) {

Serial.println(" - Dim");

} else if (analogValue < 500) {

Serial.println(" - Light");

} else if (analogValue < 800) {

Serial.println(" - Bright");

} else {
Serial.println(" - Very bright");

delay(500);

DIAGRAM :

OUTPUT :
INFRARED SENSOR:

REQUIREMENT :

1. Arduino UNO board

2. Infrared sensor

3. Female to male cable

CONNECTION :

• VCC - 5v

• GND – GND

• OUT – Digital or analog pin

PROGRAM :

int IRSensor = 9; // connect ir sensor module to Arduino pin 9

int LED = 13; // conect LED to Arduino pin 13

void setup() {

Serial.begin(115200); // Init Serila at 115200 Baud

Serial.println("Serial Working"); // Test to check if serial is working or not

pinMode(IRSensor, INPUT); // IR Sensor pin INPUT

pinMode(LED, OUTPUT); // LED Pin Output

void loop() {

int sensorStatus = digitalRead(IRSensor); // Set the GPIO as Input

if (sensorStatus == 1) { // Check if the pin high or not

digitalWrite(LED, LOW); // LED LOW

Serial.println("Motion Ended!");

}
else{

digitalWrite(LED, HIGH); // LED High

Serial.println("Motion Detected!");

DIAGRAM :

OUTPUT :
RESULT:

The topic me clearly understood and learned successfully.


Ex.No :03 To Study Raspberry Pi development board and to
implement LED Blinking applications
Date :

AIM:

To Study Raspberry Pi development board and to implement LED blinking applications.

REQUIREMENT :

1. Arduino UNO board

2. LED light

3. Resistor

4. Female to male cable

CONNECTION :

Cathode (-) to resistor terminal 2

Resistor terminal 1 to GND

Anode (+) to digital pin or analog pin

PROCEDURE :

STEP 1: Set up the Arduino and LED connect pin followed by the respective connections.

STEP 2: Start the Arduino IDE and put your code.

STEP 3: Next select correct board and port set the band rate (9600).

STEP 4: Finally compile your code and upload the code into Arduino board.

STEP 5: Stop the program.


PROGRAM :

void setup() { // initialize digital pin 13 as an output.

pinMode(2, OUTPUT);

void loop() {

digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(2, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

}
DIAGRAM :

RESULT:

The topic me clearly understood and learned successfully


Ex.No : 04 To develop an application to send and receive data with
Arduino using HTTP request
Date :

AIM :

To develop an application to send and receive data with Arduino using HTTP request

REQUIREMENT :

1. ESP32 Board

2. Micro USB Connects

REQUIRED LIBRARIES :

Open the library manager then install the following libraries ,

• WiFi

• HttpClient

PROCEDURE :

STEP 1: Start the program and connected the ESP32 via USB cable into the system.

STEP 2: Connected the internet via wifi on your devices.

STEP 3: Run the POST method program and you will post your detail into the

respective/repository.

STEP 4: While upload the program long press the boot button on ESP32.

STEP 5: Run the GET method program and you will get the respect the id value

details.

STEP 6: Stop the program.


PROGRAM :

#include <WiFi.h>

#include <HTTPClient.h>

// Wi-Fi credentials

const char* ssid = "BARANI"; // Replace with your WiFi SSID

const char* password = "barani123"; // Replace with your WiFi password

// HTTP server details

const char* serverNameGET = "http://jsonplaceholder.typicode.com/posts/1";

const char* serverNamePOST = "http://jsonplaceholder.typicode.com/posts";

void setup() {

Serial.begin(115200);

delay(4000);

// Connect to Wi-Fi

WiFi.begin(ssid, password);

Serial.print("Connecting to WiFi...");

while (WiFi.status() != WL_CONNECTED) {

delay(1000);

Serial.print(".");

Serial.println("\nConnected to WiFi");

void loop() {

if (WiFi.status() == WL_CONNECTED) {

WiFiClient client; // Create a WiFi client

HTTPClient http; // Initialize the HTTP client


// =========== GET Request ===========

Serial.println("Making GET request...");

http.begin(client, serverNameGET); // Specify the client and URL

int httpResponseCode = http.GET(); // Send GET request

if (httpResponseCode > 0) {

String payload = http.getString(); // Get the response

Serial.println("Response Code: " + String(httpResponseCode));

Serial.println("Received payload: " + payload);

} else {

Serial.println("Error on GET request: " + String(httpResponseCode));

http.end(); // Close the connection

delay(3000); // Wait 3 seconds before next request

// =========== POST Request ===========

Serial.println("Making POST request...");

http.begin(client, serverNamePOST); // Specify the client and URL for POST request

http.addHeader("Content-Type", "application/json"); // Set content type to JSON

// Create JSON data for the POST request

String jsonData = "{\"title\":\"foo\",\"body\":\"bar\",\"userId\":1}";

httpResponseCode = http.POST(jsonData); // Send POST request

if (httpResponseCode > 0) {

String payload = http.getString(); // Get the response

Serial.println("Response Code: " + String(httpResponseCode));

Serial.println("Received payload: " + payload);


} else {

Serial.println("Error on POST request: " + String(httpResponseCode));

http.end(); // Close the connection

} else {

Serial.println("WiFi not connected!");

delay(10000); // Wait 10 seconds before next request cycle

}
OUTPUT :

RESULT :

The topic me clearly understood and learned successfully.


Ex.No : 05 To develop an application that measures the room
temperature and posts the temperature value on the cloud
Date :
platform
AIM :

To develop an application that measures the room temperature and posts the temperature value
on the cloud platform.

HARDWARE REQUIRED:

1. ESP32 development board

2. DHT11 Sensor

3. Connecting Wires

SOFTWARE REQUIRED:

1. Google Firebase

2. Arduino IDE

CONNECTIONS:

• Gnd – gnd

• Data – D14

• Vcc – 3v3

REQUIRED LIBRARIES :

Open the library manager then install the following libraries ,

1. DHT sensor library and Adafruit Unified Sensor library

PROCEDURE :

STEP 1: get up the ESP32 and DHT11 connect to the correct pins followed by the

respective connections.

STEP 2: Create database on Google Firebase and connect the firebase with the board using
Firebase host and Firebase authentication key.

STEP 3: Now run the program, You can see the output in serial monitor and also in google
firebase Cloud.
FIREBASE CLOUD INSTRUCTIONS :

• Cloud platform link : https://firebase.google.com/ Click ‘Go to Console’ as

highlighted in the red rectangular box.

• You will be redirected to a new web page with the welcome message. Click the button
‘Create a Project’

• Write the name of your project. Remember to tick the Firebase term agreement. Now click
‘Continue’.

• Go to the settings icon and click ‘Project Settings’., Now, go to ‘Service Accounts’ and click
‘Generate new private key’. copy it then paste it in code.

• Next, Under the Build tab go to ‘Realtime Database.’ Then click ‘Create Database.’after that
you will see the host link, then copy that then paste it in code.

PROGRAM :

#include <ESP8266WiFi.h>

#include <FirebaseESP8266.h>

#include <DHT.h>

// WiFi credentials

const char* ssid = "BARANI";

const char* password = "barani123";

// Firebase setup

#define FIREBASE_HOST "roomtempmonitor-277c5-default-rtdb.asia-


southeast1.firebasedatabase.app" // Replace with your Firebase database URL

#define FIREBASE_AUTH "J8TOiH1EZ8A783PuzMdD5wgMt1sE2NeyI0qb0ACd" // Replace


with your Firebase database secret

FirebaseData firebaseData;

FirebaseConfig firebaseConfig;

FirebaseAuth firebaseAuth;
// DHT Sensor setup

#define DHTPIN 4 // Digital pin connected to the DHT sensor

#define DHTTYPE DHT11 // DHT11 or DHT22

DHT dht(DHTPIN, DHTTYPE);

void setup() {

Serial.begin(115200);

delay(4000);

dht.begin();

// Connect to Wi-Fi

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);

Serial.println("Connecting to WiFi...");

Serial.println("Connected to WiFi");

// Set up Firebase

firebaseConfig.database_url = FIREBASE_HOST;

firebaseAuth.token.uid = FIREBASE_AUTH;

Firebase.begin(&firebaseConfig, &firebaseAuth);

Serial.println("Firebase initialized");

void loop() {

// Check WiFi connection

if (WiFi.status() != WL_CONNECTED) {

Serial.println("WiFi disconnected! Reconnecting...");


WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);

Serial.println("Reconnecting to WiFi...");

Serial.println("Reconnected to WiFi");

}// Read temperature and humidity

float temperature = dht.readTemperature();

float humidity = dht.readHumidity();

// Check if read failed

if (isnan(temperature) || isnan(humidity)) {

Serial.println("Failed to read from DHT sensor!");

return;

// Print temperature and humidity to Serial

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.print(" °C\tHumidity: ");

Serial.print(humidity);

Serial.println(" %");

// Send data to Firebase

if (Firebase.setFloat(firebaseData, "/room/temperature", temperature)) {

Serial.println("Temperature updated in Firebase: " + String(temperature));

} else {

Serial.println("Failed to update temperature: " + firebaseData.errorReason());


}

if (Firebase.setFloat(firebaseData, "/room/humidity", humidity)) {

Serial.println("Humidity updated in Firebase: " + String(humidity));

} else {

Serial.println("Failed to update humidity: " + firebaseData.errorReason());

// Wait for a bit before the next reading

delay(10000); // 10 seconds delay between readings

DIAGRAM :
OUTPUT :

GOOGLE FIREBASE OUTPUT:


RESULT :

The topic me clearly understood and learned successfully.


Ex.No : 06 To develop an application that measures the moisture of soil
and post the sensed data over Google firebase cloud
Date :
platform

AIM :

To develop an application that measures the moisture of soil and post the sensed data over
Google firebase cloud platform.

REQUIREMENTS:

● ESP32 Board

● Soil Moisture Sensor

● Cables

CONECTION:

● Vcc – 5v

● Gnd – gnd

● A0 – A0

● D0 - (SKIP THIS)

REQUIRED LIBRARIES :

Open the library manager then install the following libraries ,

• FirebaseESP8266

• ESP8266WiFi

PROCEDURE :

STEP 1 : get up the ESP32 and soil moisture sensor and connect to the correct pins followed by
the respective connections.

STEP 2 : Create database on Google Firebase and connect the firebase with the board using
Firebase host and Firebase authentication key

STEP 3 : Now run the program, You can see the output in serial monitor and also in google
firebase Cloud.
PROGRAM :

#include <ESP8266WiFi.h>

#include <FirebaseESP8266.h>

// Replace with your Firebase database URL and secret

#define FIREBASE_HOST "soil-5e14f-default-rtdb.firebaseio.com"

#define FIREBASE_AUTH "pDxJz8JxOjPFcO1OzyDb9sJPrlJq0NaagXqSUvUE"

// Replace with your Wi-Fi credentials

#define WIFI_SSID "BARANI"

#define WIFI_PASSWORD "barani123"

const int soilSensorPin = A0;

FirebaseData firebaseData;

FirebaseConfig firebaseConfig;

FirebaseAuth firebaseAuth;

void setup() {

// Initialize serial communication

Serial.begin(115200);

// Connect to Wi-Fi

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("Connecting to WiFi");

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

Serial.println("Connected!");

Serial.print("IP Address: ");


Serial.println(WiFi.localIP());

// Set Firebase configuration

firebaseConfig.database_url = FIREBASE_HOST; // Set database URL

firebaseConfig.signer.tokens.legacy_token = FIREBASE_AUTH; // Set authentication token

// Start Firebase

Firebase.begin(&firebaseConfig, &firebaseAuth); // Pass both config and auth

Serial.println("Firebase initialized.");

void loop() {

// Read the value from the soil moisture sensor (0 to 1023)

int soilMoistureValue = analogRead(soilSensorPin);

// Print the value to the Serial Monitor

Serial.print("Soil Moisture Level: ");

Serial.println(soilMoistureValue);

// Send the value to Firebase

if (Firebase.setInt(firebaseData, "/SENSE/SOILDATA", soilMoistureValue)) {

Serial.println("Data sent to Firebase successfully.");

} else {

Serial.print("Firebase error: ");

Serial.println(firebaseData.errorReason());

// Delay for a bit to avoid flooding the database

delay(1000);

}
DIAGRAM :

OUTPUT :

GOOGLE FIREBASE OUTPUT :


RESULT :

The topic me clearly understood and learned successfully.


Ex.No : 07 To develop an application for measuring the distance using
ultrasonic sensor and post distance value on Google cloud
Date :
IoT platform
AIM:

To develop an application for measuring the distance using ultrasonic sensor and post

distance value on Google cloud IoT platform.

REQUIREMENT:

1. ESP32

2. Ultrasonic sensor

CONNECTIONS:

• Vcc – vin

• Trig – d5

• Echo d18

• Gnd – gnd

REQUIRED LIBRARIES :

Open the library manager then install the following libraries ,

• ESP8266WiFi

• FirebaseArduino

PROCEDURE:

STEP 1 : get up the ESP8266 and Ultrasonic sensor and connect to the correct pins

followed by the respective connections.

STEP 2 : Create database on Google Firebase and connect the firebase with the board

using Firebase host and Firebase authentication key

STEP 3 : Now run the program, You can see the output in serial monitor and also in

google firebase Cloud.


PROGRAM :

#include <FirebaseESP8266.h>

#include <ESP8266WiFi.h>

// Firebase configuration

#define FIREBASE_HOST "soil-5e14f-default-rtdb.firebaseio.com"

#define FIREBASE_AUTH "pDxJz8JxOjPFcO1OzyDb9sJPrlJq0NaagXqSUvUE"

FirebaseData firebaseData;

FirebaseConfig firebaseConfig;

FirebaseAuth firebaseAuth;

// Define your pins

const int trigPin = 5; // Change to your actual trigger pin

const int echoPin = 6; // Change to your actual echo pin

void setup() {

Serial.begin(115200);

// Wi-Fi connection

WiFi.begin("BARANI", "barani123");

while (WiFi.status() != WL_CONNECTED) {

delay(1000);

Serial.println("Connecting to WiFi...");

Serial.println("Connected to WiFi");

// Firebase configuration

firebaseConfig.database_url = FIREBASE_HOST;
Firebase.begin(&firebaseConfig, &firebaseAuth);

Serial.println("Firebase initialized");

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

// Test Firebase connection with a basic write operation

if (Firebase.setString(firebaseData, "/test", "connection successful")) {

Serial.println("Firebase test connection successful.");

} else {

Serial.println("Firebase test failed: " + firebaseData.errorReason());

void loop() {

if (WiFi.status() != WL_CONNECTED) {

Serial.println("WiFi not connected. Trying to reconnect...");

WiFi.reconnect();

delay(1000);

return; // Exit loop to prevent blocking

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

distance = (duration * 0.034) / 2; // Calculate distance

// Send distance to Firebase

Serial.println("Sending distance to Firebase...");

if (Firebase.setInt(firebaseData, "/distance", distance)) {

Serial.println("Distance updated in Firebase: " + String(distance));

} else {

Serial.println("Failed to update distance: " + firebaseData.errorReason());

delay(1000); // Delay for a second

yield(); // Allows the ESP8266 to perform background tasks

}
DIAGRAM :

OUTPUT :
GOOGLE FIREBASE OUTPUT :

RESULT :

The topic me clearly understood and learned successfully


Ex.No : 08
Date : Develop a Simple application based on sensors.

AIM :

To develop a Simple application based on sensors.

REQUIREMENTS:

1. Arduino UNO.

2. Bread board.

3. Ultrasonic sensor.

4. Bluetooth module(HC05).

5. Female to male and male to male cables.

PROCEDURE :

STEP 1 : Download the app using the link and install the app in your mobile.

https://drive.google.com/file/d/1balZJrsXkquxb7OoNgbUSdCWFh47muoH/view?usp

=share_link

STEP 2 : Connect your arduino board same as the following diagram.

STEP 3 : Now run and upload the program into arduino then open your mobile and

open the Bluetooth and click the HC05 and enter 1234 as a password.

STEP 4 : Open the app in your mobile and click the click to connect and now select

the HC05 bluetooth name.

STEP 5 : That’s it connected this is message was showed in your app now you put the

object infront of ultrasonic sensor the sensor give a correct distance in cm.
PROGRAM :

const int trigPin = 4;

const int echoPin = 5;

long duration;

int distance;

void setup() {

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

Serial.begin(9600);

void loop() {

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;

Serial.print("Distance in cm : ");

Serial.println(distance);

}
OUTPUT :

RESULT :

The topic me clearly understood and learned successfully.


Ex.No : 09
Date : Develop IoT Application using Django Framework and
Firebase/Bluemix Platform.
AIM :

To develop IoT Application using Django Framework and Firebase/Bluemix Platform.

HARDWARE REQUIRED:

1. ESP32 development board

2. DHT11 Sensor

3. Connecting Wires

SOFTWARE REQUIRED:

1. Google Firebase

2. Arduino IDE

3. Visual Studio code

CONNECTIONS:

• Gnd – gnd

• Data – D14

• Vcc – 3v3

REQUIRED LIBRARIES :

In Arduino IDE ,Open the library manager then install the following libraries ,

1. DHT sensor library

2. FirebaseESP32.h

PROCEDURE :

STEP 1 : First create Arduino file and install the required libraries

STEP 2 : And type the code in the file and select correct board name and port

STEP 3 : And now create a project in firebase cloud

STEP 4 : Then create a webapp using below mentioned method


STEP 5 : Go to the settings in firebase icon and click ‘Project Settings’., Now, go to

‘Service Accounts’ and click ‘Database Secrets’ .copy it then paste it in code.

STEP 6 : Next, Under the Build tab go to ‘Realtime Database.’ Then click ‘Create

Database.’after that you will see the host link,then copy that then paste it in code.

STEP 7 : Then,install the django framework

STEP 8 : Integrating Firebase Database to Django Project

Next STEP, Create files

1. urls.py

2. views.py

3. Home.py

• Goto project settings in firebase and scroll down you will see the lot of codes and

choose and copy the config block and paste it into views.py config block.

• Then ,give the cmd line python manage.py runserver.

• Finally create the local host server ,this open to get the humidity and temperature

value.

• First create a database into firebase and next click the following icon(</>)
• Give a nickname to your Web Project and Click On Register App

• Now you will see the configuration of your App like this. Copy this Code

somewhere. You will need it later.

• Click On The Realtime Database button

• Now Click On Create Database.

• Now we create a Django webapp so lets create virtual environment first by

following comments

• Open cmd and type.

python -m pip install -U pip

• Install virtual environment- Enter following command in cmd.

pip install virtualenv

• Set Virtual environment.

virtualenv env_site

• Change directory to env_site by this command

cd env_site

• Go to Scripts directory inside env_site and activate virtual environment

• Cd Scripts and next type activate for activating activate.bat file

• Install Django - Install django by giving following command

Pip install django


• Return to the env_site directory cd ..

• Start a project by following command

django-admin startproject projectname

• Change directory to projectname cd projectname

• and now we need to install pyrebase4 using this comment in cmd

pip install pyrebase4

• open pycharm or vscode and open the correct folder where your Django files contain like this

• Create a views.py file in your project directly. The Structure should be like this .

• Next edit only urls.py no need to create it the file and type this code.

from django.contrib import admin

from django.urls import path

from . import views

urlpatterns = [

path('admin/', admin.site.urls),

path('', views.home),

• Next create views.py into projectname folder it and types this code.
from django.shortcuts import render

import pyrebase

config={

"apiKey": "AIzaSyAC6MeF1tqIOEQwwLptWtFCg8t2Z4reB0o",

"authDomain": "dht11-f5b71.firebaseapp.com",

"databaseURL": "https://dht11-f5b71-default-rtdb.firebaseio.com",

"projectId": "dht11-f5b71",

"storageBucket": "dht11-f5b71.appspot.com",

"messagingSenderId": "550162327226",

"appId": "1:550162327226:web:b8a4593bc436431a350483",

"measurementId": "G-THS4J3Y3PD"

firebase=pyrebase.initialize_app(config)

authe = firebase.auth()

database=firebase.database()

def home(request):

HUMIDITY=database.child('ESP32_APP').child('HUMIDITY').get().val()

TEMPERATURE=database.child('ESP32_APP').child('TEMPERATURE').get().val()

return

render(request,"Home.html",{"HUMIDITY":HUMIDITY,"TEMPERATURE":TEMP

ERATURE})

• Here change the config section as per your firebase config file.

• Next create templates folder in this directory.

C:\Users\rohit\env_site\project_name
Like this

• Next create Home.html file inside the templates folder and type this code into it

HOME.HTML

<!DOCTYPE html>

<html lang="en">

<head>

</head>

<body>

<H1>

<meta charset="UTF-8">

<title>Sample Project</title>

Room Humidity is {{ HUMIDITY }}

</H1>

<br/>

<h2>

Room Temperature is {{ TEMPERATURE }}

</h2>

<br>
</body>

</html>

• Next open setting.py and do a one edit into it first goto 79th line in

setting.py file and copy the NAME field value and paste into 57th line

‘DIRS’ = [] into it and change name into templates

• Now everything is ready lets run the server Now move to your project directory

C:\Users\rohit\env_site\projectname and run our project using the given command.

python manage.py runserver.

• It will give the localhost address and copy the webaddress and paste into browser

you will get the output this take the value from firebase.
OUTPUT :

RESULT :

Thus the program has been verified and output is executed successfully.

You might also like