Академический Документы
Профессиональный Документы
Культура Документы
Bachelor Thesis
Bachelor Thesis
(i) the thesis comprises only my original work toward the Bachelor Degree
(ii) due acknowledgment has been made in the text to all other material used
V
Abstract
This paper presents an approach for smart home automation using Internet of Things
(IoT ) integration with computer vision, web services and cross-platform mobile services.
This project aims to increase home security using the aforementioned approach. The
approach focuses on: (1) sending data and receiving instructions by sensors, cameras and
servo motors, to and from the end user, through embedding intelligence to the mentioned
gadgets using Raspberry Pi tiny computer; (2) assisting interaction of end users and home
devices through cross-platform mobile application developed using Ionic Framework; (3)
connecting the two client sides, the end user and devices, through publish/subscribe model
using PubNub Data Stream Network; (4) data representation and exchange efficiently
using JSON data format. Moreover, four use cases were implemented to demonstrate
this approach efficiency.
VI
Contents
Acknowledgments V
1 Introduction 1
1.1 Internet of Things . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Internet of Things Applications . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Aim and Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Background 5
3 Methodology 6
3.1 System Architecture and Approach . . . . . . . . . . . . . . . . . . . . . 6
3.2 Model Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.3 Technical Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3.1 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3.2 Using Raspberry Pi for IoT . . . . . . . . . . . . . . . . . . . . . 14
3.3.3 Using JSON for the data exchanged parsing . . . . . . . . . . . . 15
3.3.4 Using PubNub for data streaming and exchange . . . . . . . . . . 15
3.3.5 Using OpenCV for Computer vision and image processing . . . . 16
3.3.6 Using Ionic framework for web/mobile application . . . . . . . . . 16
5 Conclusion 21
6 Future Work 22
Appendix 23
VII
References 25
VIII
Chapter 1
Introduction
1
CHAPTER 1. INTRODUCTION 2
Figure 1.2: Shows different applications of internet of things in all aspects of life2 .
Figure 1.3: Shows different use cases of IoT in Home Automation field3 .
A user has the following features through a mobile application in which he/she:
1. can turn on or off LED lights and monitor the state of the LED.
2. can lock and unlock doors through servo motors and monitor if the doors are locked
or unlocked.
4. is notified through email if the door is left open for too long.
5. is notified of who entered through the door as the camera captures the face image
and send it to him/her via email.
7. is able to control the surveillance car from anywhere to monitor his/her home.
CHAPTER 1. INTRODUCTION 4
1.4 Motivation
During the past few years, internet was known as a big mass that we can acquire
data from. Embedding mobile transceivers to everyday items and gadgets enabled new
forms of bi-directional communication between people with other people, and people with
things. That paradigm, known as Internet of Things, that was first introduced in 1998
by Kevin Ashton, has received recently more attention in the academia and industry [8],
and this would add a new dimension to the world of Information and communication
technology.
While that paradigm is growing and have high positive impact on many aspects of
our lives, challenging issues arise, that should be considered and addressed. The central
issues are guaranteeing security and privacy of users and their data. Another issue is fully
achieving smartness of interconnected devices by enabling their interaction. Exchanging
data and autonomous behavior is the key to achieving the latter [4].
IoT has different definitions from different perspectives, however, they all revolve
around ”things” generally, collecting, exchanging and communicating data with each
others and with people through the ”internet”. IoT helps in decision making and au-
tomating almost everything around us. The smarter life IoT vision promises in the near
future through various applications, made smart Home Automation actually possible,
starting from basically monitoring different parts of home, to actually controlling them.
Integration of IoT and Home Automation, made it possible to monitor and control homes
from different parts of the world. Some examples of applications to this are: controlling
and setting the desired temperature of the house before arriving home, turning on/off the
lights of a room and setting its intensity, running washing machine while the person is at
work, leakage or smoke detection and notification, monitoring home through surveillance
camera or car inside the house while the person is away, or remote central locking, and
many other applications.
As the field of Home Automation through IoT is a wide application in a very wide
and challenging field due to the reasons mentioned in the previous paragraphs, I chose to
work on that field as part of this thesis, specifically in maintaining and ensuring security
and safety inside home.
Chapter 2
Background
IoT aims in creating a network between objects embedded with sensors, that can
store, analyze, communicate and exchange data together over the internet. This leads
to efficient industry, manufacturing, efficient energy management, resource management,
accurate health care, smarter business decisions based on analyzed data, safer driving
through smart cars that are able to communicate together, smart home automation and
countless more applications.
As this project focuses on smart home automation through IoT, smart home concept
should be understood first. Smart homes combines common devices, found in homes,
to be able to control it. The technology originally was developed and used to control
environmental systems, but recently, almost any electrical component can be included
within the system of smart home [7].
The system designed for the home automation project presented in this paper needs
a control unit, a computer, to be able to control the different electrical devices connected
to it. Raspberry Pi, is a credit-card tiny computer, that can be plugged to a monitor,
uses standard keyboard and mouse, that enables people of different ages learn how to
program. For its simplicity and capabilities, it has been chosen to be the control unit of
this project1 .
Data stream network is the infrastructure and network that connects devices from
anywhere in the world, allowing developers to build real-time applications in a secure and
reliable manner. PubNub is the data stream network that was used in this project as the
publish/subscribe communication design provided by it allowed bi-directional connection
easily and reliably.
Cross-platform software is a software developed to be run on multiple and different
platforms such as web, iOS or Android. Ionic, is an open source SDK for developing cross-
platform applications using HTML, CSS and JS components. It was used in developing
the mobile application used in testing the developed approach in this project.
1
URL: https://www.raspberrypi.org/help/what-is-a-raspberry-pi/
5
Chapter 3
Methodology
The first thing that had to be thought about after choosing this topic was the system
architecture. How will the appliances and devices communicate with a web/mobile ap-
plication, receive commands and send their status? Should it be a server client protocol,
in which there is a direct connection between the devices and the application used by
the user? How will a direct connection be established over the internet? Or should the
client and server communicate through a medium channel that the messages should be
passed on before reaching the client or the server? These questions had led to exploring
different approaches and services. Raspberry Pi was chosen as the main control unit, to
connect different sensors and devices together and to the internet. The Raspberry Pi is
a tiny computer, that has forty GPIO pins and capable of being programmed, so it was
chosen for its simplicity and capabilities.
6
CHAPTER 3. METHODOLOGY 7
The next challenge, after finding a way to connect different devices together and to
the internet was actually controlling them over the internet through a web/mobile appli-
cation built using Ionic Framework. Different ways and services were explored including
setting-up port forwarding on the router. Setting-up port forwarding will change the con-
figuration of the router and expose one port of the private Local Area Network(LAN) to
the public, which is considered a security vulnerability that has to be managed carefully.
Some of the services that were explored and considered to allow the communication of the
web/mobile application with the Raspberry Pi connecting different devices are Weaved,
Pusher and AWS Mobile Hub. However, the need of real-time interaction and PubNub’s
publish/subscribe model, it was chosen as the most adequate solution.
Figure 3.2: Illustrates the system architecture used in this home automation project.
CHAPTER 3. METHODOLOGY 9
To simplify the publish/subscribe model along with the system architecture used in
this Home Automation project, here is the explanation of the steps of constructing it:
Different sensors, cameras and servo motors were connected to the Raspberry Pi. It
was programmed to collect and publish the data, in the form of JSON string, acquired
from these devices to PubNub. Data is published from the Raspberry Pi by providing
it with the ”publish key” and the ”channel name”. The data is sent to the channel
provided by PubNub servers, and forwarded by PubNub to the subscribers of this channel.
The subscriber in this scenario, of a user acquiring data and readings by the sensors
and monitoring devices, is the web/mobile application. The ”subscription key” and
”channel name” is embedded in the web/mobile application’s code. allowing it to receive
messages forwarded by PubNub. On the other hand, in a scenario where the user wants
to send a command to home appliances, controlling the LED lights for example, the
web/mobile application is the publisher provided by the ”publish key” and the ”channel
name”. The commend is sent in the form of JSON string to PubNub servers, while the
”subscription key” and ”channel name” is embedded in the Raspberry Pi code. This
allows the Raspberry Pi to receive any published strings on the channel it is subscribed
to. Upon receiving the JSON string, the Raspberry Pi take the action specified by that
string. This allows full control and monitoring of all devices connected to the Raspberry
Pi by the user, as illustrated in the previous figure (Figure 3.2).
Figure 3.3: Here is a more specific illustration of how the mobile and connected devices
to the Raspberry Pi exchange data through PubNub.
CHAPTER 3. METHODOLOGY 10
Figure 3.4: Shows the top and front views of the model design.
CHAPTER 3. METHODOLOGY 11
Another part of the project was the surveillance car. It was modeled by a four wheel
drive (4WD) car using four DC motors and chassis made of acrylic material. The car
motors were connected to two H-Bridges and to a Raspberry Pi to control it over the
internet.
Figure 3.8: Shows the car model after assembling its components3 .
CHAPTER 3. METHODOLOGY 13
Figure 3.9: Shows the car model after connecting the Raspberry Pi and the 2 H-Bridges.
3.3.1 Components
The components that were used in the Home Automation Simulation are:
• Two RaspberryPi 2 model B: The main processing and controlling unit of the
system. One was used for the room model and the other for the surveillance car.
• Infrared (IR) sensor: Shows the current state of the front door, either opened or
closed.
• Web Camera: Acts as a surveillance camera for the room streaming images of that
room that are processed by the RaspberryPi. It utilizes OpenCV’s image processing
to be able to detect objects in the room.
• Two H-Bridges: Each H-Bridge controls two motors, two are used to control the
four DC motors of the car.
• Wi-Fi Dongle: Attached to the Raspberry Pi through USB port to allow its con-
nection to wireless internet instead of using Ethernet cable.
CHAPTER 3. METHODOLOGY 14
The Raspberry Pi is a low priced, credit card sized computer. It can be connected
to a computer monitor or a television through HDMI cable and HDMI port found in the
Raspberry Pi4 . It has four USB ports, allowing the connection of different peripherals to
it such as keyboard, mouse, memory stick or Wi-Fi dongle, that allows its connection to
wireless internet. As any computer, the Raspberry Pi needs an Operating System(OS)
to run on it, to allow the interaction between it and the user. Different OS choices that
can run on the Raspberry Pi are available such as Raspbian, Linux and a Windows 10
special version for the Raspberry Pi. The OS is downloaded to a micro SD card and
mounted to the Raspberry Pi’s SD memory reader. It also has Ethernet port that allows
its connection to the internet through Ethernet cable from a router.
Raspbian was installed on a micro SD card that was mounted to the Raspberry Pi, that
allowed writing Python scripts. The needed hardware, such as sensors and LEDs, were
connected, using jumper wires, to the GPIO pins in the Raspberry Pi. Python scripts
were written on the Raspberry Pi, which allowed controlling and monitoring the connected
hardware for testing. The PubNub ”publish key”, ”subscription key” and ”channel name”
were embedded in the python scripts written on the Raspberry Pi, allowing data exchange
through PubNub servers.
4
URL: https://www.raspberrypi.org/help/what-is-a-raspberry-pi/
CHAPTER 3. METHODOLOGY 15
Figure 3.11: Shows a screen shot of the developed application for Home Automation.
8
URL: http://opencv.org/about.html
9
URL: http://ionicframework.com/
Chapter 4
Both, the Raspberry Pi and the mobile application, are senders and receivers of data.
This applies as both publish and subscribe at the same time to the same PubNub channel.
This allowed bi-directional communication for data exchange. Accordingly, multiple use
cases were implemented and studied for result analysis.
The LEDs, connected to the Raspberry Pi through the GPIO pins and embedded in
the model, were controlled through a mobile application developed with Ionic. A ”Light”
tab was created in the application which has a button that toggles between ”ON” and
”OFF” when clicked. The default value of the button shows the current status of the LED
lights. If the button shows the value ”OFF”, this means that the LEDs are currently
turned off. However, when the button is clicked, the value toggles to ”ON”, sending
a JSON string holding a value of 1 for ”led” attribute, {’led’:1}, to the channel the
application publishes to, through PubNub and the ”publish key”. The JSON string
received by this channel is then sent to its subscribers, the Raspberry Pi in this project’s
case. The Raspberry Pi then receives the JSON string, checking the ”led” attribute value
and turns the LEDs accordingly. The mobile application is also a subscriber to the same
channel, in which it can check the last status of the LEDs published on PubNub channel
and shows either ”ON” or ”OFF” as a default value of the button in the application.
17
CHAPTER 4. USE CASES AND RESULTS 18
A 180 degrees servo motor, acting as the door lock of the modeled room, was connected
to the Raspberry Pi through the GPIO pins. It was glued to the model’s door along with
a glued cardboard tip to lengthen the servo’s horn. A ”Lock” tab was created in the
application which has a button that toggles between ”LOCK” and ”UNLOCK” when
clicked. The default value of the button shows the action that will be taken by the
servo lock, changing its angle, when the button is pressed. If the button shows the value
”UNLOCK”, this means that the servo motor will be adjusted to 0 degree, unlocking the
door. The button’s value toggles to ”LOCK”, When the button is clicked, sending a JSON
string holding a value of 0 for ”lock” attribute, {’lock’:0}, to the channel the application
publishes to and the ”publish key” provided by PubNub. The JSON string received by
this channel is then sent to the Raspberry Pi, which receives the JSON string, checking
the ”lock” attribute value and sets the servo motor’s angle to 0 degrees, unlocking the
door.
The mobile application is also subscriber to the same channel the Raspberry Pi is
a subscriber to, as discussed in 4.1.1. Therefore, it can receive messages sent by the
Raspberry Pi from the infrared (IR) sensor installed on the door. By default, the IR
beam is cut by the door frame, indicating that it is closed. When the door is opened, the
IR beam is uncut, which will send a JSON string holding a value of 1 for the ”ir” attribute,
{’ir’:1}, to PubNub. The JSON string is then forwarded to the mobile application, in
CHAPTER 4. USE CASES AND RESULTS 19
which the application will change the door status message to ”Door is opened.”. When
the door is closed, the same scenario takes place, however, the value of the attribute ”ir”
in that case, sent to PubNub and then forwarded to the mobile application, is 0, {’ir’:0},
updating the door status message to ”Door is closed.”. If the door is left open for more
than a minute, an email notification is sent to the predefined user’s email.
A web camera was connected to the Raspberry Pi through a USB port for the room
model surveillance. A simple motion detection algorithm was written and run using
OpenCV library to detect if the room is occupied or not. The algorithm detects major
changes in the room environment as it has the default room environment background.
If a major difference detected between the background the algorithm has and the recent
captured image, then the room is occupied, otherwise, it is not. If the room is occupied,
a JSON string holding the value of 1 for ”occ” attribute, {’occ’:1}, is published by the
Raspberry Pi, to PubNub channel. The JSON string is then forwarded by that channel
to its subscribers, the mobile application in this case. When the JSON string is received
by the mobile application, the ”occ” attribute value is checked and a message is displayed
accordingly, if the room is occupied, the message displays ”The room is occupied”, if not,
the message displays ”The room is not occupied”. This allows the user to always monitor
his/her room assuring its security.
The last part of the model was the surveillance car, which has its own Raspberry
Pi controlling it. The Raspberry Pi of the car was a publisher and a subscriber to the
same channel, the other Raspberry Pi connected to the room model publish and sub-
scribe to. This makes both Raspberry Pis able to receive the same messages, keeping
the whole system synchronous. A camera module was connected to the Raspberry Pi
of the car, which live streams to a YouTube channel, so that the user has an eye inside
the house while he/she is away. The YouTube channel link was provided to the mobile
application so that the user can control and monitor his/her home in one place. The mo-
bile application has a tab that contains four control buttons that move the car forward,
backward, left and right, along with the live video stream through YouTube, so that the
user can see what he/she is controlling, and where to direct the car. The car control is
done through sending JSON strings over PubNub. If the ”Forward” key is pressed and
held on the mobile application, a JSON string message, {’car’:forward}, is sent to the
Raspberry Pi through PubNub. Accordingly, the car starts and keeps moving forward
until the ”Forward” key is released, which sends another JSON string from the mobile
application to the Raspberry Pi over PubNub, ’car’:stop}, stopping the car and mak-
ing it ready to receive another direction command the same way as forward command.
CHAPTER 4. USE CASES AND RESULTS 20
The surveillance car can be used anytime to keep an eye of the user inside the house.
If a security or safety breach is detected through the IR sensor on the door or the fire
detector for example, the surveillance car can be a moving eye monitoring the house. It
can check lively what is going on exactly, so that the user can take decisions accordingly
and effectively.
4.2 Results
Results show that everything worked as anticipated, although some high pings in the
network may cause minor occasional lag in the connection and data exchange, however,
there was no major lag detected affecting the model control and testing. The lag maybe
a casual effect of using 3G connection, however, most home automation systems employ
DSL or Broadband connection, resulting in acceptable performance. Eventually, expected
results were met.
Chapter 5
Conclusion
21
Chapter 6
Future Work
IoT is having tremendous attention recently and its various applications are growing,
changing the way we live and work. This project’s main focus was on security and safety
perspective of smart home automation, which is a small part of what can be automated
and controlled inside a smart home. Future work focus would be working on actual AC
devices to implement what was simulated in the model in a real house, developing a
more advanced motion detection algorithm on surveillance cameras, and surveillance car
moving autonomously avoiding obstacles.
As there are various appliances that can be controlled and automated while being
away from home, the same approach used in implementing this project will be used
to enable control over various appliances before reaching home, saving time and effort;
Such application examples can be, monitoring temperature and humidity, and being
able to control them, controlling stoves and microwaves, locking and unlocking doors
autonomously depending on the visitor face recognition and confidence level, surveillance
car moving autonomously reaching for a security breach or safety issue to live stream
what happens so that the user can act accordingly and many others that would combine
IoT with smart appliances autonomy.
22
Appendix
23
List of Figures
1
URL: http://iottech.dk/wp-content/uploads/2014/10/evolution-of-iot.png
2
URL: http://frikiyo.es/wp-content/uploads/2016/04/internet-de-las-cosas.jpg
3
URL: https://s-media-cache-ak0.pinimg.com/736x/8d/12/ac/8d12ac256d6fc5beebba14138423d543.jpg
4
URL:https://www.pubnub.com/wp-content/uploads/2015/03/pubsub-broadcast-design-
pattern1.png
5
URL: http://www.vilartec.com.br/img/p/50-187-thickbox.jpg
6
URL: http://img.alibaba.com/img/pb/787/831/750/750831787 329.jpg
7
URL: http://www.linuxuser.co.uk/wp-content/uploads/2014/07/RaspberryPiB+.png/
24
Bibliography
[1] Luigi Atzori, Antonio Iera, and Giacomo Morabito. The internet of things: A survey.
Computer Networks, 54(15):2787 – 2805, 2010.
[2] Nicola Bui and Michele Zorzi. Health care applications: A solution based on the
internet of things. In Proceedings of the 4th International Symposium on Applied
Sciences in Biomedical and Communication Technologies, ISABEL ’11, pages 131:1–
131:5, New York, NY, USA, 2011. ACM.
[3] L. Coetzee and J. Eksteen. The internet of things - promise for the future? an
introduction. In IST-Africa Conference Proceedings, 2011, pages 1–9, May 2011.
[4] L Heuser, Z Nochta, and NC Trunk. Ict shaping the world: A scientific view, 2008.
[5] Nurzhan Nurseitov, Michael Paulson, Randall Reynolds, and Clemente Izurieta.
Comparison of json and xml data interchange formats: A case study. Caine,
2009:157–162, 2009.
[6] Kari Pulli, Anatoly Baksheev, Kirill Kornyakov, and Victor Eruhimov. Real-time
computer vision with opencv. Commun. ACM, 55(6):61–69, June 2012.
[8] Gérald Santucci et al. From internet of data to internet of things. In Paper for the
International Conference on Future Trends of the Internet, volume 28, 2009.
[10] A. Zanella, N. Bui, A. Castellani, L. Vangelista, and M. Zorzi. Internet of things for
smart cities. IEEE Internet of Things Journal, 1(1):22–32, Feb 2014.
25