2 Python Lab Manual
2 Python Lab Manual
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
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.
CHAPTER 2
Materials and Methods
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.
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.
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.
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
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.
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.
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
Page | 19
DEPARTMEN OF MCA 2022-23