0% found this document useful (0 votes)
24 views

2 Python Lab Manual

Uploaded by

Sagar M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

2 Python Lab Manual

Uploaded by

Sagar M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

IoT Enabled Smart Home Automation System 1NH21MC079

CHAPTER 1
INTRODUCTION

The Internet of Things (IoT) is a system that allows devices to be connected and remotely
monitored across the Internet. In the last years, the IoT concept has had a strong evolution,
being currently used in various domains such as smart homes, telemedicine, industrial
environments, etc. [1]. Wireless sensor network technologies integrated into the IoT enable
a global interconnection of smart devices with advanced functionalities [2]. A wireless home
automation network, composed of sensors and actuators that share resources and are
interconnected to each other, is the key technology to making intelligent homes. A “smart
home” is a part of the IoT paradigm and aims to integrate home automation. Allowing
objects and devices in a home to be connected to the Internet enables users to remotely
monitor and control them [3]. These include light switches that can be turned on and off by
using a smartphone or by voice command, thermostats that will adjust the indoor
temperatures and generate reports about energy usage, or smart irrigation systems that will
start at a specific time of a day, on a custom monthly schedule, and thus will control water
waste. Smart home solutions have become very popular in the last years. Figure 1.1 shows
an example of a smart home that uses different IoT-connected utilities. One of the greatest
advantages of home automation systems is their easy management and control using
different devices, including smartphones, laptops and desktops, tablets, smart watches, or
voice assistants. Home automation systems offer a series of benefits; they add safety
through appliance and lighting control, secure the home through automated door locks,
increase awareness through security cameras, increase convenience through temperature
adjustment, save precious time, give control, and save money.

Page | 1
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

Figure 1.1: An IoT-based smart home depicting the use of smart sensing
devices for different purposes.

Several home automation systems involved with IoT have been proposed by academic
researchers in the literature in the last decade. In wireless-based home automation systems,
different technologies have been used, each of them with their pros and cons. For example,
Bluetooth-based automation is low cost, fast, and easy to be installed, but it is limited to
short distances. GSM and ZigBee are widely used wireless technologies as well. GSM
provides long-range communication at the cost of a mobile plan of the service provider that
operates in the area. Zigbee is a wireless mesh network standard that is designed to be low-
cost and with low power consumption, targeted at battery-powered devices in wireless
control and monitoring applications. However, it has a low data speed, low transmission, as
well as low network stability, and has a high maintenance cost. WiFi technology is used in.
The advantages of Wi-Fi technology over ZigBee or ZWave are related to price, complexity
(meaning simplicity), and accessibility. First, Wi-Fienabled smart devices are usually cheap.
In addition, it is easier to find do-it-yourself devices that use Wi-Fi, resulting a less expensive
option. Second, Wi-Fi is already a necessity and it is in most homes, so it is easier to buy
devices that are already Wi-Fi-enabled.

Page | 2
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

Finally, Wi-Fi is characterized by simplicity, meaning that a user must connect only a minimal
number of devices for a home automation setup. Since it is very common, the investment
on extra hardware is avoided; a user only needs the basic setup for a home automation
system. However, Wi-Fi is not designed to create mesh networks, it consumes ten times
more energy than similar devices using ZigBee, Z-Wave, or Bluetooth for example, and many
Wi-Fi routers can only allow up to thirty devices connected at once. As compared to
Ethernet, Wi-Fi brings several advantages, including the easy connection and access of
multiple devices, the expandability (adding new devices without the hassle of additional
wiring), lower cost, or single access point requirement. The cons include limited distance to
cover (a Wi-Fi network with standard equipment can be limited in range through walls and
other obstructions in a standard home), the number of devices can be limited, there is
interference and complex propagation effects, obstacles can block the WiFi signal and affect
the devices connected to it, and there are connection speed (the fastest speed of Wi-Fi is
much slower than a wired network), Internet security, and privacy issues. Low-cost, open-
source hardware components, such as Arduino and Raspberry Pi microcontroller unit (MCU)
boards, and a combination of sensors have been very used in the home automation domain.
Home automations using Arduino boards are proposed in [3]. Arduino is highly flexible, open
source, not expensive, and easy to program. In addition, the existence of a large and active
community of users is a great plus.

Page | 3
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

Table 1. Features comparison for home automation system published in the


last 10 years.

Another category of home automation systems is represented by commercial platforms,


such as Qivicon, Domintell, Loxone, or HomeSeer. They offer a wide range of smart home
devices, from multiple vendors, different communications protocols for wired (Domintell)
and wireless (Qivicon) transmissions, or both (HomeSeer and Loxone), and multiple
automations such as a locking system, controlling temperature, lightning
system,environmental system, video surveillance (only Qivicon and HomeSeer), or anti-
intrusion. All solutions provide a mobile app for controlling the systems. Pricewise, it
depends on the size of the house, the number of devices to be installed, and the needs of
the user. According to, the minimum cost comes between 1800 and 2600 euros. Currently,
a great variety of open source home automation systems exist. OpenHAB and Home

Page | 4
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

Assistant are two of the strongest players in the open source home automation community,
sharing a similar vision and integrating many devices. However, openHAB requires
knowledge regarding how to insert commands to integrate devices; it is complex and time
consuming. Home Assistant, on the other hand, is more user friendly, but it requires a
significant configuration effort. Mobile apps seem less flexible and quite complicated and
complex, especially for beginners. Domoticz delivers a decent number of features; its
configuration is mostly done through the web interface, and plugins are used to extend its
functionality. Unfortunately, the interface itself is not extremely intuitive. Domoticz is quite
limited in terms of supported devices and configurations. Calaos [40] and Jeedom are two
French players in the open source home automation community. Unfortunately, the
communities and forums are predominantly French, which can be a barrier to worldwide
adoption. A feature comparison of the most relevant open-source home automation
platforms is presented in Table 2. The platforms can be differentiated, among others, in
terms of the development language, the API, the amount of implemented protocols and
plugins, and the amount and type of documentations. Of course, these are not the only
options available. The authors of present a detailed comparison of fifteen open-source
platforms.

Table 2. Comparison of the most relevant open-source home automation


platforms.
Page | 5
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

CHAPTER 2
Materials and Methods

2.1. System Architecture and Design


The classic Ethernet and/or a Wi-Fi local network are usually enough for a working qToggle
setup. The different hardware used in the system includes Raspberry Pi 3 or 4 boards (any
model), ESP 8266 Wi-Fi modules, and smart devices. The Raspberry Pi version used for this
project is Raspberry Pi 4, due to the improvements brought, as compared to previous
versions. For example, Raspberry Pi 1 and 2 do not have Bluetooth (it is needed for
controlling the thermostats). An important feature of the Raspberry Pi is the row of general-
purpose input/output (GPIO) pins. A 40-pin GPIO header is found on all current Raspberry Pi
boards [44]. The three roles of a Raspberry Pi board in a qToggle setup are the following: the
board could act as a qToggle device when it is equipped with peripherals (sensors or relay
boards), it could also act as a master hub for other devices, and, finally, it could help install
the ESP firmware on some devices, when running Tuya Convert OS (Tuya is a Chinese smart
devices platform that offers cloud services for ESP8266/ESP8285-based devices). Tuya
Convert OS helps replace this proprietary Tuya firmware with a custom firmware, without
disassembling the device. An important fact is that it works only for Tuya-based devices. In
fact, Tuya Convert OS is a customized Raspbian OS image that runs Tuya Convert with a
friendly user interface. The main part of the home automation system based on IoT is the
microcontroller. The ESP 8266 Wi-Fi module represents a set of efficient highly integrated
wireless Systems on Chip (SoCs), which provides a complete and standalone Wi-Fi network
solution. The ESP8266EX version is one of the most integrated Wi-Fi chips in the industry. In
addition to its Wi-Fi functionalities, ESP8266EX integrates an enhanced version of L106
Diamond series 32-bit processor from Tensilica (company based in Silicon Valley, in the
semiconductor domain), with on-chip SRAM. ESP8266EX has seventeen GPIO pins, which
can be assigned to various functions by programming the appropriate registers, two power
pins, one ground pin, reset pin, and two clock pins. The devices used by qToggle are usually
sensors or actuators with an upstream network connection. Keeping the device firmware
Page | 6
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

updated is probably one of the most essential tasks, and it is often neglected when dealing
with a large number of devices. qToggle facilitates this task by allowing updates of the
firmware very simply for devices of different types and models. The qToggle API is an
intuitive HTTP API that enables remote controlling of basic hardware ports, such as GPIOs or
analog-to-digital converters (ADC). The idea behind qToggle is to control programmable
systems having a TCP/IP stack via simple HTTP requests.

For example, these systems can be single-board computers or TCP/IP-enabled


microcontrollers. API functions are grouped into the following categories:
• Device management—general status and configuration of the device;
• Port management—port information and configuration;
• Port values—reading and writing values from and to ports;
• Notifications—event notifications;
• Reverse API calls—API calls via reverse HTTP requests.
API specifications may seem quite complex, offering a wide range of functionalities and use
cases. However, most of them are optional, and only a small set of functions are mandatory
for a qToggle implementation. The qToggle ecosystem is composed of a qToggleServer,
qToggleOS, espQToggle, add-ons, and other tools and packages that are specific to certain
setups and use cases. The main component is qToggleServer, which is written in Python. It
acts as a hub and provides the user-friendly web app. qToggleOS is an operating system (OS)
ready to be used with Raspberry Pi boards and runs qToggleServer. espQToggle is a custom
firmware for ESP8266/ESP8285 devices and implements the qToggle API. Finally, addons are
optional pieces of software that enhance the functionality of qToggleServer. A device used
by qToggle will describe itself, indicating its configuration, its supported optional
functionalities, and what ports it exposes. Each port, in its turn, will describe itself, indicating
its identifier, type, configuration, and so on. By combining master–slave relationships
between simple devices and hubs in a network, a complex tree topology is obtained. Thus,
a large number of smart devices can be easily managed, as shown in Figure 2. The type of
communication in Figure 2 is Wi-fi or Ethernet. Consumers could operate at any level in the
hierarchy, thus limiting the access inside the network to any desired subtree.
Page | 7
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

Figure 2.1: The qToggle topology.

In a real-world setup, it is difficult to individually manage many devices. Therefore, a hub


will allow a centralized administration of devices used by qToggle. Hubs act as consumers
when communicating to other devices, but they also expose an API interface that allows
other consumers to see them as devices. This allows for the creation of complex hierarchies
of devices and hubs that are in a master–slave relationship. With qToggle, a device may act
as a master for other slave devices. The master controls slave devices and allows accessing
them through its own API functions. In the same way, a slave device can act as a master for
other devices. Thus, complex chained master–slave configurations can be obtained. Special
API functions are supported by the master for listing, adding, and removing slaves. Slave
devices are identified on the master by their names, but the master must be prepared for a
slave’s name to change at any time. qToggle implements three roles that dictate the access
level: the administrator role, which has the absolute power over a device, being able to view
and modify the configuration; the normal role, which has no access the configuration but

Page | 8
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

can read from/write to ports, and the view-only role that can only read the port’s values. To
facilitate automation, qToggle allows adding rules that dictate port values, based on various
conditions. This means that a port can be taught to use an expression based on other ports
and functions in a way that resembles spreadsheet formulas. Expressions can be set at a
device level or at a hub level. Expressions on a device are very fast, but they can only depend
on ports present on the device. When setting an expression at a hub level, the ports of any
device that is known by the hub can be included. This will effectively implement relations
between different devices. If consumers need to be notified about events that take place on
the device, for example port value changes, qToggle offers three notification methods:
listening for events using long HTTP requests (long polling), webhooks, and polling (the least
efficient, but easiest to be implemented). qToggle setups are usually deployed in private
networks, where devices cannot be directly accessed from the Internet. The solutions often
depend on port forwarding, where public IPs are available. If port forwarding is not
wanted/impossible, the devices can be set to open a connection to an external public server
and to wait for API requests. This mechanism is called reverse HTTP and allows making HTTP
requests to a device inside a private network without forwarding any port.

From a developer point of view, qToggle offers add-ons that are an easy and convenient way
of packaging optional functionalities, which are usually tied to a specific device or service.
Add-ons can be published or be kept private, depending on the developer’s needs and
licensing requirements. The entire source code is completely opensource [45], so one can
easily understand how it works, may propose changes or may even join the team. In
addition, we provide documentation on using and further developing qToggle for new
devices or use cases. Regarding the security, qToggle uses a series of best practices that are
often found in nowadays web-based applications. HTTPS is employed for when a client from
the outside (the Internet) talks to the hub. It ensures encryption, authenticity of the hub,
and integrity of the HTTP messages. Plain HTTP is used only locally, inside the premises,
between the hub and its controlled devices. A TLS certificate is used in conjunction with
HTTPS to ensure the security goals mentioned above; Let’s Encrypt is used to generate and
renew the TLS certificates. This process is done automatically on the hub, upon certificate
Page | 9
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

expiry. Remote (administrative) access on the hub is done via SSH. The SSH protocol uses
ECDSA (or similar) private/public key pairs for authentication and encryption. Alternatively,
the administrator password defined on the hub may be used to log in remotely with
username and password. The API defines three roles that dictate the permissions of an API
request: administrator, normal user, and view-only user. API requests use the JSON Web
Token (JWT) defined by RFC 7519 to supply authentication data. A shared secret (called
password) ensures the authenticity of the caller. The secret is hashed with a salt before used
to sign the JWT token to prevent compromising the original password. Reply attacks are
prevented by using the current timestamp as a nonce included in the JWT. Alternatively, we
could have used HTTP Basic Authentication, HTTP Digest Authentication, or a cookie-based
session management with a conventional login form. Basic Authentication is insecure when
transmitted over unencrypted channels, while Digest Authentication is unnecessarily
complicated and requires exchanging multiple messages. The cookie/session-based method
is prone to session stealing attacks and may also be insecure on unencrypted channels. The
embedded Over-the-Air (OTA) mechanism (firmware update) ensures that the hub as well
as its attached devices always run the latest available version, thus allowing us to quickly
bring security patches in case a vulnerability is discovered.

2.2. Configuring the Web Application


qToggleServer provides a user-friendly interface, named frontend, which comes in the form
of a progressive web application (PWA). It is designed to be used on smartphones, tablets,
but also on laptops/desktop machines. Firstly, the application should be installed and, being
a PWA, it should be added to the home screen. After installation, the qToggle app will be
found in the applications list of the device, and it can be uninstalled whenever the user wants
to. When the user logs in for the first time (see Figure 3a), an admin with an empty password
should be used. However, for security reasons, it is highly recommended to set a password
in the Settings page of the app. The dashboard is the section where users will spend most of
the time when using qToggleServer. Here, they can create panels and groups of panels, as
shown in Figure 4. In the panel edit mode, the user can perform various tasks, for example
add, move around, remove, resize, or configure widgets. Widgets usually require selecting
Page | 10
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

one or more ports. Ports values will be displayed and/or changed by the widget upon
interaction. An example is given in Figure 5. The ports section is only accessible to
administrators. In this section, the user may add, remove, and configure ports (see Figure
6). If users have slave devices management enabled in qtoggleserver.conf (by default they
are enabled), the first thing they will have to do is to select the device whose ports will be
edited. The first device in the list represents the hub (the master device) itself. An important
fact is that only administrators can add, remove, and configure slave devices.

Page | 11
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

CHAPTER 3
Real Home Case Study

In the following, the use of qToggle in a real home will be presented. The scenario consists
of a two-floor house with five rooms, two bathrooms, kitchen, pantry, shed, garage, and
garden. In this case, qToggle is used for various purposes, such as:
• Controlling the indoor temperature (thermostats and air conditioning (A/C))
• Controlling the lights (on–off);
• Monitoring the power and the energy;
• Controlling the doors—gates, garage door, or both at the same time (open–close);
• Security—the alarm;
• Garden sprinklers.

3.1. Controlling Temperatures and A/C


The purpose of controlling the indoor temperatures is to maintain thermal comfort and to
save energy cost. In this case, the thermostats system offers the following advantages: the
ability to access and control the indoor temperature anytime and from anywhere using
qToggle app on the mobile phone, as presented in Figure 8a, the ability to monitor and
separately set the temperature in individual rooms (not every room has the (not every room
has the same heating requirements), and, finally, the ability to enable scheduling (lower the
temperature during the day, when nobody is home, or during vacation). In this way, manual
adjustments are eliminated to save time and effort. same heating requirements), and,
finally, the ability to enable scheduling (lower the temperature during the day, when nobody
is home, or during vacation). In this way, manual adjustments are eliminated to save time
and effort.

Page | 12
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

Figure 3.1: Controlling indoor temperatures with qToggle app (a) together with smart
thermostats (b,c).

Page | 13
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

CHAPTER 4
SYSTEM DESIGN

Figure 4.1: Block diagram

1) Smart Home is a very useful project for the people who are not able to do various activities
efficiently when they are at home and need one’s assistant to perform those tasks. M
2) With the Android Application the complication of wiring in case of wired automation is
prevented. With the use of Wi-Fi based Home automation would help a man to switch on/off
wherever he is. The Android application system provides secure access to home. In recent
years, the Home Automation systems have seen rapid changes due to the introduction of
various wireless technologies.
3) The Home Automation industry is growing rapidly, this is fuelled by the need to provide
supporting systems that are made to ease our life. Automation systems are supposed to be
implemented in existing home environments, without any changes in the infrastructure. The
automation is based on android application of and uses Wi-Fi module along with
microcontroller. This book presents the overall design of ‘IOT based Home Automation’,
Page | 14
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

which we are currently developing. 4) The automation recognizes commands given by the
app through the user and transfers it to our microcontroller which detects the command
and proceeds with the switching accordingly. We are using the Arduino microcontroller
module & Wifi module ESP8266 Node MCU to implement our vision. Further we are trying
to implement the same on a more user friendly and bigger scale. The home automation
system is intended to control all lights and electrical appliances in a home or office using
voice commands.

Figure 4.2 : Flow of our model (Flowchart)


Page | 15
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

CHAPTER 5
IMPLEMENTATION

1) Home Automation using Internet Of Things (IOT) refers to the automation wherein it
allows the users to control their devices using the Internet. It requires the user to connect
his/her appliances, which he wishes to be remotely controlled, to the Arduino circuit. It also
requires the user to connect the Arduino to the NodeMCU Wi-Fi module in order to allow
the devices to be controlled from anywhere in the world using the Internet. The Wi-Fi
module is connected to the Firebase real-time database using Database secrets in order to
receive the triggering signals.

2) On the front end, we developed an Android app to pass signals to the Arduino circuit. We
used a real-time database as a backbone of the project to send signals over the Internet. The
Android app is linked to the database using the Firebase API readily available.

Figure 5.1: Circuit diagram


Page | 16
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

Figure 5.2: Test case table

Figure 5.3 : qToggle architecture for the presented case study.

Page | 17
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

CHAPTER 6
CONCLUSION

In conclusion, the Internet of Things (IoT) has revolutionized the concept of home
automation, leading to the development of smart homes. These homes leverage IoT
technology to connect and control various devices and utilities remotely via the Internet.
The integration of sensors, actuators, and wireless sensor networks enables advanced
functionalities and automation in homes.The choice of wireless technology for home
automation systems has been a topic of exploration, with various options available such as
Bluetooth, GSM, ZigBee, and Wi-Fi. While each technology has its advantages and
disadvantages, Wi-Fi has gained popularity due to its affordability, simplicity, and
widespread availability. Wi-Fi-enabled devices are cost-effective, easy to find, and do not
require additional hardware investments. However, Wi-Fi does have limitations in terms of
energy consumption, network stability, and the number of connected devices.The qToggle
system architecture, discussed in this chapter, presents a practical solution for home
automation based on IoT. It utilizes Raspberry Pi boards, ESP8266 Wi-Fi modules, and smart
devices to create a centralized hub that allows remote control and management of
connected devices. The qToggle API provides an intuitive interface for controlling hardware
ports and supports various functionalities, including device management, port
management, notifications, and reverse API calls. The qToggle ecosystem includes
qToggleServer, qToggleOS, espQToggle, and add-ons, providing a comprehensive
framework for home automation.
Security is a crucial aspect of home automation systems, and qToggle incorporates best
practices to ensure data encryption, authenticity, and integrity. The use of HTTPS, TLS
certificates, and SSH for remote access adds a layer of protection to the system.

Page | 18
DEPARTMEN OF MCA 2022-23
IoT Enabled Smart Home Automation System 1NH21MC079

CHAPTER 7
REFERENCES

1] Arpita Yekhande, Prof. Kapil Misal, “HOME AUTOMATION SYSTEM USING


RASPBERRY PI. “ presented at International Research Journal of Engineering
and Technology (IRJET) ,10 | Oct -2017).
[2] Abhijit Shejal, Amit Pethkar, Akash Zende, Pratyusha Awate,
Prof.Sudhir.G.Mane, “DESIGNING OF SMART SWITCH FOR HOME
AUTOMATION.” Presented at International Research Journal of Engineering
and Technology (IRJET) 05 | May 2019.
[3] Sudha Kousalya, G Reddi, Priya Vasanthi, B Venkatesh, IOT Based Smart
Security and Smart Home Automation presented at International Journal of
Engineering Research & Technology 04, April-2018
[4] K Eswari, DeviK Shravani, M Kalyani, Mr. Abbas Hussain, Mrs. N Gayathri
“Real-Time Implementation of Light and Fan Automation using Arduino”
presented at International Journal for Research in Applied Science &
Engineering Technology (IJRASET), 06, June-2020
[5] Bouzid Mohamed Amine , Chaib Fatima Zohra , Hamani Ilyes , Aid Lahcen,
Allaoui Tayeb, “SMART HOME AUTOMATION SYSTEM.” Presented at
International Journal of Robotics and Automation (IJRA) ,4 | Dec. 2018
[6] Ayush Gajjar, Deepak Mishra, Shubham Ingale, Aniket Kore, “SMART HOME
SYSTEM.” Presented at International Research Journal of Engineering and
Technology (IRJET) , 01 | Jan 2019

Page | 19
DEPARTMEN OF MCA 2022-23

You might also like