Smart Home Control Using MQTT Protocol.
Smart Home Control Using MQTT Protocol.
Theme
• BOUMERZAK Kheira
• BERRICHI Akram
0
Acknowledgment
Our deep and sincere gratitude, appreciation and respect to one of the best professors we
encountered during our academic years, to our wonderful supervisor
Mr. Ziani-Cherif Salim,
Thank you for your valuable support and guidance.
We would like to extend our sincere gratitude and appreciation as well, to the jury for
accepting to read, review and evaluate this work.
We would also like to give our thanks to all the employees of our university studies at the
computer science department.
1
Dedication
First of all, I thank ALLAH THE ALMIGHTY WHO gave me the courage, strength
and ability to accomplish this work.
Then, I dedicate with all my heart this modest work:
To my dear mother, the sweetest person I ever know, thank you so much for raising
me better, you are the source of my life and happiness.
To the dearest one in my heart, the one who always makes me feel happy and worth it,
my best friend and everything in my life my dear father.
To the angelic person who represent my second family, who is like a father
To me Bz. Mohammed I appreciate your support and love, I will always be grateful,
Thank you
To my soulmates, the source of my strength in life, my incredible sisters, whom I love
so much: Meriam, Amal, Ikram, Chaymae, Yousra and to my one and only, my great
beloved brother Mohammed, am so grateful for everything you did for me so far.
In the memory of my dear and wonderful grandfather, for the great love he always
gave, you were such an angel who carved a special place in my heart that will forever
remain the same.
Lastely, to my dear friend Chaouki, the wonderful person you are, I deeply thank you
for the big support, so many appreciations,
I love you all beautiful people.
Kheira BOUMERZAK
2
Dedication
First of all, I thank ALLAH THE ALMIGHTY WHO gave me the courage, strength
and ability to accomplish this work
In the memory of my grandparents from both my mom and my dad side, uncle Sassi,
uncle Ali, uncle Mouloud and cousin Sofiane
And very special gratitude is due to all those extraordinary people who have stood
by me in very hard moments.
Akram BERRICHI
3
Abstract
Abstract: We all know that technology keeps advancing within the years to provide a comfortable
environment in order for humans to live a better life. Speaking of which, the one among them that
caught our attention was IoT (Internet of Things). Thinking of that, we developed a real interest in
how Things will work. Therefore, we’ve chosen “Smart Home Control using Mqtt Protocol”, to be
our main project. Hence, To explore how things are connected with each other, from using MQTT
protocol, to what software and what equipment were used in order to make things alive, we will
explain it all since the main goal of this project is to provide security with innovation at home.
Keywords: Smart Home, Internet of Things, Home Appliances, Raspberry Pi, Nod-Red, Esp8266,
Arduino, MQTT, Automation
Résumé : Nous savons tous que la technologie continue de progresser au fil des ans pour fournir un
environnement confortable permettant aux humains de vivre une vie meilleure. En parlant de cela,
celui d’entre eux qui a attiré notre attention était l’IoT (Internet des objets). En pensant à cela, nous
avons développé un réel intérêt pour la façon dont les choses fonctionnent. Par conséquent, nous
avons choisi “Domotique intelligente basée sur le Protocol Mqtt” comme projet principal. Par suite,
pour explorer comment les choses sont connectées les unes aux autres, de l’utilisation du protocole
MQTT, à quels logiciels et quels équipements ont été utilisés pour rendre les choses vivantes, nous
expliquerons tout car l’objectif principal de ce projet est d’assurer la sécurité avec l’innovation à la
maison.
Mots clés : Maison intelligente, Internet des objets, Electroménager, Raspberry Pi, Nod-Red,
Esp8266, Arduino, MQTT
نعلم جميعًا أن التكنولوجيا تستمر في التقدم مع مرور السنوات بهدف توفير بيئة مريحة من أجل أن يعيش البشر حياة: ملخص
طورنا اهتما ًما حقيقيًا عن كيفية عمل، كان إنترنت األشياء و عند التفكير في ذلك، الذي لفت انتباهنا، بالحديث عن ذلك.أفضل
مع استكشاف كيفية. ليكون مشروعنا الرئيسي، "Mqtt اخترنا أتمام "المنزل الذكي المبني على أساس البروتوكول، لذلك.األشياء
، إلى البرامج و المعدات المستخدمة من أجل جعل األشياء حية، Mqtt من استخدام بروتوكول، ارتباط األشياء ببعضها البعض
.سنشرح كل ذلك بدقة اذ ان الهدف الرئيسي لهذا المشروع هو توفير األمن و الراحة في بيت مفعم باألجهزة الذكية
اردوينو, األجهزة المنزلية, إنترنت األشياء, المنزل الذكي:الكلمات المفتاحية
4
Contents table
Contents Table
List of Figures................................................................................................................................... 8
List of tables ...................................................................................................................................... 8
General Introduction ..................................................................................................................... 9
Publish/Subscribe: ................................................................................................... 36
Broker ...................................................................................................................... 36
Topics and Subscriptions:........................................................................................ 37
Quality of Service Levels: ........................................................................................ 37
Retained Messages: ................................................................................................. 38
Wills ......................................................................................................................... 38
Keep Alive & Client Take-Over ............................................................................... 39
Persistent Session and Queuing Messages .............................................................. 39
6
Contents table
7
Figures-Tables Lists
List of Figures
Figure I.1 IoT Architecture [20] ........................................................................................................................... 12
Figure I.2 Smart Home Automated Network example [21] ................................................................................. 13
Figure I.3 Architecture of smart Home interaction between indoors & outdoors [2]........................................... 15
Figure I.4 Example of smart wiring [45] .............................................................................................................. 16
Figure I.5 Smart homes in market [47]................................................................................................................. 19
Figure II.1 Different kinds of Area Networks [2]................................................................................................. 23
Figure II.2 Effective Messaging Protocols in different layers [6] ........................................................................ 24
Figure II.3 The 7 layers of the Osi Model [44] .................................................................................................... 25
Figure II.4 Message delivery in MQTT [13] ........................................................................................................ 28
Figure II.5 Temperature publish/subscribe model [17] ........................................................................................ 28
Figure II.6 Message delivery in HTTP [48] ......................................................................................................... 29
Figure II.7 Data exchange workflow in CoAP [48] ............................................................................................. 30
Figure II.8 Message delivery in AMQP [48] ........................................................................................................ 31
Figure II.10 Message Size vs Message Overhead [6]........................................................................................... 32
Figure II.9 Power Consumption vs Resource Requirement [6] ............................................................................ 32
Figure II.11 Reliability/QoS vs. Interoperability [6] ............................................................................................ 33
Figure II.12 Bandwidth vs. Latency [6] ............................................................................................................... 33
Figure II.14 Security vs. Provisioning [6] ............................................................................................................ 34
Figure II.13 M2M/IoT Usage vs. Standardization [6] .......................................................................................... 34
Figure II.15 Lamp controlling example [17] ........................................................................................................ 36
Figure II.16 Message delivery at different QoS levels [46] ................................................................................. 38
Figure II.17 Message Transmission in MQTT[10]............................................................................................... 39
Figure II.18 Typical message flow in MQTT [46] ............................................................................................... 40
Figure III.1 Raspberry Pi to ESP8266 installation process .................................................................................. 54
Figure III.2 Controlling light by sending ‘on’ command & reading data from dht11 sensor [17] ....................... 71
Figure IV.1 Project general architecture............................................................................................................... 73
Figure IIV.2 Master Slave wiring through i2c bus lines (sda & scl) ................................................................... 75
Figure IV.3 Slave recognition by master through the 7 bit address ..................................................................... 76
Figure IV.4 Master slave data transfer concept .................................................................................................... 77
Figure IV.5 Master & Slave Wiring ..................................................................................................................... 79
Figure IV.6 Flowchart: Project Research ............................................................................................................. 80
Figure IV.7 Flowchart: Raspberry Project ........................................................................................................... 80
Figure IV.8 Flowchart: ESP8266 Project ............................................................................................................. 81
Figure IV.9 Flowchart: Sensors Project ............................................................................................................... 82
Figure IV.10 Schematic: Security System Using fire, gas, motion, humidity & temperature Sensors ................ 83
Figure IV.11 Flowchart: RFID Door Lock Project .............................................................................................. 85
Figure IV.12 Schematic: Door lock system.......................................................................................................... 86
Figure IV.13 Flowchart Garage Project ............................................................................................................... 88
Figure IV.14 Schematic: Garage Project .............................................................................................................. 89
Figure IV.15 Flowchart: Master-Slave Concept................................................................................................... 90
List of tables
TABLE II.1Comparative Analysis of Messaging Protocols for IoT Systems: MQTT, CoAP, AMQP and HTTP
[6] ......................................................................................................................................................................... 32
TABLE II.2 MQTT Message Format (2Bytes Header) [8] .................................................................................. 36
TABLE II.3 The different QoS work Concept ..................................................................................................... 37
TABLE II.4 When to use Which QoS .................................................................................................................. 38
TABLE II.5 Brokers with features and limitations .............................................................................................. 42
8
General Introduction
General Introduction
Our future lies in our hands, so why not make it better and more appropriate?
In this computer era, everyone has a very busy life. Therefore, one should consider living in a comfort
zone rather than being stressed. So, why not benefit from technological advancements?
Home Automation is the leading approach to this goal, which has become and will continue to
become a trend in the upcoming century. It's a term used to describe how all of our domestic amenities
and appliances operate together and how we can control them with ease from our smartphones, tablets,
or computers having Internet connectivity; because they are the means from which one can use the
Internet at any time and from anywhere. As a result, it opens a door that connects us to various home
appliances that we use on a daily basis, allowing anyone to control their own home.
Therefore, we decided to turn this intriguing idea concept into a real-world project, in order to
experience how it really works.
For a better understanding of our project and its content, here is a brief description of the chapters.
In the first chapter, we will present a general outline of the Internet of Things, Smart Homes,
their architecture, the advantages of employing them, and problems they solve. In addition, their state
inside & outside of Algeria.
In the second chapter, we will discuss the various protocols that can be used to manage and
monitor the home, as well as a comparison of why some protocols are better than others. Then go over
MQTT in depth, as it's the preferred protocol we've chosen as our main protocol and one that plays a
major role in appliance communication. We'll go through how it's built and why it's the ideal option
for use in.
In the third chapter, we shed the light on the different tools of hardware and software that were
used, how they mash up together, their functionalities and features. Thus, the connection between them.
In the last chapter, we will discuss how we came to achieve our aim of building a smart home
that we can control from afar, as well as how we programmed it.
9
Chapter I:……………………………………….…………………SMART HOMES
10
Chapter I:……………………………………….…………………SMART HOMES
SMART HOMES
Introduction
In recent decades, home automation systems have grown in popularity as they improve
comfort and quality of life. With the integration of IoT (Internet of Things) services by embedding
intelligence into sensors and actuators, then networking the smart things to facilitate interaction
between them. Doing so will result in increasing computational power, storage space and improving
data exchange efficiency. Therefore, it becomes easier to manage multiple operations/objects since
they are all interconnected. In fact, IoT household gadgets help save money, energy, not to mention
time as well.
Such systems depend on the collection of data. The data is then used for monitoring,
controlling, processing & transferring information to other devices via the internet. This allows
specific actions to be automatically activated whenever certain situations arise. In a simple
example, consider a smart kettle. The kettle can be programmed to automatically turn off once it
reaches a specific temperature. Then send a notification to the user’s smartphone.
Now apply the same concept to the entire home and all the devices present. That is a smart
home powered by IoT. Instead of manually going up to the device and taking action, those actions
can be taken at the press of a button. These days, most smart IoT home automation devices allow
you to control them via an app or even via voice commands.
Now imagine if you did not even need to undertake such actions. In other words, the smart
home will know when to take certain actions and automatically take them. This is what our
project will try to convey.
Internet of Things
The IoT can be used to improve every aspect of life, bringing into existence many scenarios,
such as smart homes, self-driving cars, smart cities, smart agriculture and much more.
What options do home sensors and gadgets have to communicate with one another? What's more,
how do you make a house smart? Don't worry. That is exactly what our initiative is about.
Definition
The Internet of Things, or IoT for short, was initially mentioned in 1999, in a speech given
by the British engineer Kevin ASHTON. It was used to describe a system that connects physical
objects to the Internet. They are also data-creating and data-transmitting systems that provide value
to their users through various services (data analytics, machine learning…etc.) [19].
11
Chapter I:……………………………………….…………………SMART HOMES
It refers to the interconnection of devices over internet, which allows them to send and
receive data without human intervention. Smart homes are an important aspect of the Internet of
Things, as they allow internet-connected appliances and devices to be managed automatically and
frequently via a smartphone.
Gateways for data filtering, preprocessing, and moving it to the cloud and vice versa,
receiving commands from the cloud.
Cloud gateways to ensure data transition between field gateways and central IoT servers.
Streaming data processors to distribute the data coming from sensors among relevant IoT
solution’s components.
12
Chapter I:……………………………………….…………………SMART HOMES
Data Lake for storing all the data of defined and undefined value.
User applications to enable users to monitor and control their connected things.
When developing an IoT architecture of a particular solution, it’s also important to focus on two
important elements:
Consistency: paying enough attention to every element of the IoT architecture and making
them work together.
Smart Homes
Definition
Smart Homes, also known as automated homes, intelligent buildings, integrated home systems,
or domotics, are a recent design trend that uses internet- connected gadgets to provide remote
monitoring and management of appliances and systems such as lighting and heating[21].
However, smart home technology has progressed to the point where almost any electrical
component in the house can now be integrated into this intelligent automation system. Furthermore,
rather than simply turning on and off equipment, smart home technology can monitor the indoor
environment and the activities that occur when the house is occupied. As a result of these
technological advancements, a smart home can now monitor its occupants' actions as well as operate
gadgets independently in predetermined patterns as the user desires, simply by using their smartphone
as a controller, as illustrated in figure2.
13
Chapter I:……………………………………….…………………SMART HOMES
b) Present: fast forward to today, having a virtual assistant such as Alexa or Google Home is
the standard for ordinary families. These devices allow you to set timers, create lists, ask
questions, and play music by simply making requests. Home security has also never been
more evolved than it is right now. Video doorbells allow you to check who is at the front of
your door on your phone. You can even control your door locks, garage doors, and security
cameras all from your phone or tablet. Everything from smart faucets with motion sensors that
help conserve water to digital refrigerators featuring touch-screens and voice command helps
make the home an ever- evolving hub of connectivity. The next step in home technology is
connectivity, also known as home automation. Home automation consists of connecting all
your devices to the internet. Imagine being able to control everything in your home with just
one touch. With home automation, these scenarios are not unrealistic. On the flip side,
remember when you used to have to manually turn the channel on the television or go to the
library when you were writing a research paper – if you’re of a certain age, of course. It
wasn’t very long ago that you had to run towards the radio to press the “play” and “record”
button at the same time to record your favorite song on a cassette player. With today’s
technology, those instances seem as if they were hundreds of years ago, not twenty [4].
c) Future: while it may seem like we’ve already reached the peak of possibilities in home
technology and automation, there is still plenty to look forward to. As devices in the home
continue to advance, users can expect significant money and energy savings. Individuals can
also expect technology to anticipate their needs and wants before being notified of them. The
development of more smart appliances and security can also be anticipated. From lights that
turn on and off by themselves without being prompted to doors that open with face
recognition, there are still lots to look forward to in this space. Kitchen gadgets are expected
to reach new heights as well. Consumers are used to having only a few options when it comes
to home technology, but as more companies explore the market, there will be more variety
that may also be more affordable. The possibilities are seemingly endless regarding
technology in the home. As it continues to evolve and gain popularity, users can expect to
save time and money. However, a world where everything is connected and shared with big
companies seems like something to be wary of to a certain degree. In the end, the consumer
will have to decide what they are comfortable with [4].
Architecture of Smart Homes
Residents can communicate with smart devices; and in order to send or receive commands,
all of those things will be connected to the home network.
14
Chapter I:……………………………………….…………………SMART HOMES
Home networking enables the home to be fully connected and controlled both internally and
externally. External connectivity is provided via Ethernet or the Internet network through the home
gateway.
Figure I.3 Architecture of smart Home interaction between indoors & outdoors [2]
We can see in Figure 3, that the appliances and user interfaces are all located inside the house,
which represents: offline mode "indoors" which is completely secure, especially if homeowners are
concerned about cyber security attacks,safe because no internet connectivity is used, so they can't
access to the home system, but the thing is, the appliances will work separately which means each
task is performed independently, for example: you can scan the tag to open your door but can't turn
on the fan in this case, because it is controlled remotely and in this case we will need to use internet
in order to monitor all of the home from a distance using the control panel to perform tasks without
requiring human intervention which represents outdoors where we remotely control the devices
through a mobile, pc, etc...
This connection between indoors and outdoors via the internet is what makes the home smart.
Wireless System
Wi-Fi is uniquely placed to support IoT applications that require internet connectivity in
order to work. Some IoT applications, such as vehicular services, or video-based apps like
connected security cameras, will need the bandwidth of the wireless broadband network,
implemented to enable other requirements [24] [25].
15
Chapter I:……………………………………….…………………SMART HOMES
Security & safety: Improving security and safety are the most critical elements of household
electronics. Therefore, many basic security options, such as Wi- Fi-enabled cameras, smart sensors,
like the ones which can detect water leaks, humidity levels, carbon monoxide, motion-heat…etc.
might be a life saver, all thanks to their ability to communicate with us, by notifying us in our
smartphones, wherever we are, to prevent any possible danger.
Energy Efficiency & saving: This category tries to reduce home energy usage by scheduling
and adjusting the working time of home devices based on energy availability [3]
Convenience: A smart home's residents should have the finest possible life experience. Where
the home environment adapts to what owners are doing or wishes, with just a touch of a button.
One of the key advantages of home automation utilizing IoT is that this sort of service seeks to
lessen the difficult household chores while also ensuring healthcare, childcare, and elder care [3].
Well there are several nagging tasks that we can pass to the house to do instead. However,
here we are going to mention couple ones as follow [5]:
3- Am I safe in my house?
With all kinds of sensors that we can use for all the smart houses out there, you can ensure
your safety while being indoors no matter what kind of danger there is. Gas sensors to detect
gas, fire sensors to detect fire, and a way to monitor all of that data and more even while being
outdoors to make sure your house is perfectly safe.
With prove smart home appliance we can create schedule for automation each with a specific
task, wouldn’t that be useful, to be able to interact and control our homes anywhere, anytime
we wish through our smartphone. Therefore, making use of smart technology will make our life
so much easier.
Home automation is almost impossible to find or very little used in Algerian housing.
Because it is not seen as a need or a necessity. In a country where a building with an elevator is
seen as a luxury/prestige as well as apartments delivered in 2001 have not yet been completed
and where electricity and water failures persist.
In Algeria, the electronic remote control protocol is little used (automatic light, watering,
opening and closing doors, garages, windows automatically), despite the fact that the electrical
energy meets the local needs in the country.
Despite many aspects an intelligent home can offer and perform better than a human can.
We choosed to talk about two most important ones in our opinion, which are: safety and energy
saving:
1. The economic boom from the 2000s led to the creation of large residences (pavilions, villas,
buildings and duplexes) sumptuous and well appointed, thus, the home automation market
was revived. But if Home automation were to be implemented, economy would be a
significant development and beneficial to people, here are two main advantages:
Almost no waste, therefore so much Energy saved. And this is one of the most
compelling reasons to save one budget.
Controlling light consumption saves money. Automation of devices, such as light
systems, opening or closing blinds, kitchen appliances… prevents loss and reduces
annual electricity costs by almost 20-50%. Installing such a system increases the
value of the home if it is sold.
2. When it comes to security, it means the residents and their belongings’ safety. It is among
the main bases of home automation to consider security a top priority in the majority of
homes, especially in these times when innovation abounds in anti-intrusion systems, such
as sensors, alarm detectors and surveillance videos. Once these security systems are
installed whether a homeowner is within or outside their home they can feel very safe
knowing they will be notified of anything that is happening in and out of where they live
(for example setting alarms on while sleeping, if detecting any danger the alarm will be set
on, make a noise in order for the homeowner to wake up), which is a detail that most
Algerian homes do not have but need.
Though, in Algeria Home automation has long been unfavorable due to non-fertile
environment: less use of online payment, remote monitoring is not easy, Digital camera
installation is very complicated and time consuming. Concerning potentially dangerous domestic
incidents such as water or gas leaks, fires, and floods, as well as other issues that are waiting to
be resolved. We believe that these are more than sufficient reasons to allow us to develop this
safe implementation in our homes in order to increase safety
As a result, we believe that this project is critical enough to invest time and effort into. In
order to implement a bright future and, hopefully, a better standard of living in the coming years.
On the other hand, Smart Homes in global scale, this info graphic (figure5) below shows the
projected total global number of connected smart home monitoring/automation units in service
and the total revenues for smart home automation/monitoring technologies in 2024, as forecast
by Juniper Research:
18
Chapter I:……………………………………….…………………SMART HOMES
19
Chapter I:……………………………………….…………………SMART HOMES
Conclusion
The smart home is designed in order to provide comfort and safety for the family inside the home
and to provide a decent living for them. It also contains features that facilitate the elderly and patients
to carry out those normal daily activities that they are unable to do in the normal state. These services
are represented in the ability to operate home appliances from afar, monitor the house and make sure
that the doors are closed and the alarm system is activated without the need to return and do this
manually and provide a safe and comfortable atmosphere for the children. And other tasks that the
smart home performs. And as we saw in this chapter previously. What distinguishes home automation
is the control system, which makes it easy to control, monitor and connect devices to each other, and
those interaction are studied in next chapters.
Home automation improves people's lives by automating a variety of tasks, where the sky's the
limit when it comes to what you can make a home do.
Knowing the state of smart homes in Algeria specially, our project aims to demonstrate that such a
project is achievable and very doable through solving the basic problems that we can have and finding
more efficient ways to make life easier through its implementation.
Out of many proposed systems, we’ve choosed six functions that we thought were the most interesting
and focused on implementing them. They can be summed up as follows:
Fire & gas detectors that inform us through phone notifications about the fire & gas levels of the
house and whether we should worry about it or not.
Displaying house Temperature & humidity status.
Home garage opening & closing through a phone tap, plus automatic evacuation through a fan in
case of gas leak.
Door lock security system that allows you to have an extra layer of security & make sure you know
who is in and out of the house.
Controlling lights-lighting across the house from wherever you are, plus lighting based on
movement without manual interfering.
Security camera that detects movement and warns in case something fishy is going on.
How we achieved these objectives? That is what we will discover in the next chapters.
20
Chapter II:………………………………………….……IoT Communication Protocols
21
Chapter II:………………………………………….……IoT Communication Protocols
Introduction
In the communication domain for smart homes, we find two challenging objectives. The first one
is how to make possible the communication of the equipment inside the house. The second one is to
connect the smart house to the outside Internet world.
However, the most important part relies on the selection of the relevant connection structure
including the effective messaging protocol. Therefore, before selecting the appropriate messaging
protocol for IoT systems, the pre- requisite is to get a better understanding of a target IoT system and
its message/data sharing requirements.
Unlike the Web, which uses a single standard messaging protocol (HTTP/HTTPS), IoT cannot rely
on a single protocol for all its needs. What we mean by that is in the IoT structure we can use multiple
protocols, where each one does a specific task, compared to a single protocol that is only designed for
a sole purpose, back to Http examples that were implemented in the goal of accessing web pages or
websites. Consequently, many messaging protocols are available to choose for various types of
requirements of the IoT system. Some of them have been designed to address applications requiring
fast and reliable business transactions such as AMQP (Advanced Message Queuing Protocol) and JMS
(Jakarta Messaging). A numerous have been designed to address applications requiring data collection
in constrained networks such as MQTT and CoAP. Many of them have been designed to address
applications requiring instant messaging (IM) and online presence detection such as XMPP and SIP.
A few of them have been designed to address web applications requiring communicating over the
Internet such as Restful client/server protocols HTTP and CoAP [6].
This clearly shows that the future of the IoT lies in several messaging protocols, but also it depends
mostly on the case studied or used, for example in our case we focused mostly on one protocol, which
is responsible for appliances communication. Consequently, it is necessary to investigate the pros and
cons of the widely accepted and emerging messaging protocols for IoT systems to determine their best-
fit scenarios.
22
Chapter II:………………………………………….……IoT Communication Protocols
We will focus on indoor solutions to transmit data. For the communication in a smart home, we will
focus on PANs because they are the most adapted in terms of distance and flow. We can find residential
networking standards and initiatives that we are going to develop.
23
Chapter II:………………………………………….……IoT Communication Protocols
Figure 2 above, shows widely used messaging protocols and its layer position in IOT networks, where
the:
Application layer (1st Line): is the layer that provides protocols that allow user to send and
receive Information to users, a few example of protocols are the: Http, Mqtt, Amqp, Coap, and
others.
Transport Layer (2nd Line): manages the delivery and error checking of data packets. It
regulates the size, sequencing, and transfer data between systems and hosts. Takes data
transferred in the application layer and breaks it into segments on the transmitting host. It is
responsible for reassembling on the receiving host, turning it back into data that can be used by
the application layer. The transport layer san data at a rate that matches the connection speed of
the receiving device, an error control, checking if data was received incorrectly an if not
requesting it again
Network Layer (3rd Line): this layer is responsible for routing the data via the best path where
it receives frames from data link layer, then deliver them to their intended destination among
base on the addresses obtained inside the frame, it finds the destination, one of the most common
examples of the network layer is IP (internet protocol). At this layer routers are crucial
components used to quite literally route information where it needs to go between networks.
Data Link Layer (4th Line): this layer is responsible for converting data streams to signals bit
by bit and sending that over the underlying hardware. At the receiving host, Data link layer picks
up data from hardware which are in the form of electrical signals, assembles them in a
recognizable format, and hands over to the upper layer. Example of data link protocols are
Ethernet, WiFi, ZigBee, …etc
We simply defined the layers in the Osi model (figure II.2) so that we could compare them to
the IoT layers and see the difference. So, from the image below (II.3), we can see that there are four
layers present, which can be divided as follows:
24
Chapter II:………………………………………….……IoT Communication Protocols
Sensing Layer: sensors, actuators, devices are present in this Sensing layer. These
Sensors or Actuators accepts data (physical/environmental parameters), processes
data and emits data over network.
Network Layer: internet/Network gateways, Data Acquisition System (DAS) are
present in this layer. DAS performs data aggregation and conversion function
(Collecting data and aggregating data then converting analog data of sensors to digital
data etc). Advanced gateways which mainly opens up connection between Sensor
networks and Internet also performs many basic gateway functionalities like malware
protection, and filtering also sometimes decision making based on inputted data and
data management services, etc.
Data processing Layer: this is processing unit of IoT ecosystem. Here data is
analyzed and pre-processed before sending it to data center from where data is
accessed by software applications often termed as business applications where data
is monitored and managed and further actions are also prepared. So here Edge IT or
edge analytics comes into picture.
Application Layer: this is last layer of 4 stages of IoT architecture. Data centers or
cloud is management stage of data where data is managed and is used by end-user
applications like agriculture, health care, aerospace, farming, defense, etc.
25
Chapter II:………………………………………….……IoT Communication Protocols
Bluetooth
Bluetooth is a standard IoT protocol used for wireless data transmission. This communication
protocol is secure and perfect for short-range, low- power, low- cost, and wireless transmission
between electronic devices. Also, BLE (Bluetooth LowEnergy) is a low-energy version of Bluetooth
protocol that reduces the power consumption and plays an important role in connecting IoT devices.
Bluetooth protocol is mostly used in smart wearables, smartphones, and other mobile devices, where
small fragments of data can be exchanged without high power and memory. [26]
Z-wave
The Z-Wave is a relatively new wireless home automation protocol. It’s a radio frequency (RF)
based communications technology, designed particularly for control, monitoring and status reading
of household applications. It supports full mesh networks, enabling numerous Z-Wave devices to
communicate with each other simultaneously.
Z-Wave allows for secure and lower consuming communication between approve Z-wave
26
Chapter II:………………………………………….……IoT Communication Protocols
devices. Due to its interoperability, Z-wave encompasses a broad ecosystem of intelligent products
that work together between brands and models. With the advanced technology of Z-Wave, there is
no interference from Wi-Fi, ZigBee, or other 2.4GHz wireless technologies in a similar ban [26].
ZigBee
ZigBee is an IoT protocol that allows smart objects to work together. It is commonly used in home
automation. More famous for industrial settings, ZigBee is used with apps that support low-rate data
transfer between short distances. Street lighting and electric meters in urban areas, which provides
low power consumption, the ZigBee communication protocol is also used in security systems and in
smart homes [26].
Radiofrequency
This is the frequency band used for communications transmission and distribution. We can control
home appliances using a pair of RF modules (transmitter and receiver). It is one of the wireless waves
with a form of electromagnetic radiation with frequencies ranging from 3 kHz to 300 GHz. ZigBee
is a more powerful and longer-range RF device [27].
Messaging Protocols
IoT data protocols are used to connect low power IoT devices. These protocols provide point-
to-point communication with the hardware at the user side. Connectivity in IoT data protocols is
through a wireless, wired or a cellular network.
Messaging protocols can be used in the application layer of the OSI model with several
communication protocols. Some of the messaging protocols are [7]:
27
Chapter II:………………………………………….……IoT Communication Protocols
In figure 4, we see the sending and receiving process is a publish/subscribe model, the figure
here represents the case of one publisher and one receiver, but we can have multiple publisher with
multiple subscribers, it depends on the situation used.
The publisher plays the role of the sender (e.g. temperature sensing device), it publishes the
temperature data “payload” under its topic (e.g. Temp). The Broker handles that topic with its payload
and delivers it immediately to the devices that are already subscribed to the same topic (e.g. devices
that need the temperature data to handle other commands must be subscribed to “Temp” topic before
data delivery process) when it is received.
Here’s an Overview of Mqtt working, that we will discuss later in details. For example, let’s
say we have a setup where a humidity sensor needs to send its readings to the broker, and on the other
end, a computer and a mobile device need to receive this humidity value. In order to get the readings
across to the receiving devices, the MQTT publish/subscribe data flow process goes through the
following steps:
- Firstly, the humidity sensor defines the topic it wants to publish on, in this case, “Temperature”.
Then, it publishes the message “Temperature value”.
As stated earlier, the role of the broker here is to take the message “Temperature value” and
deliver it to the receiving computer and mobile device.
Sender client/ server / receiver client: generally explain the actions of each. HTTP server
generally serves only the requested HTTP methods, therefore, we consider a message delivery in
HTTP when a client requests to update data in a specific URL and another client requests to read data
from the same URL.
CoAP messaging protocol is based on Request/Response abstraction; generally, the servers are
the devices that have sensors or control units and the clients are the devices that apply actions
depending on the response results from the servers.
Advanced Message Queuing Protocol (AMQP)
AMQP is a lightweight M2M protocol, which was developed by John O’Hara at JPMorgan
Chase in London, UK in 2003. It is a corporate messaging protocol designed for reliability, security,
provisioning and interoperability. AMQP supports both request/response and publish/subscribe
architecture. It offers a wide range of features related to messaging such as reliable queuing, topic-
based publish-and-subscribe messaging, flexible routing and transactions.
AMQP communication system requires that either the publisher or consumer creates an
“exchange” with a given name and then broadcasts that name. Publishers and consumers use the name
of this exchange to discover each other. Subsequently, a consumer creates a “queue” and attaches it
to the exchange at the same time. Messages received by the exchange have to be matched to the queue
via a process called “binding”.
AMQP exchanges messages in various ways: directly, in fan out form, by topic, or based on
headers. AMQP normally requires a fixed header of 8-bytes with small message payloads up to
maximum size dependent on the broker or the programming technology. AMQP uses TCP as a default
transport protocol and TLS/SSL and SASL for security. Thus, the communication between client and
broker is connection-oriented.
Reliability is one of the core features of AMQP, and it offers two preliminary levels of Quality
of Service (QoS) for delivery of messages: Unsettle Format (not reliable) and Settle Format (reliable).
30
Chapter II:………………………………………….……IoT Communication Protocols
AMQP protocol is mainly used in the banking industry. Whenever a message is sent by a
server, the protocol tracks the message until each message is delivered to the intended
users/destinations without failure.
Now that we got to know a little bit about each messaging protocol. Find below a table and a few
charts that compare these protocols on many aspects:
31
Chapter II:………………………………………….……IoT Communication Protocols
6. Semantics/ Connect, Get, Post, Put, Consume, Get, Post, Head,
Methods Disconnect, Delete Deliver, Publish, Put, Patch,
Publish, Get, Select, Ack, Options, Connect,
Subscribe, Delete, Nack, Delete
Unsubscribe, Recover, Reject,
Close Open, Close
7. Quality of QoS 0 - At most Confirmable Settle Format Limited (via
Service (QoS)/ once (Fire-and- Message (similar to (similar to At Transport
Reliability Forget), QoS 1 - At most once) or most once) or Protocol - TCP)
At least once, QoS Non-confirmable Unsettle Format
2 - Exactly once Message (similar to (similar to At
At least once) least once)
8. Standards OASIS, Eclipse IETF, Eclipse OASIS, ISO/IEC IETF and W3C
Foundations Foundation
9. Transport TCP (MQTT- UDP, SCTP TCP, SCTP TCP
Protocol SN can use UDP)
TABLE II.1Comparative Analysis of Messaging Protocols for IoT Systems: MQTT, CoAP, AMQP and HTTP
[6]
In the following graphs, we will look at a comparison of which points each protocol good at. First,
we will start with message size and power consumption in figure 9 and 10:
Figure II.7 Message Size vs Message Overhead Figure II.8 Power Consumption vs Resource Requirement
32
Chapter II:………………………………………….……IoT Communication Protocols
Then, see the diffrence when it comes to bandwidth and reliability in figure 11 and 12:
33
Chapter II:………………………………………….……IoT Communication Protocols
Finally, comparing security aspects (though security is a vast area to dig more details in, this
graph only shows more likely an overview). In addition comparing which protocol is most suited in
machine to machine environment:
-Ideal for IoT -CoAP has been - has been employed in -HTTP is a global web
-Hosted by OASIS open swiftly gaining projects such as standard but mostly not
standards consortium and momentum and Oceanography’s suitable and used in the
Eclipse Foundation supported by many monitoring of the Mid- IoT industry.
-Used and supported by large companies such Atlantic Ridge, the usage of HTTP in
the large number of as Cisco (Field Area NASA’s the IoT is limited due to
organisations such as Network), Contiki, Nebula Cloud its heavyweight size and
IBM, Facebook, Erika and IoTivity. Computing and India's slow performance.
Eurotech, Cisco, Red -CoAP is an IETF Aadhar Project. -HTTP is an IETF and
Hat, M2Mi, Amazon standard W3C standard and
Web Services (AWS), already established as a
InduSoft and Fiorano. global standard for the
Web.
If you are not sure about which protocol to use, it’s up to your home requirements, which area
you should focus on. Whether you want your whole house appliances to interact with each other, or
only some individuals, if the reliability of messages required and transmission bandwidth and
latency are the most important factors …ect.
Yes, we did a comparison but it was not about who is the best in all areas, rather, each one can be
used depending on the proposed and method of usage required. Therefore, we can't decide which
one is the best protocol.
Publish/Subscribe:
When a device (or client) wants to send data to a server (or broker) it is called a publisher.
When the operation is reversed, it is called a subscribe. Multiple clients can connect to the broker and
subscribe to topics that they are interested in. Clients can also publish messages to specific topics of
their interest through the broker. The broker is a common interface for devices to connect to, and
exchange, data. The publish /subscribe messaging model works somewhat like a TV station. A TV
station broadcasts a TV program using a specific channel and a viewer tunes into that channel to view
the broadcast. There is no direct connection between the broadcast station and the viewer.
Broker
Instead of a device sending messages directly to the recipient device(s), they are sent to the
broker, and the broker forwards it to everyone that needs that message. MQTT uses a subject line
called the ‘topic’. If anyone wants a copy of that message, all they need to do is to subscribe to that
topic. On the other hand, if a broker receives a message on a topic for which there are no current
subscribers, the broker discards the message unless the publisher of the message designated the
message as a retained message.
36
Chapter II:………………………………………….……IoT Communication Protocols
37
Chapter II:………………………………………….……IoT Communication Protocols
The selection of the QoS level depends on the system case, like if it:
Retained Messages:
A retained message is a normal MQTT message with the retained flag set to true. The broker stores
the last retained message and the corresponding QoS for that topic. Each client that subscribes to a
topic pattern that matches the topic of the retained message receives the retained message immediately
after they subscribe. The broker stores only one retained message per topic.
Wills
Another extra feature MQTT server has is last will & testament (LWT). It is // a message used to
notify the reason why a connection between a broker and client, who was actively subscribing or
publishing to a topic, was terminated. The notification message is sent to all clients subscribed to that
topic, so that any authorized client in the system can publish a new value back to the edge-network
device, LWT is not only generated by the lack of a keep alive response but also in case a client ends
a connection without a proper disconnect from the broker.
38
Chapter II:………………………………………….……IoT Communication Protocols
MQTT Architecture
MQTT’s communication model avoids direct connections between devices by relaying data
through a central server called the broker. This is really desirable in IoT because it’s easy to add new
devices without touching the existing infrastructure, and since new devices only need to communicate
with the broker, they don’t actually need to be compatible with the other clients [10]. To understand
more, let’s see the following key parts. This system is made up of:
Client (publisher & subscriber)
MQTT Broker (the main central processing unit)
Topic (a reference of the data transmitted)
As we saw in figure 18, which represents the protocol’s architecture. Where 3 main elements are to
pay attention to:
a) Client:
Client could be a Publisher or Subscriber or both and it always establishes the network
connection to the Server (Broker).
The publisher is the source of the data on the system to be sent. A subscriber is a
client who wants to receive messages from the publisher. In the case of subscription,
it gets logically attached to the topic of its interest. When the client subscribes to a
topic of its interest it can exchange messages with this topic. It becomes beneficial to
use this protocol in the scenario where we want to exchange small messages which
require less bandwidth.
b) Broker:
Is a server that receives all messages from the clients and then routes the messages to
the appropriate destination clients.
An MQTT broker or server is software running on a computer that receives messages
from external sources– publishers, and then routes them to the appropriate destination
subscribers. The computer can be a Raspberry Pi, an on premise desktop PC, or a cloud
based server running open-source or proprietary software. One of the most popular
open-source message brokers is the Mosquito broker.
Depending on the implementation, a broker can manage up to thousands of
simultaneously connected MQTT clients. Therefore when choosing an MQTT broker,
you should consider factors such as scalability and integration. In addition to receiving
and routing messages to clients, the broker also delivers other capabilities such as
Quality of Service, Store and Forward, Security.
c) Topic:
Every message is published to an address, known as a topic. The address of a
message, which represents the subject of the published message, and is used by
brokers to filter messages for each connected client. The topic consists of one or
more topic levels. Each topic level is separated by a forward slash.
40
Chapter II:………………………………………….……IoT Communication Protocols
Brokers of MQTT
The MQTT broker is the heart of each MQTT arrangement. It provides a connecting link
between applications or physical devices and enterprise systems. Brokers are in charge of
subscription, determined sessions, missed messages and general security, including authentication
and authorization. The following table describes mostly used brokers with their features and
limitations [10].
Broker About Features Limitations
Mosquitto It supports MQTT - All QoS - Clustering
version 3.1 and it is - Fewer
open source. - Authentication
Configuration
- Bridge - Not allow
- Dynamic topics simultaneous
connection with
- Web sockets using
authentication
RSMB (Really It is a tiny broker - All QoS - Security
small which supports V3 - Web sockets
message broker) and V3.1
- Bridge
- Dynamic topics - Cluster
41
Chapter II:………………………………………….……IoT Communication Protocols
VerneMQ VerneMQ could be - All QoS - Performance
a superior, degradation
distributed MQTT
- Bridge
because of TLS
message broker - Authentication
supports MQTT - Dynamic topics
version 3.1 and - Web sockets
3.1.1
- Encryption
Facebook Messenger: in order to solve problems of limited battery life and internet bandwidth
associated with smartphone use, Facebook innovatively deployed MQTT for its messenger and
Instagram chats that would enable it to function effectively even with the varying internet
connections available across the world. Chats are associated with an MQTT topic, and all
members of a chat group subscribe and publish to that topic. A “Topic Director” steers the MQTT
chat packets to the different brokers that forward them to the appropriate destination subscribers.
Wearable: MQTT protocol is commonly used to enable low-power IoT wearable. The
lightweight nature of the MQTT protocol makes it suitable for wearable devices due to its limited
memory and bandwidth capacity. Data is published when it is pushed from the wearable device
to the server and the receiving devices subscribe to data pushed to the server. Because the size of
the data being sent over MQTT is small by design, messages can be sent quickly, making the
hardware very responsive.
Agriculture Technology: this sector has the potential to increase and enhance the efficiency of
the farming systems by providing continuous monitoring and reporting of the weather and soil
conditions such as soil pH, soil temperature and moisture, air temperature, humidity, and sunlight
availability. MQTT protocol and IoT sensors for agriculture enable seamless data collection and
availability to cloud servers (broker) even for a challenged Internet connection.
Remote Sensing: sensors used in monitoring remote environments are often low power devices
operating in locations with a poor internet connection.
42
Chapter II:………………………………………….……IoT Communication Protocols
Advantage(s) Disadvantage(s)
- A big advantage of MQTT is - As perfect as it sounds MQTT protocol it has One
that the message used in it can disadvantage though, which is MQTT dependency
have any format. This means that to the broker. In MQTT the broker affects the
the publisher and subscriber need scalability of the overall system, meaning that the
to establish beforehand the data network can expand as much as the broker can
format. support it. Also, the broker can be a point of failure
- Lightweight. in an automation system because the broker usually
- Extremely reliable, ensuring is plugged directly in a wall socket while the
message delivery. devices that send/retrieve data from it are most of
- Battery friendly. the time battery operated. So, in case of a power
outage the broker will be offline while the devices
will try to publish data to it [12].
Conclusion
The choice of MQTT as the main communication protocol between devices was seen as suitable
for an IoT smart home system, goes back to its ideal use in constrained environments like IoT which
has low power, limited computation capability and memory, limited bandwidth, and simplicity of use,
rapid deployment and its reliability at transferring data and commands to remote devices.
Therefore, we dedicated a fair time to understand its working, its architecture, the domains where
it is mostly used in, and its various brokers with their limitations and features, even though we never
studied this protocol, nor have the slightest info about it.
43
Chapter III:………………………………………IoT Smart Home Project Components
44
Chapter III:………………………………………IoT Smart Home Project Components
IoT smart homes creation became one of the brightest projects on this last years, they created
devices that can be installed at homes and linked with some supported appliances to command them.
Despite the fact that these devices are expensive, they can effectively interact with human.
However, from our point of view, the drawback of all of these devices is their fully connection
to the internet. Thus, it would be an issue. As a result, the main goal of this project is creating devices
to do an IOT smart home by a minimal communication with internet services, in order to maximize
home independency and privacy with lower cost.
Therefore, on this chapter, we are going to discuss hardware components (as this image below
shows, classified equipment) and software used in order to make this project work, their features and
their work concept with their configuration process.
Hardware
● List of Components:
The following list shows all the components and parts required to complete the build of home
automation project.
45
Chapter III:………………………………………IoT Smart Home Project Components
46
Chapter III:………………………………………IoT Smart Home Project Components
The flame sensor is used to detect the fire or other infrared
light which are in the range of wavelength from 760 nm to
1100nm. The module consists of an IR sensor,
Flame Sensor potentiometer, OP-Amp circuitry and a LED indicator.
When a flame is detected, the module will turn on its red led.
This module is sensitive to flame but it can also detect
ordinary light. The detection point is 60 degrees. The
sensitivity of this sensor is adjustable and it also has a stable
performance [35].
47
Chapter III:………………………………………IoT Smart Home Project Components
This 16-button uses a combination of four rows and four
4x4 Membrane columns to provide button states to the host device, typically
Keypad a microcontroller. Underneath each key is a pushbutton, with
one end connected to one row, and the other end connected
to one column [39].
The L293D Motor driver shield is one of the best ways for
controlling DC motors, Servo motors, and Stepper motors in
L293D Motor a single board. It can control the rotation direction and speed
Driver Shield of four DC motors, two Servo motors, and two Stepper
motors. It is easy to connect with an Arduino UNO or
MEGA.
48
Chapter III:………………………………………IoT Smart Home Project Components
Are defined as a passive two-terminal electrical component
Resistors that implements electrical resistance as a circuit element.
Resistors’ primary job is to regulate or to set the flow of
electrons (current) through them by using the type of
conductive material from which they are composed. The
colored bands are used to denote the resistance, tolerance
and the temperature coefficient.
49
Chapter III:………………………………………IoT Smart Home Project Components
Development Boards
Arduino Uno
Features
Flash Memory: 32KB(0.5KB is used for Boot loader), SRAM is 2 KB, EEPROM is
1KB
Digital input/output pins are 14 (Out of which provide PWM output), Analog input
pins are 6 (A0-A5)
Operating Voltage 5V, Recommended input Voltage 7-12V, limit 20V
CLK Speed is 16 MHz, a power jack, a reset button, USB connection
DC Current on 3.3V Pin is 50mA & on I/O pin is 40mA
Microcontroller: ATmega328P -- 8 bit AVR family microcontroller
Applications
Prototyping of Electronics Products and Systems
Multiple DIY Projects (Do It Yourself)
Easy to use for beginner level DIYers and makers
Projects requiring Multiple I/O interfaces and communications.
50
Chapter III:………………………………………IoT Smart Home Project Components
This board is based on ESP8266MOD Wi-Fi module and it contains the ESP8266EX System on
chip (SoC) from Espressif Systems Company but it has 4 Megabytes of flash memory.
Specification
UARTs: 1, SPIs: 1, I2Cs: 1
RAM: 128 KB, Flash Memory: 4MB,
SRAM: 64KB
Built-in low-power 32-bit CPU ,Clock
Speed: 80 MHz
Wi-Fi built-in (11 b/g/n protocol),
Integrated TCP/IP protocol
PCB Antenna
Operating Voltage: 3.3V
Input Voltage: 7-12V
Digital I/O Pins (DIO): 16
Analog Input Pins (ADC): 1
Microcontroller: Tensilica 32-bit RISC CPU
Xtensa LX106
Application
● Prototyping of IoT devices
● Low power battery operated applications
● Network projects
● Projects requiring multiple I/O interfaces with Wi-Fi and Bluetooth functionalities
51
Chapter III:………………………………………IoT Smart Home Project Components
Raspberry PI 3 Model B
Applications
Media center
Build a home automation system
Industrial/Home automation
Server/cloud server
Print server
Security monitoring
Robotics
Gaming
Web camera
Environmental sensing/monitoring (e.g.
WEATHER STATION)
Low cost PC/tablet/laptop
Specification
1GB RAM, Flash Memory 16 Gbytes SSD memory
card
BCM43438 (802.11 b/g/n) wireless LAN and
Bluetooth Low Energy 4.1(BLE) on board
40-pin extended GPIO
Clock speed 1.2GHz
Full size HDMI, 4 Pole stereo output, composite
video port
Memory Card Slot Push/Pull Micro SDIO
Processor Operating Voltage 3.3V, Raw Voltage
input 5V
2A power source, Power Micro USB socket 5V1,
2.5A
Maximum current through each I/O pin 16mA
CSI camera port for connecting a Raspberry Pi
camera
DSI display port for connecting a Raspberry Pi
touchscreen display
Micro SD port for loading your operating system
and storing data
Operating System Boots from Micro SD card,
running a version of the Linux operating system or
Windows 10
52
Chapter III:………………………………………IoT Smart Home Project Components
ESP-32 CAM
Specification
802.11b/g/n Wi-Fi module
Up to 160MHz clock speed
summary computing power up to 600 DMIPS
Built-in 520 KB SRAM, external 4MB SRAM
Supports UART/SPI/I2C/PWM/ADC/DAC
Support OV2640 and OV7670 cameras, built-
in flash lamp
Supports multiple sleep modes
Embedded Lwip and FreeRTOS
Support Smart Config/AirKiss technology
Support for serial port local and remote
firmware upgrades (FOTA)
Application
● Video streaming
● Security systems
Therefore we will see the software used first, then jump to configuration process:
53
Chapter III:………………………………………IoT Smart Home Project Components
Here, server is RPi and client is Esp8266, we are using it as an MQTT publish subscribe
client.
From a PC on a local network. Esp8266 and RPi are going to use the same local network
which we created in the last blog and ESP8266 as an MQTT publish subscribe client.
54
Chapter III:………………………………………IoT Smart Home Project Components
Raspberry PI OS (Raspbian)
The Raspberry Pi is a computer and like any other computer it needs an OS installed, here it
is called Raspbian [15].
Raspbian is a free operating system based on Debian optimized for the Raspberry Pi
hardware. It comes with over 35,000 packages precompiled software bundles in a nice format
for easy installation on the Raspberry pi.
Raspbian Images
A Raspbian image (Adafruit Raspberry Pi Linux Distro) is a file that can be downloaded onto
an SD card which in turn can be used to boot your Raspberry Pi. The installation process of
Raspbian OS to the card is done via Raspberry Imager, the Steps are below.
55
Chapter III:………………………………………IoT Smart Home Project Components
56
Chapter III:………………………………………IoT Smart Home Project Components
Node-RED
Node-RED is a graphical programming language built on Node.js. It implements a server and runs
what are called “Flows'': programs based on JavaScript. Why would you want to run a server-side IDE
for your programs? Because Node-RED also makes it dead simple to spin up web apps and use them
as your online information and control system [16].
Node-RED is an open-source software platform for data computation coming from external hardware
devices like PLC, Raspberry pi, Arduino’s, micro-controller via various communication protocols like
OPC-UA, MQTT, Ethernet, API or MODBUS.
It provides a browser-based editor that makes it easy to wire together flows using the wide range
of nodes in the palette that can be deployed to its runtime in a single-click.
The light-weight runtime is built on Node.js, taking full advantage of its event-driven, non-
blocking model. This makes it ideal to run at the edge of the network on low-cost hardware such
as the Raspberry Pi as well as in the cloud.
The messages in NODE-RED are straightforward JavaScript objects that can have any
arrangement of properties.
Originally developed by IBM’s Emerging Technology Services team and now a part of the JS
Foundation.
In short, the Node-RED is a simple “wiring” of nodes or predefined code blocks to perform the tasks.
As we see below, are the main sections of the node-red interface, where on the left-side, we can see a
list with a bunch of blocks. These blocks are called nodes and they are separated by their
functionality. If we select a node, we can see how it works in the info tab. In the center, we have the
Flow and this is where we place the nodes.
57
Chapter III:………………………………………IoT Smart Home Project Components
The Connected Nodes and the Flow
1- Input Nodes: it allows you to enter the input data into the flow. They have a grey square on their
right side which you can connect to the other nodes.By connecting this node to another node, you can
send the input data. You can also connect services like Twitter, Google, serial, web sockets and send
those data as inputs to the other nodes. Or else you can manually enter the input data using the node
called “inject”.
Inject Node: This node permits manual activating of streams. It encourages us to infuse
occasions at booked spans.
Examples of Input nodes: inject, catch, status, Mqtt, etc.
2- Output Nodes: it allows you to send the data to the outside world, to other services for example
twitter. It has a grey square on their left side which can be connected to either input node or function.
If you don’t want to send the data to any services like Twitter or email nodes, you can simply debug
those messages by using the tab “deploy” on the top right corner of the editor.
Output nodes: debug, link, Udp, Tcp, Web Socket, Http request, etc
3- Processing Nodes: the processing nodes are used to process the data in which they have one input
endpoint and one or more output endpoints. They are used to transform the data types, to write the
custom codes and to trigger a message.
Processing nodes: comment, delay, function, switch, change, etc
Running Node-Red
When the Node-RED establishment and introductory arrangement is finished, it can be used. Three
ways to run NODE-RED:
✔ Locally
✔ On a device
✔ In the identified cloud environment
Home Automation
58
Chapter III:………………………………………IoT Smart Home Project Components
Visual representation of wiring hardware, services and other components, And many
more...
In order to access the Node-RED program, type in the browser the Raspberry Pi IP
address followed by the port number 1880.
Node-RED Dashboard
This plugin opens up a new level of web visualization and dashboard customization. The plugin
gives the user a clean and easy-to-use platform of which the visualization features can be tailored to
each and every individual's liking. The platform is hosted on the IQ Home gateway itself, so it is
available across the network. With the plugin, the sensor data can be displayed as a line, bar, pie chart
or use gauges.
59
Chapter III:………………………………………IoT Smart Home Project Components
Installing Node-RED
When Pi reboot on, we can test the installation by entering the IP address of our raspberry Pi in the
web browser followed by the 1880 port number:
http://127.0.0.1:1880/ or http://192.168.43.99:1880/ A page like this appears:
60
Chapter III:………………………………………IoT Smart Home Project Components
Note: node red includes elements called ‘nodes’ used to interact with mosquitto server that
it is running inside the raspberry.
- Node-red Nodes:
Node red nodes are arranged in specified
fields each of them have its own functions,
now we will use elements from network and
dashboard nodes.
- MQTT in:
This element is the one who receives the
message when it is published from the client
with the specified topic, as mentioned in the
figure, we must configure it to connect to
our MQTT server and set the topic ‘gas’ and
QoS.
- MQTT out:
It is a non-visible element,it sends
(publishes) the message to all clients
subscribed to the specified topic, as
mentioned in the figure, we must configure
it to connect to our MQTT server and set the
topic ‘led’ and QoS and Retain.
61
Chapter III:………………………………………IoT Smart Home Project Components
- Switch:
The switch element is the one who can
send “on” and “off” commands, generally
this element must be connected at least with
one MQTT out element in order to send the
configured ‘On/ Off’ payload.
- Gauge:
The gauge element is mostly used to
monitor the received data therefore we must
link it with MQTT in element in order to
monitor the gas data
62
Chapter III:………………………………………IoT Smart Home Project Components
We developed our final project dashboard using some of the previous elements and these
are the results.
Eclipse Mosquitto is an open source message broker that implements the MQTT protocol
versions 3.1 and 3.1.1. It is one of the most famous MQTT brokers.
It's very easy to install and easy to use. It is lightweight and is suitable for use on all devices
from low power single board computers to full servers. The MQTT protocol provides a
lightweight method of carrying out messaging using a publish/subscribe model. This makes it
suitable for Internet of Things messaging such as with low power sensors or mobile devices such
as phones, embedded computers or microcontrollers. The Mosquitto project also provides a C
library for implementing MQTT clients, and the very popular mosquitto_pub and mosquitto_sub
command line MQTT clients. It can be installed on UNIX machines. It can be secured via SSL
and passwords.
1- Its importance
After setting up mosquitto MQTT server on a Raspberry Pi. Then, it allows you to connect all
DIY nodes to someone's very own MQTT broker.
In MQTT, the broker is primarily responsible for receiving all messages, filtering the messages,
deciding who is interested in it and then publishing the message to all subscribed clients.
To communicate with the ESP8266 in WiFi (or from the Internet),the
MQTT (Mosquitto broker) communication protocol is used.
They receive the messages from the publishers and take care to properly maintain that
information stream so that only publishers that have proper authentication can send messages.
63
Chapter III:………………………………………IoT Smart Home Project Components
The Broker then provides the data in “Topics” to the “Subscribers”. In the same vein, the Broker
checks the authenticity of each “Subscriber” and only provides each Subscriber with the topics
it is subscribed to.
Mosquitto belongs to the Messaging Oriented Middleware (MOM) software category which
supports sending and receiving of messages between distributed systems.
2- Server ports
The server listens on the following ports:
1883 : MQTT, unencrypted, unauthenticated (SSL)
1884 : MQTT, unencrypted, authenticated
8883 : MQTT, encrypted, unauthenticated (SSL)
8884 : MQTT, encrypted, client certificate required (SSL)
8885 : MQTT, encrypted, authenticated
8887 : MQTT, encrypted, server certificate deliberately expired
8080 : MQTT over WebSockets, unencrypted, unauthenticated
8081 : MQTT over WebSockets, encrypted, unauthenticated
8090 : MQTT over WebSockets, unencrypted, authenticated
8091 : MQTT over WebSockets, encrypted, authenticated
But the most common standard ports for Mqtt to use are TCP/IP port 1883 is
reserved with IANA for use with MQTT. TCP/IP port 8883 is also registered, for
using MQTT over SSL.
The authenticated listeners require a username / password:
After installing the MQTT server, install the client using command.
64
Chapter III:………………………………………IoT Smart Home Project Components
Then check if it is running using command.
Modify the listener line including the raspberry static IP address and save the modification.
After rebooting the raspberry, run this command to run the mosquito with custom
configuration in the background.
mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf &
Arduino IDE
The Arduino IDE (Integrated Development Environment) is where to develop programs that
will tell the Arduino what to do. We can load new programs onto the main chip, the ATmega328p, via
USB using the Arduino IDE. This development environment has a high number of libraries and active
community, it also covers all registers configuration so it is less complicated [31].
Arduino IDE contributors integrated ESP-IDF compiler on their IDE; hence, most of ESP development
board become compatible with Arduino IDE to program this microcontroller with C and C++ language. Though,
it’s written in the Java programming language, and which represents the programming medium between the user
and the board. This development environment has a high number of libraries and active community, it also
covers all registers configuration so it is less complicated than ESP-IDF. To get started of Arduino IDE with
ESP8266 boards, we referred to the source provided. We used The Arduino IDE in our project for:
• Write and compile programs for the NodeMcu card and arduinos.
65
Chapter III:………………………………………IoT Smart Home Project Components
• Connect and Communicate with the NodeMcu board & arduino’s to transfer the programs to it.
For the ESP8266 to interact with the MQTT server, we also must install sleepydog library to use
the watchdog timer for system reset and low power sleep, and mqtt library by Adafruit .This library
allow ESP8266 to talk with node-red over Raspberry pi [30].
After installing these two libraries, to program the NodeMCU as subscriber or publisher
to topics we must follow these programming steps.
66
Chapter III:………………………………………IoT Smart Home Project Components
Declare WLAN and MQTT server Credentials.
67
Chapter III:………………………………………IoT Smart Home Project Components
In void setup, connect to Wi-Fi and subscribe to the declared subscribe
object
In void loop create subscription pointer to get if there is new data transferred to specified topic
then do operation depending on the message , to publish gas value data simply do the
instruction gas.publish(Gaz_value);
68
Chapter III:………………………………………IoT Smart Home Project Components
69
Chapter III:………………………………………IoT Smart Home Project Components
Conclusion
The connection between Raspberry pi, Node-red, Arduinos and MQTT in short:
The Node-RED software is running on a Raspberry Pi in order to create the interface where
the communication between the ESP8266, and Arduino’s interaction is achieved via the
MQTT protocol which is responsible for data exchange.
Node Red receives data from ESP8266 and allow to control arduino’s connected to it from a
dashboard created in Node Red Dashboard.
Arduino IDE code performs several steps but define major broker connection with MQTT,
function post (send messages) even specific topic and subscribe function (receive messages)
even specific topic.
Node client receiving messages: Mqtt (subscribe) from Esp8266 through the topic “event”
node debugging and debugging. Example, sending node values MQTT (publish) which are
“On” “Off” to ESP8266 topic “event” to to display LED status.
At each change Node-RED publishes an MQTT message. For example, servo / pan, 92.
The message is transmitted over the WiFi local area network toESP8266.
After decoding the message, the respective servo-motor is moved to the required angular
position.
We can also control the articulated system from the Internet browser of a tablet or a
smartphone.
We will have a home automation application running on our RPi that allows us to monitor and
control various devices in the house.
We will access our application from any web browser: whether it’s using a laptop, a tablet or
a smartphone. It will be accessible from anywhere.
70
Chapter III:………………………………………IoT Smart Home Project Components
Example:
✔ controlling an output by sending a command,
Lamp example
✔ reading data from a sensor and publish it, Sensor
example
Figure III.2 Controlling light by sending ‘on’ command & reading data from dht11 sensor [17]
At the beginning of this chapter, we started with a general description of the system hardware to be
implemented, also we gave a description, plus the characteristics and installation process of the
software used. In addition, we’ve set an example of how things communicate illustrated in figure 1
above.
Next, we will look into, let’s call “what is behind the scenes”, the i2c concept that we are going to
discuss now in chapter 4. Besides discussing project’s result, their flowchart and circuits diagrams for
better illustration of the system.
71
Chapter IV:………………………………... Project Structure and Results Discussion
72
Chapter IV:………………………………... Project Structure and Results Discussion
Node-red is like the web viewer, where we view the reported information of our controlled
devices thanks to the node-red dashboard in the goal of triggering orders quickly
The mosquito server to establish a communication between things so they can talk and this
interaction is done via MQTT protocol over Wi-Fi.
In this Chapter, we are going to discuss and see other different technologies seen named I2C. Where
the esp8266 is going to play the role of the master that control the slaves, which in our case are the
arduino’s by giving them certain orders to do specific tasks, like opening/closing garage, turning
lights on/off, controlling the house temperature, receiving notifications in case of detecting intruders
and so on…, and this idea of the master slave communication is done via the I2C which help us to
minimize the prototype connection between the components.
Overall, we are going to overview the concept of the I2C communication, how it works, its
features, the concept of the slave and master interaction, how we are going to connect these, how
the esp8266 is going to control the other arduino’s. It’s basically, like the CEO of home automation
company, is the Raspberry Pi “The boss” who everything works under, Then the vice president
ESP8266 who take the head orders to be then given to the workers (the arduino’s) to complete the
tasks, then reviewed again by esp8266 to check if each one is doing his job as it should be, to report
it back to the Raspberry pi. Where everything is well organized. Then, we will present the process
of each project’s part in the form of flowchart.
The following synoptic diagram will allow us to better understand the overall functioning of the
studied
system:
73
Chapter IV:………………………………... Project Structure and Results Discussion
Our project architecture is based on MQTT Broker (server) with one client (subscriber /
publisher), as mentioned in the fig1, the raspberry plays the role of MQTT broker (mosquitto) and
user interface (Nodered dashboard). The raspberry is connected to the WLAN network and defined
by its IP which means that the services are accessible only in local Network therefore the MQTT
client (esp8266) must be connected to the same network in order to subscribe and publish data using
defined topics. In our project we use our client to subscribe to topics that are related to the things we
want to control, in addition, we publish data with the topics that are related to sensors values and
status. Moreover, our MQTT client (esp8266) is an I2C Master used to control the connected
Arduino’s (slaves) that are responsible to interact with appliances.as result, the Arduino’s will
process the sensor values and appliances status and exchange that data with ESP8266 in order to
send and synchronize that data with server.
Important Features
Only two common bus lines (wires) are required to control any device/IC on the I2C
network
No need for prior agreement on data transfer rate like in UART communication. So the
data transfer speed can be adjusted whenever required
Simple mechanism for validation of data transferred
Uses 7-bit addressing system to target a specific device/IC on the I2C bus
I2C networks are easy to scale. New devices can simply be connected to the two
common I2C bus lines
⮚ Limitation
Slower data transfer rate than SPI
The size of the data frame is limited to 8 bits
More complicated hardware needed to implement than SPI
74
Chapter IV:………………………………... Project Structure and Results Discussion
All the devices/ICs on the I2C network are connected to the same SCL and SDA
lines as shown below:
Figure IV.2 Master Slave wiring through i2c bus lines (sda & scl)
The devices connected to the I2C bus are categorized as either masters or slaves. At any instant of
time only a single master stays active on the I2C bus. It controls the SCL clock line and decides
what operation is to be done on the SDA data line.
All the devices that respond to instructions from this master device are slaves. For differentiating
between multiple slave devices connected to the same I2C bus, each slave device is physically
assigned a permanent 7-bit address when a master device wants to transfer data to or from a slave
device, it specifies this particular slave device address on the SDA line and then proceeds with the
transfer. So effectively communication takes place between the master device and a particular slave
device [20]. For example:
❖ The Master- ESP8266: This board is responsible for asking the slave for all the information
like the temperature, the door status, the light or the gas level. Other functions of this board is to
post the data on the web or read data from the web because this board has Wi-Fi built-in on it.
On startup, this board reads the Wi-Fi connection information from the microSD card and use it to
connect to Adafruit and establish a bidirectional MQTT connection; reading and writing using
MQTT
75
Chapter IV:………………………………... Project Structure and Results Discussion
❖ The Slaves -the Arduino’s Uno: The program inside this micro controller runs many STATE
machines to get information about all the sensors, calculate and maintain floating averages of the
temperature, the light, reading from Gas, fire sensors and store all the values in variables ready to
be sent to the master when needed.
As a slave, it is getting ready to answer the requests from the masters such as the value for the door
state or the temperature in the bedroom.
2. Single Master with Multiple Slaves
Because I2C uses addressing, multiple slaves can be controlled from a single master. With
a 7 bit address, 128 (27) unique addresses are available. Using 10 bit addresses is uncommon, but
provides 1,024 (210) unique addresses. To connect multiple slaves to a single master, wire them
like this, with 4.7K Ohm pull-up resistors connecting the SDA and SCL lines to Vcc.
3. Multiple Masters with Multiple Slaves
Multiple masters can be connected to a single slave or multiple slaves. The problem with
multiple masters in the same system comes when two masters try to send or receive data at the
same time over the SDA line. To solve this problem, each master needs to detect if the SDA line
is low or high before transmitting a message. If the SDA line is low, this means that another master
has control of the bus, and the master should wait to send the message. If the SDA line is high,
then it’s safe to transmit the message. To connect multiple masters to multiple slaves, use the
following diagram, with 4.7K Ohm pull-up resistors connecting the SDA and SCL lines to Vcc.
All the other slave devices don't respond unless their address is specified by the master device on
the SDA line
In short, Data is transferred between the master device and slave devices through a single
SDA data line, via patterned sequences of 0’s and 1’s (bits). Each sequence of 0’s and 1’s is termed
as a transaction and the data in each transaction is structured as below [18]:
76
Chapter IV:………………………………... Project Structure and Results Discussion
2. Address Block
To let the slave know that data is being sent to it, and not another slave. It does this by
addressing. Each slave device consists of a frame of 7 unique sequence bits to/from which the
master device needs to send/receive data. The master sends the address of the slave it wants to
communicate with to every slave connected to it.
Each slave then compares the address sent from the master to its own address. If the address
matches, it sends a low voltage ACK bit back to the master. If the address doesn’t match, the slave
does nothing and the SDA line remains high.
All the slave devices on the I2C bus compare these address bits with their address. In short, it
identifies the slave when the master wants to talk to it.
3. Read/Write Bit
A single bit at the end of the frame specifying the direction of data transfer, which informs the
slave whether the master wants to write data to it or receive data from it. If the master device/IC
need to send data to a slave device, this bit is set to ‘0’ (low voltage level). If the master needs to
receive (request) data from the slave, this bit is set to ‘1’ (High voltage level).
4. ACK/NACK Bit
Each frame in a message is followed by an Acknowledged (data frame was successfully
received, an ACK bit ‘0’ is returned to the sender from the receiving device.)/ Not-Acknowledged
bit. If the physical address of any slave device coincides with the address broadcasted by the master
device, the value of this bit is set to ‘0’ by the slave device. Otherwise it remains at logic ‘1’
(default).
77
Chapter IV:………………………………... Project Structure and Results Discussion
5. Data Block
After the master detects the ACK bit from the slave, the first data frame is ready to be sent. The
data frame is always 8 bits long set by the sender. Each data frame is immediately followed by an
ACK/NACK bit to verify that the frame has been received successfully. Set to ‘0’ by the receiver
if it successfully receives data.
Otherwise it stays at logic ‘1’. The ACK bit must be received by either the master or the slave
(depending on who is sending the data) before the next data frame can be sent. This combination
of data block followed by ACK/NACK bit is repeated until the data is completely transferred
6. Stop Condition
After all of the data frames have been sent, the master can send a stop condition to the slave to halt
the transmission. The stop condition is a voltage transition from low to high on the SDA line after
a low to high transition on the SCL line, with the SCL line remaining high.
In short:
1. When a master device tries to send data to a particular slave device through the I2C bus, it sends
the start condition to every connected slave.
2. The master sends each slave the 7 bit address of the slave it wants which corresponds to the
slave device to be targeted, along with the read/write bit ‘0’, which signifies a write.
3. Each slave compares the address sent from the master to its own address. If the address matches,
the slave returns an ACK bit by pulling the SDA line low for one bit(ACK/NACK bit to‘0’, which
signals the master device that a slave device is successfully targeted). If the address from the master
does not match the slave’s own address, the slave leaves the SDA line high (ACK/NACK bit stays
at ‘1’ (default). i.e, this signals the master device that the slave device identification is
unsuccessful.).
4. If a slave device is successfully targeted, it will receive 8 bits of data by the master (which
present the order), then the slave will set the ACK/NACK bit to ‘0’, which signals the master device
to continue. Other remaining slaves are not concerned with what this data means.
7. To stop the data transmission, the master sends a stop condition to the slave by switching SCL
high before switching SDA high.
79
Chapter IV:………………………………... Project Structure and Results Discussion
Project Research
This Organization chart explains the general idea’s plan of our working system, the steps we followed
in order to keep the project organized.
Raspberry Project
80
Chapter IV:………………………………... Project Structure and Results Discussion
The Raspberry Pi organization chart explains how we used the raspberry pi. Before we use it, we
make sure that our Wi-Fi is within range. We control the house using a node red interface control
panel, which allows us to monitor all of the appliances. MQTT broker, on the other hand, is in
charge of house communication via MQTT messaging protocol over Wi-Fi.
ESP8266 Project
The following ESP8266 flowchart depicts how NodeMcu reads the program and executes it, keeping
track of all the sensors he is controlling by issuing orders so that each sensor can complete his task.
81
Chapter IV:………………………………... Project Structure and Results Discussion
82
Chapter IV:………………………………... Project Structure and Results Discussion
The security system project is an I2C slave so the I2C Master will interrupt this device, in
this case, the data transmit function will be triggered and the slave will stop using the sensors than
it transfers the last stored values from the sensors, therefore the master know how much data will
be received
Gas detection
A gas detector can read analog (A0) / (D0) digital output voltage that is proportional to the
concentration of smoke/gas. This voltage that the sensor outputs changes accordingly to the
smoke/gas level that exists in the atmosphere. In other words, the relationship between voltage and
gas concentration is the following:
● The greater the gas concentration, the greater the output voltage
● The lower the gas concentration, the lower the output voltage
Note: Results given by sensors are displayed On Serial Monitor so it can help us observe their
state.
Figure IV.10 Schematic: Security System Using fire, gas, motion, humidity & temperature Sensors
1- When the smoke reaches a certain level, it will make a buzzer and a red LED
will turn on. As it’s shown in figure below:
83
Chapter IV:………………………………... Project Structure and Results Discussion
2- When the output voltage is below that level, a green LED will be on.
Notifying operators in the area where the leak is occurring, giving them the
opportunity to leave.
Flame sensor
It will read the analog values given by the flame sensor (0-1024).
If flame is detected in front of the sensor, it will be activated, the buzzer will
make a sound and a warning message will be displayed. Else, if no flame is
detected in front of the sensor, a safety message will be displayed.
84
Chapter IV:………………………………... Project Structure and Results Discussion
85
Chapter IV:………………………………... Project Structure and Results Discussion
Circuit Explanation
● First thing to do, is to retrieve the information of the tags on the serial monitor by uploading the
“dumpinfo” from the
● examples in the Arduino.
● The 4x4 keypad has 8 connections but we only used 3 columns for the password, the ones that
require numbers.
● In case of entering the wrong password, tag or intrusion the red led will light up indicating
danger. Else the green led indicates safety.
● The buzzer will beep anytime we scan tag or for security purposes.
● The servo motor is responsible for closing or opening the door.
86
Chapter IV:………………………………... Project Structure and Results Discussion
To open the door, the user will have to first scan the right tag and then he will have to enter
the correct password. On scanning the wrong tag or on entering the wrong password, the system
will deny access.
The main goal is to monitor the door manually or from a smartphone by typing their unique pin
numbers into a special website which gives the advantage to interact in case we forget the door is
open.
1- It displays door locked, scan your tag 2-Scanning the right tag, it will ask for password
3- Entering four digits password 4- if pw is correctly entered, the door shall open
87
Chapter IV:………………………………... Project Structure and Results Discussion
88
Chapter IV:………………………………... Project Structure and Results Discussion
The Garage project in every cycle of the master it receives sensors data and node-red buttons
status in order to know whether it uses emergency case (control door and fan depending on sensors)
or just control them depending on user interface variables. Also, if master asks it receive data it
transmits the door and fan status then the master sync it to the user interface.
The main goal is to monitor the garage door and to interact in case we forget the door open.
Members could open the garage door using an android app on their mobile phones, in our case the
node-red dashboard is our user interface where we can trigger the opening or closing of the garage
door by selecting the open/close button.
● The controller will take the action of closing and opening the door.
● Else it will open automatically in case of gas or fire detection, at the same time evacuate the air
by turning the fan on.
89
Chapter IV:………………………………... Project Structure and Results Discussion
Master-Slave Concept
90
Annex
General Conclusion
To create a well-designed Smart Home, we needed to integrate IOT hardware, equipped with
actuators and sensors. Depending on the sensors values, we had to train house to intelligently
interact not only between appliances but with home owners too, by integrating them in computing
machines that are included into the IOT system. Moreover, this will let the home interact more
smartly.
Practically, creating separated devices that can interact with each home appliance gives a
high flexibility and compatibility for home customization, especially due to the fact that they are
easy to install, providing an easy usage experience. Consequently, after testing the home, we
definitely can say that integrating Mqtt protocol “which is responsible mostly for devices
communication”, was a good choice for the fluidity of data transmission he provides due to the
light weight message the protocol offers, as well as the reliability that quality of service integration
within the protocol affords. And the sensors that interacted with each other in order to design the
monitoring and control of home devices, based on the microcontrollers NodeMcu, Raspberry Pi,
and arduino's modules, which worked flawlessly.
Despite the complexity and difficulty of this research, implementing this project gave us the
opportunity to learn new skills and gain new knowledge in the field of smart automation. In
addition, our method of thinking has improved. Furthermore, one of project’s main originality relies
on a secure platform that combines online and offline services to allow users more privacy and
home independence (Offline Mode can be used for peoples who don’t want to have their houses
Online), as well as being sustainable (track user behavior), reliable (not expensive Hardware
devices), adaptable (on one needs), scalable, fully controlled (easy interface) and Secure.
We can invest in the field of home appliances by developing fully functional appliances that
are compatible with this platform. Furthermore, we may be able to work out deals with companies
that already have extensive expertise making home appliances, allowing us to integrate and
generalize our controlling interface to their products. Our objective is to empower our users to
transform their homes into smart homes by leveraging IoT and AI technologies to achieve
maximum comfort with minimal effort.
In conclusion, the contribution of this project is mainly summed up in the discovery of a
new field called home automation, which is a very interesting and very vast and innovative field.
Though, we took the risk to engage with it and it was really challenging for us, to study something
new that we wasn’t sure if it will work out or not, but it was worth it. It gave us the chance to hit
many different areas to understand too in order to hook up everything. Though, we find it difficult
but after a hard work we make it through. Also, we had to learn electronics (even if it’s not our
specialty we took the initiation). In addition, to studying the working concept of hardware, to the
implementation of the protocol that we wasn't familiar with at all, since it was new to us. However,
we aim to expand our knowledge and experience in this domain, considering it as a future research.
Then, we sincerely hope that this effort will serve as a springboard for further in-depth studies.
91
Annex
So based on our experience during this journey, here are some examples of what we faced, and
fortunately solved:
● If you ever find yourself unable to connect via SSH, you can always check the IP address if it’s
the raspberry pi’s or if you made any changes in your raspberry’s pi uwf (firewall) setting, which
took us a while to figure it out in our case, it’s good to be curious but be always be careful.
● Considering alarms sound, if you were to use buzzers. Then, if anything happens like starting to
buzz from the start without pre-orders, then check your code settings, go to setup and where you
are defining the buzzer as an output [pinMode(buzzer,OUTPUT)], make sure to declare its status
as low, [digitalWrite(buzzer,LOW)].
● Need to be careful when installing libraries, you can find so many within same name but
different creators, to avoid troublesome errors, use only what you need.
● To interact with MQTT broker in LAN network in raspberry we must disable its firewall.
● We must choose good power source and ground all hardware together in order to let the project
function correctly.
● In our project, we must run the raspberry first, then run the NodeMCU with Arduino’s. However,
we must reset the NodeMCU in order to establish communication with all Arduino’s after they get
sensors data via I2C.
92
Annex
4. Application to turn on the lights inside the house automatically if there is movement detected and
is dark inside the house, using PIR sensor, and a light sensor.
5. Application to have access inside the house using an RFID module, Oled module with i2c
interface and an MG 90 S servo motor.
Using all these applications, anyone can build a smart home to make their life better and more
comfortable. All of the components used with esp8266 and Raspberry pi help us to monitor and
control the house from any place as long as we are connected to the internet.
93
Annex
Annex C: Fritzing
Is the Software we used in creating our circuit’s Schematic. It’s an innovative Electronic
Design Automation software that has an extensive library of electronic components with a very
simple user interface, where we can view these three following modes:
3. PCB: allows us to place parts on a printed circuit board. An auto-router generates the traces
and the final pcb layout can be exported to the necessary production formats.
94
Annex
95
Annex
Transport Protocols
IP: Internet Protocol
TCP: Transmission Control Protocol
UDP: User Datagram Protocol
SCTP: Stream Control Transmission Protocol
Security Protocols
TLS: Transport Layer Security
SSL: Secure Sockets Layer
SSH: Secure Shell
DTLS: Datagram Transport Layer Security
IPsec: Internet Protocol Security
QOS: Quality of Service
Network & messaging protocols
Wi-Fi: Wireless Fidelity
ZigBee: ZigBee End-Device and ZigBee Coordinator
ZWave: ZWave
RF: Radio Frequency
BLE: Bluetooth Low Energy
RESTful: Representational State Transfer
MQTT: Message Queuing Telemetry Transport
HTTP: Hypertext Transfer Protocol
AMQP: Advanced Message Queuing Protocol
CoAP: Constrained Application Protocol
XMPP: Extensible Messaging and Presence Protocol
EXL: Efficient XML Interchanges
DDS: Data Distribution Service
IM: Instant Messaging
M2M: Machine-to-Machine
WSN: Wireless Sensor Networks
PINS Input/output
ADC: Analog to Digital Converter
GPIO: General-Purpose Input/output
DIO: Digital I/O Pins
ADC: Analog Input Pins
Serial Communication
I2C: Inter-Integrated Circuit
I2S: Inter-IC Sound
SPI: Serial Peripheral Interface
DSI : Display Serial Interface
UARTs: Universal Asynchronous Receiver/Transmitter
CLK: Clock pin
96
Annex
Serial Monitor baud rate: rate at which information is transferred in a communication channel
Current
AC: Alternative Current
DC: Direct Current
IC: Integrated Circuit
Power jack: a power source
PORTS
USB: Universal Serial Bus
HDMI: High-Definition Multimedia Interface
CSI: Camera Serial Interface port
Power Micro USB: for powering stuff or charging
Memory & storage
EEPROM: Electrically Erasable Programmable Read-Only Memory
GDDRAM: Graphics Double Data Rate Synchronous Dynamic Random-
Access Memory
SRAM: Static Random-Access Memory
Flash Memory: Electronically Erasable Programmable Read Only Memory
RAM: Random Access Memory
SD-card: Secure Digital Card for storing data
TF- card: Trans Flash Card
Microcontroller
ATmega328P: AVR family microcontroller
MCU: Microcontroller Unite
SOC: System on Chip
BCM43438: Wi-Fi chip
Organizations
IBM: International Business Machines, a leading US computer manufacturer
Facebook: Free Expression, a messaging application
Eurotech: strategic partnership of leading European universities of science and technology
Cisco: US Technology Company that is best known for its networking products.
Red Hat: an IBM subsidiary and software company that provides open source software
products to enterprises.
Software AG: a business infrastructure software provider with products in various
technologies
Tibco: The Information Bus Company creates software and hardware products around
business solutions based on Service Oriented Architecture or SOA.
ITSO: smart ticketing technology (Operates smart cards)
M2Mi: Machine-To-Machine Intelligence (computer Software Company)
AWS: Amazon Web Services (a cloud service from Amazon)
InduSoft: Web Studio is collection of automation tools to develop modern Human Machine
97
Annex
Interfaces (HMI), Supervisory Control and Data Acquisition (SCADA) systems, and embedded
instrumentation and control applications.
Fiorano: a global leader in Integration middleware, API Management and Peer-to-peer
distributed systems.
Microsoft: a leading global vendor of computer software; hardware for computer, mobile and
gaming systems; and cloud services.
98
ANNEX
100
ANNEX
101
ANNEX
147. if (retries == 0) {
148. // basically die and wait for WDT to reset me
149. while (1);
150. } }
151. Serial.println("MQTT Connected!");
152. }
153. void recive_Arduino_data(){
154. Gaz_val=0;
155. flame=0;
156. humid=0;
157. temperature=0;
158. motion=0;
159. fan=0;
160. //Serial.println(c);
161. Wire.requestFrom(5,4);
162. garag += Wire.read()<< 8; // receive a byte as character
163. garag += Wire.read();
164. //garagelight += Wire.read()<< 8; // receive a byte
165. //garagelight += Wire.read();
166. fan += Wire.read()<< 8; // receive a byte
167. fan += Wire.read();
168. Wire.requestFrom(8,10); // request 8 bytes from slave device #8
169. Gaz_val += Wire.read()<< 8; // receive a byte as character
170. Gaz_val += Wire.read();
171. flame += Wire.read()<< 8; // receive a byte
172. flame += Wire.read();
173. humid += Wire.read()<< 8; // receive a byte
174. humid += Wire.read();
175. temperature += Wire.read()<< 8; // receive a byte as character
176. temperature += Wire.read();
177. motion +=Wire.read()<< 8; // receive a byte
178. motion += Wire.read();
179. //motion=digitalRead(D4); }
180. void send_data(){
181. Wire.beginTransmission(5); // transmit to device #5
182. Wire.write(highByte(Gaz_val)); //I2C is byte oriented;
183. Wire.write(lowByte(Gaz_val));
184. Wire.write(highByte(flame)); //I2C is byte oriented;
185. Wire.write(lowByte(flame));
186. Wire.write(highByte(motion)); //I2C is byte oriented;
187. Wire.write(lowByte(motion));
188. //Wire.write(highByte(garagelight)); //I2C is byte oriented;
189. //Wire.write(lowByte(garagelight));
190. Wire.write(highByte(garag)); //I2C is byte oriented;
191. Wire.write(lowByte(garag));
192. Wire.write(highByte(fan)); //I2C is byte oriented;
193. Wire.write(lowByte(fan));
194. Wire.endTransmission(); // stop transmitting }
195. void send_password(){
196. Wire.beginTransmission(6); // transmit to device #6
197. Wire.write((char* )doorpass.lastread); // sends x
198. Wire.endTransmission(); // stop transmitting }
102
References
References
[1] Prof. Prashant Rathod, Syed Khizaruddin, Rashmi Kotian, Shubham Lal.
[2] "The Smart Home Concept: our immediate future", Vincent et Al, IEEE International Conf
2006,doi:10.1109/ICELIE.2006.347206,[Online].Available:https://www.researchgate.net/publication/2246964
59_The_Smart_Home_Concept_our_immediate_future
[3] L. D. S. al., "State of the art of smart home", vol. 25, pp. 1313-1321, 2012.
[4] R. Harper, "Smart Homes: Past, Present and Future," in Inside the Smart Home, Bristol,UK, Springer
Science & Business Media, 2006, pp. 17-39.
[5] Samuel, "A Review of Connectivity Challenges in IoT-Smart Home," in International Conference on
Big Data and Smart City, Muscat, Sultanate of Oman, 2016.
[6] "Choice of Effective Messaging Protocols for IoT Systems", Nitin Naik et Al, Conf 2017,
IEEE,International,Systems,Engineering,Symposium,(ISSE),doi:10.1109/SysEng.2017.8088251,[Online],Avai
lable: https://ieeexplore.ieee.org/abstract/document/8088251/ .
[8] "Comparison with HTTP and MQTT In Internet of Things (IoT)", ICIRCA, Conf 2017 International
Conference on Control, Electronics, and Communications (ICCEREC), doi:
10.1109/ICCEREC.2016.7814989,[Online].Available:https://ieeexplore.ieee.org/abstract/document/7814989.
[10] "A Servey On MQTT Protocol Of Internet Of Things", Dipa Soni, Conf 2017
Researchgate,Chandubhai,SPatel,Institute,of,Technology,[Online].Available:
https://www.researchgate.net/profile/Dipa- Soni/publication/
[11] HiveMq,"what,is,mqtt-protocol-an-introduction-about-mqtt",[Online].Available:
https://www.hivemq.com/mqtt-5/
[12] "Smart home automation with MQTT", Andrei Cornel et AL, Conf 2019 54th International
Universities Power Engineering, doi: 10.1109/UPEC.2019.8893617, [Online]. Available:
https://ieeexplore.ieee.org/abstract/document/8893617
[13] "Specifying an MQTT Tree for a Connected Smart Home", Van den Bossche A. et Al, ICOST 2018
Lecture Notes in Computer Science, vol 10898. Springer, Cham. https://doi.org/10.1007/978-3-319-94523-
1_21
[14] "Secure MQTT for Internet of Things (IoT) " ,singh et Al, Conf 2015 Fifth International Conference
on Communication Systems and Network Technologies, doi:
10.1109/CSNT.2015.16,[Online].Available:https://ieeexplore.ieee.org/abstract/document/7280018,
[15] Raspberry.Community,"Raspberry-PIDocumentation",[Online].Available:
103
References
https://www.raspberrypi.org
[17] RandomNerdTutorials,"MQTTServerWorkConcept",[Online].Available:https://randomnerdtutorials.c
om/MQTT-broker
[18] Electronicshub,"Master,slave,interaction’s,workconcept",[Online].Available:
https://www.electronicshub.org/basics-i2c-communication/
[19] Vinay.S, Kusuma.M, “Home Automation Using Internet of Things", International Research Journal
of Engineering and Technology, 2015, Vol. 2, No. 3.
[20] Science Soft – Professional Software Development, " How IoT
architecture,works",[Online].Available:https://www.scnsoft.com/blog/iot-architecture-in-a-nutshell-and-how-
it-
[21] Henderson Electric, "How Does Smart Home Automation Work?” Published 2019, [Online]. Available:
https://hendersonelectric.com/how-does-smart-home-automation-work/
[24] Jatin.P, "WiFi’s evolving role in IoT”, MAY 11, 2017, P 802.
[27] Roy Delgado. A, Picking. R, Grout. V, "Remote-Controlled Home Automation Systems with
Different Network Technologies”, Paper presented to the 6th International Network Conference (INC 2006)
2006, pp360.
[28] Rajeev. P," Internet of Things: Ubiquitous Home Control and Monitoring System using Android
based Smart Phone “2013.
[30] LastMinuteEngineers,"Insight Into ESP8266 NodeMCU Features & Using It With Arduino IDE",
[Online]. Available: https://lastminuteengineers.com/esp8266-nodemcu-arduino-tutorial/
[34] SeeedTechnology Bendable El Wire, "Grove Gas Sensor MQ-5 ", [Online]. Available:
104
References
https://media.digikey.com/pdf/DataSheets/SeeedTechnology/Grove_Gas_Sensor_MQ5_Web.pdf
[44] BMC, "OSI Model: The 7 Layers of Network Architecture", [Online]. Available:
https://blogs.bmc.com/osi-model-7-layers/?print=pdf
[47] Juniper-Research,"Smart-home-statistic",[Online].Available:
https://www.juniperresearch.com/infographics/smart-home-
statistics
105