Sie sind auf Seite 1von 56

Smart Parking

Mausam Tiwari - 37448


Srison Kadariya - 37444

Work carried out under the Supervision of


Professor Leonel Domingues Deusdado
Professor Paulo Jorge Pinto Leitão

Bachelor’s in Informatics Engineering


2018-2019
2
Smart Parking

Report for the Curricular Unit of Project

Bachelor’s in informatics Engineering

Superior School of Technology and Management

Mausam Tiwari - 37448


Srison Kadariya – 37444

2018-2019
The school of Technology and Management is not responsible for opinions expressed in this
report.

4
We declare that the work described in this report is our own and it is our wish that it is submitted
for the evaluation

Mausam Tiwari - a37448

Srison Kadariya – a37444


Dedication
We dedicate this to our beloved parents for their love, support and care they have for us
throughout our lives.

6
Acknowledgement
We would like to thank you for your interest in this report. This report describes the result of
our final graduation project, carried out from September 2018 to June 2019 at Bragança,
Portugal. With this report we complete our Bachelor’s in Informatics Engineering at the
Polytechnic Institute of Bragança.

We have a plenty of people to thank for helping us complete this project. First and foremost,
we would also like to express our gratitude to our parents who are the most important part of
our lives. They are the one who made it possible to attend the Polytechnic Institute of Bragança
and who always stood behind us and our decisions. Also, we would like to thank them for the
sacrifice they made for us to give us a better future.

Secondly, we are extremely thankful to our supervisors Prof. Doctor Paulo Jorge Pinto Leitão
and Prof. Doctor Leonel Domingues Deusdado for their constant enthusiasm, straight forward
feedback and guidance that helped us stay on the right track. Their innovative idea inspired us
a lot to develop this project. Also, we greatly appreciate invaluable input from Prof. Doctor
José Fernando Lopes Barbosa.

We are also grateful to Prof. Doctor José Rufino for being supportive and caring throughout
our study at Polytechnic Institute of Bragança. And we would also like to thank every professor
at IPB. It was a pleasure to attend their lectures.
Abstract

In the present context in urban areas there are less amount of people having no private vehicles
resulting in the rapid growth of vehicles which intensifies the problem of the scarcity of parking
places. We can see these days most of the traffic congestion occurs due to vehicle drivers
struggling to find parking space. So, there is high demand of parking space in urban cities.
Consequently, traffic management and parking places are becoming hugely important as they
reduce costs, accidents and traffic congestion. At the same time, they contribute to the reduction
in pollution related problems.

For our bachelor’s degree we are given a final project to manage the parking where, a mobile
application called SmartParking running on android smartphones is developed. Our
application is intended to drivers for the purpose of searching parking spots and managing
payments.

After the completion of development, tests were made by trying to reserve the spots creating
various users and the results shows that the application meets the objective we intended.

Key-words: SmartParking, Android, Parking System

8
Table of Contents
1. Introduction ................................................................................................................................. 13
1.1. Framework ............................................................................................................................... 13
1.2. Goal ........................................................................................................................................... 14
1.3. Structure of Document ............................................................................................................ 15
2. Context & Technologies/ Tools .................................................................................................. 17
2.1. State of Art................................................................................................................................ 17
2.2. Used Technologies and Tool .................................................................................................... 19
3. Analysis and Modelling .............................................................................................................. 23
3.1. Approach .................................................................................................................................. 23
3.2 Planning ..................................................................................................................................... 24
3.3. Supporting Models .............................................................................................................. 25
4. Development/Implementation .................................................................................................... 29
4.1. Development Environment ..................................................................................................... 29
4.2. Application................................................................................................................................ 29
4.2.1. Login and Registration ..................................................................................................... 30
4.2.2. User Session ....................................................................................................................... 32
4.2.3 Reservation ......................................................................................................................... 33
4.2.5. Waiting the broker’s message .......................................................................................... 39
4.2.6. Confirming the broker recommended reservation ........................................................ 41
4.2.7. Reservation History and Future Reservations ............................................................... 45
5. Test/Evaluation/Discussion ........................................................................................................ 49
6. Conclusions .................................................................................................................................. 51
Original Project Proposal................................................................................................................... 54
List of Tables
Table 1: Time lost per day in each of the studied districts [12] ............................................................ 18

10
List of Figures
Figure 1: Mobile Operating system in Portugal in last year [14] .......................................................... 19
Figure 2: Android software layers [15] ................................................................................................. 20
Figure 3: Android Emulator ................................................................................................................... 22
Figure 4: Programming Languages used .............................................................................................. 24
Figure 5: Use Case Diagram ................................................................................................................. 25
Figure 6: Start-up Screen and registration screen ................................................................................. 26
Figure 7: Registration Screen................................................................................................................ 26
Figure 8: User session and Navigation Bar........................................................................................... 27
Figure 9: Registration page (activity_main.xml) and login page (activity_login.xml) ......................... 30
Figure 10: Users’ registration database ................................................................................................. 31
Figure 11: Code developed to check login credential ........................................................................... 31
Figure 12: Adding entries to labels table in the database...................................................................... 32
Figure 13: A piece of code for UserSession. Java and UserSession page(activity_user_session.xml) 33
Figure 14: Reservation page (activity_reservation.xml) ....................................................................... 35
Figure 15: iCalendar file used in reservation process ........................................................................... 36
Figure 16: Ical4j and JSON libraries used in reservation.java activity ................................................. 36
Figure 17: Example of MQTT architecture [21] ................................................................................... 37
Figure 18: Qos 2 architecture [22] ........................................................................................................ 38
Figure 19: Awaiting recommendation from the broker (LoadingScreen.java) ..................................... 40
Figure 20: Loading page (activity_loading_screen.xml) ...................................................................... 40
Figure 21: Broker's recommendation (activity_result_spot.xml) and spot not available at the selected
location.................................................................................................................................................. 41
Figure 22: Code to get brokers recommendation .................................................................................. 42
Figure 23: Toast to display insufficient balance ................................................................................... 42
Figure 24: Page to ask user to add credit (activity_result_spot.xml ..................................................... 43
Figure 25:Checking availability of spot after confirming ,Reservation Completion and Spot already
taken ...................................................................................................................................................... 44
Figure 26: Verifying if the user is on time ,Gate could not be opened, and Gate is opened to park .... 44
Figure 27: Google map to get directions ............................................................................................... 45
Figure 28: Code developed to create history of reservation made ...................................................... 45
Figure 29: Reservation History .............................................................................................................. 46
Figure 30: Requesting to view reservations for future use and its list. ................................................ 47
Acronyms
IPB – Instituto Politénico de Bragança

ESTIG – Escola Superior de Tecnologia e Gestão

UI – User Interface

UID – User Identification

OS – Operating System

GPS – Global Positioning System

USB – Universal Serial Bus

CPU – Central Processing Unit

SDK – Software Development Kit

IoT – Internet of Things

JDK – Java Development Kit

IDE – Integrated Development Environment

SQL – Structured Query Language

MQTT – Message Queuing Telemetry Protocol

QoS – Quality of Service

JSON – JavaScript Object Notation

AES – Advanced Encryption Standard

12
1. Introduction
In the present context, technologies are overtaking our daily life. Almost everything is
being controlled remotely through a mobile device. Cities do not escape this pattern and begin
to be controlled and monitored by devices. As the number of vehicles are being increased
intensely all around the world, parking in the cities or searching the parking areas remotely via
mobile can be helpful for people. Finding a parking place without having to spend much time
looking for it, relieves the traffic in the city and for sure saves the valuable time for the people.

1.1. Framework

The mobile application that we are developing is given the name “Smart Parking”;
which is a mobile application for very smart management of parking places for vehicles. Our
application is targeted to find vacant parking spaces with the priority to handicapped.

The main objective of our application is to consult the state of places of selected area
where the user wants to move or to park for the selected interval of time. To the user is offered
the option of selecting a suitable parking area, seeing the number of vacant parking spaces in
the particular parking lot and getting the route to the selected parking space navigating the map
that our application provides. So, the search for a vacant space is no longer a headache and
subject of worry. Even the user saves time and energy required to search the parking lots in
absence of our application and the parking lots we provide.

The application is intended for the easier movements of users to unfamiliar places,
monitoring in real time where there are vacant spaces for parking. The application is also
intended for parking regulators, who may also monitor the payments of the parking lots that
are occupied through the application.
The interface will allow the user to register and login himself in the application. Later
he can choose the vacant parking space nearby him by looking at the application’s map and
select the respective spot and pay for it. There can also be an option to select prioritized parking
space.

Finally, with the help of the application, technicians will be able to integrate new
parking places and correct errors that may exist in some sensors.

1.2. Goal

Since there are already some applications that go against the search of parking lots,
there are still very few that allow to join the inspection to the research of a parking lot. In
addition, of the applications that already exist there has not yet been one that won the market
unanimously. This way, it is possible to offer a single application that allows a driver to find a
place with ease and to pay for it, so that a surveillance agent can know through his smartphone
where all the vehicles that have not yet been controlled and that allows a technician to manage
parking sensors. With this application it is mainly intended the following objectives:

• Reduce the time spent searching for a parking lot,


• Facilitate payment and time extension of a parking lot,
• Monetize parking inspections by locating all uncontrolled vehicles,
• Manage the installed sensors in order to install, change and even remove them if
necessary.

14
1.3. Structure of Document

This report is structured as follows:

• The first chapter presents the introduction of our project which is divided into
more sub chapters; where we have described the framework and why we
develop the project and what impact it brings in the today´s smart society.

• The second chapter is about the context and technologies used in developing
the project. In this chapter we are describing about the native approach for
software development using android SDK, Android Studio as IDE and Java
for programming language. We also have presented about the previously
done projects and what we learned from those projects in section “State of
Art”.

• The third chapter presents the project architecture and solution design,
including the various types of support. We also have presented the prototypes
and used case diagram.

• The fourth chapter describes all the development aspects and libraries used.

• The fifth chapter is about the discussions of the difficulties that occurred
during the development process of our application and its evaluation.

• The sixth chapter presents the conclusions and future works that may be
carried out.
16
2. Context & Technologies/ Tools

2.1. State of Art

Today we are living in a world where the concept of smart city begins to evolve. In
every single of period of time, we are getting something that is controlled remotely through the
touch of our finger in our mobile devices and there, Smart Cities are no exception. In the present
context there are a lot of studies for controlling the cities in a smart way which can facilitate
the life of the residents, the people who work or study and of those who travels.

Sensors are already being started to deploy for detecting the vehicle in a parking area.
These sensors make possible to know if a parking place is occupied or free. Giving the status
of the parking area to any individual lets him find the spot quickly and easily. But the part of
sensors is being developed by other colleagues. Recently many countries in Europe and USA
have implemented the project Smart Traffic technology where Smart Parking comes to stay.
As Smart Cities came to stay, Ubiwhere [1] along with Micro I/O [2] and Wavecom [3] created
Citibrain [4]. Citibrain is currently creating 4 solutions, Smart Parking [5]; which we are going
to present in this report, the Smart Traffic [6]; which solves the problem of traffic management
in urban environment in an intelligent, adaptive and non-invasive manner, Smart Waste [7] and
Smart Air Quality [8].

The study [9] reveals that a car passes 95% of its lifetime being parked while only 5%
in circulation, which is why parking lots are one of the areas targeted by the Smart Cities. If
we analyse the traffic caused in a big city, we conclude that it is caused by the one who has
arrived at the destination rather than who is in their route. 30% of traffic is caused by the
people who are searching for a proper parking spot. Keeping this information in mind, we can
realize that to reduce the traffic in a city, parking is an important factor to consider.
In our project we are going to present a solution to a problem described before,
integrating it into what we call now Smart Cities. This intelligent system of parking vehicles
was developed in Ubiwhere, LuxMobility [10] and Smart Parking [11] and was integrated in
the solution of Smart Parking as we have previously presented.

The search of the parking lot is one of the most unpleasant points of the time, so it is
important to make all this time as much pleasant as possible. In this report, we will be trying
to find a faster method to find a parking spot in a best possible way without having look for a
parking for an unpredictable period. From a research done in [12], 100% of the inhabitants of
Paris have already given up at least once of a displacement by lack of parking. Adding the lost
daily time in search of a free space in authorized places in the district of Saint-Germain comes
to 294 hours and 462 hours in the neighbourhood of Commerce as the table in Figure 1
illustrates. Analysing the whole France in general, some 70 million of hours are lost every year
in search of a parking lot, which represents around 700 million euros lost every year, all without
looking at the traffic, pollution and greenhouse effect caused by all these vehicles.

Total Time Lost Lost Time Per Lost Time per


Hectare authorized space
Lyon district 434h 14h 14min 41min
Presquile

Grenoble district 157h 6h 21min 14min


Vaucanson
Paris district 462h 9h 57min 20min
Commerce
Paris district Saint- 294h 13h 40min 42min
Germain

Table 1: Time lost per day in each of the studied districts [12]

18
2.2. Used Technologies and Tool

Smartphones are becoming small extensions of us and send messages about who we
are to those around us. Our phones are now an integral part of our lives and we’re more mobile
than ever. One of the most recent Mobile App Reports from comScore [13] indicates that: We
now spend 50% of our digital media time in smartphone apps. And, the recent statistics [14]
for the mobile operating systems used in Portugal shows that there about 74% of android user,
approx. 25% of IOS users. So, we planned to develop an application that can be used with ease
by most of the mobile phone users.

Figure 1: Mobile Operating system in Portugal in last year [14]

Android is a popular computing platform based on the Linux® operating system. The
initial commercial version of Android hit the market in 2008 in the form of a mobile phone
platform, back when the most popular cell phone for a business user was the BlackBerry, when
the iPhone was beginning to make meaningful waves across all sectors, and when the majority
of phone users were still tapping out texts from a flip phone.
Figure 2: Android software layers [15]

Figure 2 displays a simplified view of the Android software layers:

• Applications: Built-in applications, such as phone, contacts, browser, and more.


The specific applications vary by Android version and manufacturer.
Commercial applications from marketplaces, such as Google Play, Amazon,
and more. Side-loaded applications, including the ones you will build. You
install these via USB cable.
• Application frameworks, such as telephony manager, location manager,
notification manager, content providers, windowing, resource manager, and
more.
• Libraries, such as graphics libraries, media libraries, database libraries, sensors,
and so on.
• The Android runtime is responsible for executing and managing applications as
they run.
• Linux Kernel, including power, file system, drivers, process management, and
more.

An Android application consists of one or more of the following four classifications:

20
• Activities: An application that has a visible user interface is implemented via an
activity. When we select an application from the Home screen or application
launcher, an activity is started.
• Services: We can use a service for any application that needs to persist for a
long time, such as a network monitor or update-checking application.
• Content providers: The easiest way to think about content providers is to view
them as a database server. A content provider’s job is to manage access to
persisted data, such as the contacts on a phone. If your application is very
simple, you might not necessarily create a content provider, however if you are
building a larger application or one which makes data available to multiple
activities and/or applications, a content provider is the proscribed means of
accessing your data.
• Broadcast receivers: You can launch an Android application to process a
specific element of data or respond to an event, such as receiving a text message.

The easiest way to get started with developing Android applications is using the
Android Studio application suite [16]. Android Studio includes tools for managing multiple
platform-specific features with the SDK Manager and the ability to test your application on
either a real device or the emulator.

Coding in Java within Android Studio is intuitive because it provides a rich Java
environment, including context-sensitive help and code suggestion hints. After you compile
your Java code cleanly, the components of Android Studio make sure all the application is
packaged properly, including the AndroidManifest.xml file.

The SDK manager, which ships as an integrated experience of Android Studio,


manages the download of the numerous elements of the Android SDK.

You can run Android applications on a real device or on the Android Emulator, which
ships along with the Android SDK. Figure 3 shows the Android Emulator’s home screen.
Figure 3: Android Emulator

22
3. Analysis and Modelling

3.1. Approach

Android and iOS are the two obvious leaders in the mobile operating system. Google
Play Market has twice as many downloads than Apple’s App Store. Also, when viewing in
context of Portugal, most of the users are using the Android OS than the Apple’s iOS. This
also motivates us in developing an application for Android.

While developing an application, there can be two different approaches, Native and
Hybrid. Native development focuses in the use of platform-specific programming languages,
Software development kits, development environment and other tools provided by the OS
vendors which results in smooth performance, speed, better user experience data protection
and security, flexibility and personalization. Where as, hybrid application development focuses
to create a single app for use on multiple platforms like Android, iPhone and Windows.
Applications developed based on hybrid approach are basically web-based program put in a
native app shell and connected to the device hardware. As, they add an extra layer between the
source code and the target mobile platform, more particularly the hybrid mobile framework. It
may result in loss of performance. They also make debugging a bigger affair. And is difficult
to maintain a proper user experience between the Android and iOS apps.

In our application development, we are focusing on native approach. In native android


development, Java is the Programming Language, Android Studio is the IDE and Android SDK
is the Software Development Kit. This can also be viewed in the figure 4. Native apps can use
100% of the features available in a certain OS and respective devices.
Android

Programming language Java, Kotlin

Integrated Development Kit (IDE) Android Studio

Software Development Kit (SDK) Android SDK

Database Management System (DBMS) MySQL, Google Cloud SQL

Figure 4: Programming Languages used

3.2 Planning

For the beginning of the development of this application, we are first creating few
prototypes which will represent in the closest format that how the application will look alike.
These prototypes can help us for design of the UI. We are also creating a use case diagram for
understanding better of what user will be able to do when he uses the application. We want to
have an application where the user can first make the registration of himself by providing his
personal data. After the registration process completes, the user can login into the application
and use the further feature. Following the login process, user can be able to edit his profile and
most importantly can make the reservations. User will search for a parking slot. In this process,
the user selects the desired location, reserves it and views the location of the spot navigating
the map. He can select the date, time. He can pay from the application his parking bills and
view the history of the previous reservations and the reservations that are made for the future
use.

24
3.3. Supporting Models

In the next pages, there are few models which helps in the development of the application.
Figure 5 is a use case diagram where it is shown the user as the actor of the system. In this
figure, the various activities that can be done by the user in the application is represented.
Figure 6 is the prototype for the initial page that can be viewed when the application launches.
There are two buttons, Register and Login. Tapping on Login button redirects to the next page.
Here, user enters the credentials and enters the application and visits the new page that is shown
in figure 7. When user reaches this page, he can interact with application by tapping on
hamburger navigation button ( )and use the various available options.

Figure 5: Use Case Diagram

Figure 6 and 7 are screenshots of prototypes taken from our application and figure 8 is
the prototype we designed for future development.
Figure 6: Start-up Screen and registration screen

Figure 7: Registration Screen

26
Figure 8: User session and Navigation Bar
28
4. Development/Implementation
This section will describe all the development aspects and the libraries used. It will also be
explained the approaches taken to develop the final product and how were the libraries used.

4.1. Development Environment

The application was developed in the windows operating system 10. As our application was
developed in Java, it was necessary to install a copy of latest OpenJDK which came bundled
with Android Studio which is documented on the Android Studio website [16].

In this way the application was developed in a native approach facilitating easy access to all
the services and features offered by the OS of the device. Also, apps developed using the native
approach consume device´s resources (CPU, battery, memory) more efficiently. The code
development was done using Android Studio IDE. Our application is intended to run in android
smartphones.

4.2. Application

Here, it is explained how the application works to describe what has been developed and how
the objectives intended are met.

When starting the application for the first time, the users can login and enter the registration
page. If they are not already registered, they can register themselves by clicking the register
button which redirects them to the registration page.

Regarding the parking system, the driver is provided with a list of parking areas which he/she
can select. When choosing the parking space, the space must be free. After the selection
process, our user gets a message if the area is free or occupied. If it is free, he can select the
desired slot and proceed. If not, he/she must select another space suggested by the agent.
4.2.1. Login and Registration

When initializing the application, the user will be able to Login if already registered. If not
he/she must register themselves which is done by navigating through the registration page
which is coded in the MainActivity.java class. In order to go to the registration page user
selects the register button.

First, lets talk about the registration process. For the users to register themselves they need to
fill in their details. The figure of the registration page and login page is shown below.

Figure 9: Registration page (activity_main.xml) and login page (activity_login.xml)

The user must enter his/her first name, last name, email address, password and phone number.
The entered credentials are then saved in our application’s database forming a row which is
shown in the figure below. We have also used Advanced Encryption Standard (AES) [17]
which is a symmetric encryption algorithm to encrypt the passwords for security purpose. If
any of the fields are left empty a toast is thrown which warns to fill all the fields. The figure

30
presented below is taken from our application’s database of registration page. It is created from
online SQLite Browser [18].

Figure 10: Users’ registration database

After the successful registration process, the page is re-directed to login page which is coded
in the Login.java activity where required credentials must be entered. The user enters his email
id and his password which he had set during the registration process. The password entered
here in the login process is again encrypted and is compared to the password that was encrypted
during registration within the database. If the credentials including both the encrypted password
match, users are logged in to the application. The fields should not be left empty as the
application throws a warning to provide the credentials. And the provided credentials must also
be same as entered in application´s database.

Figure 11: Code developed to check login credential


4.2.2. User Session

Login process follows the user session page which is UserSession.Java in our application.
This page works as the home page for our application. In this page user can make reservations
for the parking space. It is also possible to add credits and view all the parking history. Initially
credits for every user is zero in the database during the registration process and history table is
not created.

At this stage our database is empty. We only have registration table in our database. Here in
the UserSession.java we created necessary databases to push to reservation.java activity so
that it will be easy to fetch those databases afterwards.

Figure 12: Adding entries to labels table in the database

Here in this piece of code we have created five labels which are mainly the name of the
locations for parking space with their respective latitude and longitude. It is created already in
this activity so that the fetching of the database is easier when we navigate the
Reservation.java activity. A separate table of locations is created in our database for this
purpose.

32
Figure 13: A piece of code for UserSession. Java and UserSession page(activity_user_session.xml)

4.2.3 Reservation

When the application user touches on MAKE NEW RESERVATION button, he gets
navigated to a new page. In this page he can make the reservation. He will first select a location
where he wants to park his vehicle. These locations are fetched from the database and these
locations consist of id, name, latitude and longitude but for now, only names are fetched. For
fetching these data, we have created a method to load these entries from database and is shown
in the control Spinner. After this, user will select the priority for the location he selected. The
priorities are low, medium and high. When a user selects a high priority, it refers that the user
really needs to park at that specific spot but on selecting the higher priority, user might get
higher prices in the end. When user selects low priority, a string is generated stating
“conservative”, on selecting medium, “moderated” is generated and on selecting high,
“aggressive” is generated. This is done also for the negotiation purpose. Following the priority
selection, user chooses the vehicle he would like to park ,that is the user has the choice to park
either bikes or cars and selects his desired spots. In our system we have mainly 5 locations each
having 6 spots. After this selection, user will provide the maximum amount he is willing to
pay for the spot. This amount ranges from 1 to 15 euros. Then after that, user provides the
distance range for the spot which means how far can the spot be from where he has selected. It
ranges from 0 to 1000 metres. The input provided by user is also converted to number. When
range from 0 to 250 is received, it is converted to 1, receiving 250-500 is converted to 2,
receiving 500-750 is converted to 3 and receiving 750-1000 is converted to 4. After this, user
selects the start date for the parking. Here we are using DatePicker control to get our data.
User selects Month, Day and Year from this control. Then we use the same control so that user
can select the end date for the parking and then selects end Month, end Day and end Year.
These selected day, month and year are converted into the integers in the back end. Then user
gets to select the Start Time for the parking. We are using the control TimePicker. Here user
selects the hour, minute and if it is am or pm as we are using 12-hour format. Then user selects
the end parking time from the same control and provides the end hour and minute in 12-hour
format. These times are also converted to integer in the backend, but the hours are then
represented in the 24-hour format. After this, we ask to user, what matters to him the most by
using a RadioButton control. User here selects if he cares more about the location or cares
more about the price or it doesn’t matter to him. Here, the user selection is converted into the
price weight and location weight. In our case price weight and location weight works like this,
if user selects best location, price weight gets value of 40 and location gets value of 60. If user
selects best price, price weight gets value of 60 and location gets value of 40 and if user selects
It doesn’t matter, price weight gets value of 50 and location gets value of 50. These conversions
are also made for the negotiation purpose. By getting all this information, our reservation
process can continue. User then touches on MAKE THE RESERVATION! button. When
this button is touched, data is computed, verifications are made, calendars are generated and
published to MQTT Broker. We first check if the field Amount willing to pay for spot and
Distance range for spot are filled or not. If not, a toast in the screen is displayed which says the
user to fill the respective fields. Then we check if the amount ranges from €1 to €15 or not and
check if the distance range from 0 meter to 1000 meters. If they are not specified as required,
those data are not processed, and a toast is displayed to user to make those inputs correct. Our
Date Picker control doesn’t let the user to select the date that was from the day before or before
that. An overview of reservation is displayed in the figure below.

34
Figure 14: Reservation page (activity_reservation.xml)

After all of these are verified, we convert these data to JSON object. In JSON object, we put
start day, start month, start year, end day, end month, end year, start hour, start minute, end
hour, end minute, location id, latitude and longitude from table labels from database for the
location that user selected, price weight, location weight, priority as the user profile, distance
range, user id, maximum price, distance range and message id whose default value will be 1.
We convert this JSON object to String. Also, we create a new calendar of ical4j data type
which consist of start and end dates, and user Id.

Let’s discuss briefly about iCalendar [19]. It is a standard method of transferring calendar
information between computer systems. The standard allows products from many vendors to
transfer calendar information between each other. An iCaendar file consists of sections starting
with “BEGIN:” and ends with “END:”. The “VCALENDAR” is the global section that holds
all other sections. Other sections include “VEVENTS” for events, “VTODO” for to-do items,
“VJOURNAL” for journal entries and “VTIMEZONE” for time zone information.
Figure 15: iCalendar file used in reservation process

A calendar file is created for reservation event where spot id is 963, sector1 is the parking area
where 1 is the location id, starting time is 20 of July 2019 20h52 and ending time is 20 of July
2019 21h52.

Here in our application we have used iCalendar of iCal4j [20] data type. It is a java library used
to read and write iCalendar data streams.

Figure 16: Ical4j and JSON libraries used in reservation.java activity

After this, we establish the connection with MQTT Broker. Let’s have an overview of what
MQTT is and how it works.

MQTT (Message Queueing Telemetry Transport) is the standard messaging and data exchange
protocol for Internet of Things. This technology provides a scalable and cost-efficient way to
connect our devices over the internet. It can deliver data over the internet in near real-time and
guarantees the delivery. Connecting millions of Iot devices to the business infrastructure,

36
sending instant updates and moving data efficiently is where MQTT truly excels. It is designed
for Iot devices – lightweight on the wire, enabling low cost device communication that scales
the business. MQTT keeps bandwidth at an absolute minimum and deals with unreliable
networks, requiring little implementation effort for the developers.

Figure 17: Example of MQTT architecture [21]

The core goals of MQTT as listed below has made it the best client server publish/subscribe
messaging transport protocol.

• Simple implementation
• Quality of service data delivery
• Lightweight and bandwidth efficient
• Data agnostic
• Continuous session awareness
Here we are going to explain shortly about “Quality of service data delivery” goal of MQTT.

The Quality of Service (QoS) level is an agreement between the sender of a message and
receiver of message that defines the guarantee of delivery for a specific message. There are 3
QoS levels in MQTT:

• At most once (0)


• At least once (1)
• Exactly once (2)

When we talk about QoS in MQTT, we need to consider the two sides of message delivery:

• Message delivery from the publishing client to broker.


• Message delivery from the broker to subscribing client.

As we have implemented exactly once (2) level of QoS in our application, lets take a closer
look how does it work.

QoS 2 is the highest level of service in MQTT. This level guarantees that each message is
received only once by the intended recipients. QoS 2 is slowest but the safest quality of service
level. The guarantee is provided by at least two request/response flows (a four-part hand shake)
between the sender and receiver. The sender and receiver use the packet identifier of the
original PUBLISH message to coordinate the message delivery.

Figure 18: Qos 2 architecture [22]

We are using MQTT protocol in order to send and receive messages. Here we will be creating
a topic in a specific MQTT broker. We will publish some messages in the topic and the one
who are subscribed to that topic will receive those messages. We will also subscribe ourselves

38
to those topics in order to receive the reply and perform actions accordingly. For establishing
the connection with MQTT, we first define the MQTT broker’s address and port. We then
create MemoryPersistence so that we can use this memory in case the device or user restarts
the memory. Then a MQTT client is created with broker address with TCP, with a generated
client id and a MemoryPersistence. Then we set the MQTT clean session value to true so that
the server will treat the subscription as non-durable. After this, the JSON String that we created
previously from JSON Object is used as our message content to publish in the topic. We create
a new topic in the connected broker with the name SmartParkingIPB and we publish our
message to that topic and the subscribers receive the message. Then we disconnect this created
client. We then navigate to the next page/activity/class with the name LoadingScreen.java
sending few data from this class and those data are userId and created calendar string. We will
need them in upcoming pages either for communication or for data processing.

4.2.5. Waiting the broker’s message

After the user requests the reservation for any parking spots, a message is sent to the broker.
And user expects the same details in the form of string from the broker. The broker then sends
the message in form of JSON strings with the details including the price recommended for
reservation, location id and the id of received message. We convert those arrived JSON strings
to a json object and access the values of the respective keys and store them in our page’s
variables. After negotiation, the broker recommends the spot with the price accordingly
analysing the details send by the user himself. We then send all these captured values to the
next page to display the results to the user. For this message receiving process to happen, we
again establish the connection with the MQTT Broker and then we implement
MQTTCallBack which automatically generates 3 different methods and they are
connectionLost, messageArrived and deliveryComplete. For now, we will be using
messageArrived method. In this method, when a message is published to the topic that we are
subscribing, we will receive those messages as string, and we can continue to work with that
string inside this method. We cannot pass these values to any of our variable outside the method
so we should continue our task inside this method. An overview of the method is shown in the
figure 19.
Figure 19: Awaiting recommendation from the broker (LoadingScreen.java)

Figure 20: Loading page (activity_loading_screen.xml)

40
4.2.6. Confirming the broker recommended reservation

After the request is processed, users get the recommendation message from the broker with
the location, spot number and price which is calculated by the broker automatically. This
recommended process is already processed in LoadingScreen page and is shown in this
ResultSpot page where the user has the option to agree the broker recommended location and
confirm the reservation or cancel the request made before and may proceed to request a new
reservation again. If there are no spots left at the user selected location, he can navigate to the
UserSession page by selecting Home button to perform the reservation process all again.

Figure 21: Broker's recommendation (activity_result_spot.xml) and spot not available at the selected location
Figure 22: Code to get brokers recommendation

On clicking the confirmation button, users account balance is checked and if the user has
enough balance, he may proceed with confirming the reservation which results in the reduced
account credit and the user’s credit is updated. The database is checked thoroughly if the credit
is enough. If balance is inferior, a recharge button appears which re-direct the user to a page
where he can recharge their account balance. The recommendation received is cancelled as
there is not enough credit.

Figure 23: Toast to display insufficient balance

42
Figure 24: Page to ask user to add credit (activity_result_spot.xml

After confirming the reservation, we again establish the connection with the MQTT Broker as
we did when we requested to reserve the spot the same process is implemented here. But user
also gets false response from the broker. During the process, broker checks if the spot requested
by the user is still available or not. If the spot is not available, he gets a negative response
saying, “the spot is already taken”. User must repeat the process of reserving the spot. For
doing this he selects home button and navigates to UserSession page where he proceeds to
reserve the spot again.

In case everything is okay, and the requested spot is free, the reservation is completed
redirecting user to ReservationCompletion page. Here, user can view the location of the
confirmed spot. For this purpose, we have used google maps to get the directions to parking
spot.
Figure 25:Checking availability of spot after confirming ,Reservation Completion and Spot already taken

When user is ready, he asks to use the parking slot by selecting USE PARKING SPOT
button. A message is sent to MQTT broker to verify if he is at the correct time analysing the
previously formed iCalendar. If he is on time the gate is opened else gate is not opened and
he/she must make the reservation all again.

Figure 26: Verifying if the user is on time ,Gate could not be opened, and Gate is opened to park

44
Figure 27: Google map to get directions

4.2.7. Reservation History and Future Reservations

There is also possibility to view reservations history. From the UserSession page a user can
select the History button and can review all his/her reservations made. INNER JOIN query
of SQL appeared to be very useful here in getting the matching values from multiple tables to
create a new table in the database as shown in the figure 28.

Figure 28: Code developed to create history of reservation made


Figure 29: Reservation History

User can also request multiple reservations at a given time and can use those reservation for
future use which can be viewed by selecting View Reservations button. Before this page is
loaded, a message is published into the MQTT broker specifying the user id and message id.
When a subscriber (in this case, the spot agent) receives this message, he analyses which user
is requesting the history of the reservations and replies accordingly by publishing another
message in the same topic of the server. This message is received in our application in form of
JSON array string. This string is converted into JSON array and analysing this string, the start,
end date and location id is converted into a single string and treated as a single event. All these
events are read and then stored in an ArrayList. This ArrayList is then forwarded to the next
page which is ReceivedReservationHistory. When this page gets loaded, all the data from
previous page is analysed. An ArrayList is received from the previous page and is store in this
page. Each string from the list is treated equally and all the data consisting inside the string is
extracted. The string consists of start and end date which can be used to generate the array of
the iCalendar. The array of iCalendar is generated analysing the ArrayList and is published into
a specific topic of the MQTT server as soon as the end of ArrayList is found. Not only this, the
start date and the location id are also used to display in the UI as a list for the user to select one

46
of the reservations. The name of the location is retrieved from the location id which is received
from the previous intent and then a proper list in the UI is displayed which include the start
date and time of the parking event with the location name. User then selects one of the events
from the list in this intent and then requests to open the gate of his spot. User clicks a button to
perform this action and on clicking this button, one more message is published into the topic
which denotes that user wants the gate to be opened and moreover, a new intent is loaded with
the name LoadingOnlineGate. Here in this intent, the spot agent analyses the array of the
iCalendar sent previously and checks which of the events user wants to interact with. Then the
spot agent if user arrived at the correct time for that event or not and then replies with true or
false in the application by publishing the message into the same topic. When the message is
received, the application gets redirected to the intent SpotSuccess which was created
previously alongside with the message true or false. Then the actions are performed
accordingly.

Figure 30: Requesting to view reservations for future use and its list.
48
5. Test/Evaluation/Discussion

This was our first work developing a mobile application. We were making it for android which
is a mobile operating system developed by Google. We were using Java for development. We
weren't experienced about this programming language as our previous projects were created
using C#, PHP and JavaScript and we had difficulties during the development of the project.
Let's start from the database point of view. Android uses SQLite for a relational database
management system. In Java, the database can be created in two ways, either by using the
inbuilt classes and pushing the entries to the table using those classes or by using the SQL
queries. For our project development, we used both ways to create our database to learn better.
Here, during some table's creation, we found the tables weren't created because for the tables
to be created, the onCreate() method from that specific class had to be called as well or some
other method from the same class that calls onCreate() method should've been called. In the
first week of development, we were updating our database and the application was crashing.
Here we realized, whenever we update our database, we had to reinstall the application with a
new database removing the previous version. This was the part of the database. While talking
about the value passing from one class to the other, the values were received as null in the new
class. We here realized that it can be done by using putExtra() to send the value and getExtra()
to receive the value. The method putExtra() had to be called during the intent from one class
to the other. Moreover, in this project, we were using MQTT messaging protocol and this was
new to us. We were always designing an offline project without any communication but here,
we were publishing and receiving the messages and perform the actions accordingly. Before
doing so, we had to know what MQTT was and how it worked. We had to import an external
library which is a part of org.eclipse.paho.client.mqttv3. The message publishing wasn't a
problem because the name of the topic was what we wanted to have and, we were using public
broker address broker.hivemq.com:1883 for the testing. The problem was with the message
receiving. MQTT automatically implements three methods, messageArrived(),
deliveryComplete() and connectionLost(). Here in these methods, we can act independently.
Whenever someone was publishing to a topic that we were subscribed to, the message was
arriving in the messageArrived() method. We were trying to pass these values to a global
variable and work with that in a different method, but it was not possible. The task had to be
done there as the message receiving process was continuing there unless a stop condition was
reached. So, we continued our work in the messageArrived() method. Also, while message
passing, we were using iCalendar format to publish the messages. This format was also new to
us and we had to also import an external library which was provided by net.fortuna.ical4j. We
had to study what this format was and what data belongs to which segment of the formatting.
We learned about it and converted our date and time of the code to this format and published
it in our MQTT topic. The last but not the least difficult that we had was during receiving a
user's list of reservations. The received message was in JSON array format but was arriving as
a string. We had to parse this to a JSON object and convert this array to a list. The solution
developed was, we were concatenating the start and end time's JSON object to a single string
and adding it to an ArrayList. We were then this list to a different intent and then we worked
with this list using a loop and for every single list item, we were generating an iCalendar event
string. This part was tricky as we had to convert a single string into more different formats. We
were using String.split() in a single string and storing its divided part as a new array to solve
this issue. Overall, facing all these problems and challenges, we were able to learn even new
things such as MQTT and iCalendar, learn how to make a mobile application by
communicating with multiple agents and we also improved our programming skills at the end
of this work.

50
6. Conclusions

Technology runs our lives these days. Smart phones, tablets and computers - we really can’t
seem to function with out them. In a short period of time, technology has exploded in the
market and now, many people cannot imagine a life without it. And to accompany these new
technologies, it is now possible to use a single device and operate them remotely. Smart cities
are gaining strength in our society and becoming the future.

The main goal of our bachelor’s project to develop an application that can be used simply and
conveniently to search for parking spots. With the help of our application people can look for
parking spots, pay for it and manage their time from their personal mobile phones.

Before the beginning of the project we were given the freedom to choose to create, either
android or iOS application according to our choice. Taking into the account that the objective
of the project was to make parking smart and easy to every user we choose android platform
as the percentage of android users is way greater than iOS users and is easy to use.

And, from personal point of view, with this project we gained a lot of experience in making
an application which can be used in real life. Whatever the difficulties occurred we now
know can create an application based on the technology which is just emerging.
52
Bibliography
[ 1 ] “Ubiwhere” https://www.ubiwhere.com/
[ 2 ] “Micro I/O.” https://microio.pt/en/
[ 3 ] “Wavecom.” https://en.wavecom.pt/
[ 4 ] “Citibrain.” http://www.citibrain.com/en/
[ 5 ] “Smart Parking” https://www.citibrain.com/en/solutions/smart-parking/
[ 6 ] “Smart Traffic.” http://www.citibrain.com/en/solutions/smart-traffic/
[ 7 ] “Smart Waste.” http://www.citibrain.com/en/solutions/smart-waste/
[ 8 ] “Smart Air Quality.” http://www.citibrain.com/en/solutions/smart-air-quality/
[ 9 ] R.E. Knack, “Pay as you park”, Planning, vol. 71, no. 5, pp.4-8,2005
[ 10 ] “LuxMobility.” http://www.luxmobility.eu/parking.html
[ 11 ] “SmartParking.” http://smartparkingsystems.com/en/smart-parking-system/
[ 12 ] E. Gantelet and A. Lefauconnier, “The time looking for a parking space: Strategies,
associated nuisances and stakes of parking management in France,” Proc. ETC, pp. 1–7, 2006.
[ 13 ] “ComScore.” https://www.comscore.com/Insights/Blog/Smartphone-Apps-Are-Now-
50-of-All-US-Digital-Media-Time-Spent
[ 14 ] “Statcounter.”http://gs.statcounter.com/os-market-share/mobile/portugal/#monthly-
201801-201901-bar
[ 15 ] “Android Software Layers”. https://developer.ibm.com/articles/os-android-devel/
[ 16 ] “Android Studio”. https://developer.android.com/studio
[ 17 ] “AES”. https://aesencryption.net/
[ 18 ] “SQLite Browser”. https://sqliteonline.com/
[ 19 ] “Icalendar”. https://icalendar.org/
[ 20 ] “iCal4j”. https://github.com/ical4j/ical4j
[ 21 ] “HiveMQ”.https://www.hivemq.com/blog/mqtt-essentials-part-1-introducing-mqtt/
[ 22 ] “QoS2”.https://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-
levels/
Appendix A

Original Project Proposal

54
Curso de Licenciatura em Engenharia Informática
Projeto 3º Ano - Ano letivo de 2018/2019

SmartParking
Supervisor: Leonel Domingues Deusdado
Paulo Jorge Pinto Leitão

1 Research problem

This project intends to develop a UI application to run on mobile devices, which allows users to access
to the system and consult the current state and to make among others, reservations of parking slots.

2 Solution proposal

The SmartParking project aims to develop a cyber-physical system, based on multi-agent systems, for
intelligent parking in car parks and bicycles. This type of system consists of numerous devices (parking
devices and users) that have intelligence and autonomy, and in which the overall behaviour emerges from
the interaction between the individual devices.
Intelligent management of parking devices is based on negotiation between parking devices (which
provide a parking space) and users (who wish to use parking spaces), and their efficiency requires
knowledge of the occupancy forecast of parking devices based on user profiles.

3 Project development strategy

• Requirements analysis for the approach to the objective.


• Study of the technology of the technology to be implemented.
• Prototyping and definition of the development model.
• Implementation, product testing and interface.
• Writing the Report.

Team size: 2 Students


Resources: PC + Software
56

Das könnte Ihnen auch gefallen