Smart MiniBar using Raspberry Pi for Hotelier Industry [631885]
UNIVERSITY “POLITEHNICA” OF BUCHAREST
FACULTY OF ENGINEERING IN FOREIGN LANGUAGES
ELECTRONIC ENGINEERING, TELECOMMUNICATIONS AND
INFORMATION TECHNOLOGIES – APPLIED ELECTRONICS
DIPLOMA PROJECT
Project coordinator:
Prof. Dr. Ing. Nicolae GOGA
Bucharest
2018 Student: [anonimizat] “POLITEHNICA” OF BUCHAREST
FACULTY OF ENGINEERING
IN FOREIGN LANGUAGES
ELECTRONIC EGINNEERING,
TELECOMMUNICATIONS A ND INFORMATION
TECHNOLOGIES
Project coordinator Student: [anonimizat]. Nicolae GOGA
Ștefan VOICU
Bucharest
2018 Smart MiniBar using Raspberry Pi for
Hotelier Industry
“POLITEHNICA” UNIVERSITY OF BUCHAREST
FACULTY OF ENGINEERING IN FOREIGN LANGUAGES
ELECTRONIC ENGINEERING, TELECOMMUNICATIONS AND INFORMATION
TECHNOLOGIES – APPLIED ELECTRONICS
Approved
Director of department:
Prof. dr. ing. George DRAGOI
DIPLOMA PROJECT THEME FOR :
Voicu Stefan
1. Theme title:
Smart MiniBar using Raspberry Pi for Hotelier Industry
MiniBar Smart folosind Raspberry Pi pentru industria hotelieră
2. Initial design data:
– Data related to hotelier industry
– Smart algorithms data
3. Student: [anonimizat]:
Implementation of the smart system
Software Development on the Raspberry Pi
Development of the Reception Application Software
4. Compulsory graphical material:
Block scheme, functioning diagram, graphs
5. The paper is based on the knowledge obtained at the following study courses:
Object-oriented Programming, Computer Networks
6. Paper development environment:
Microsoft Word
7. The paper serves as:
Bachelor Thesis
8. Paper preparation date:
June 2018
Project coordinator Student: [anonimizat]. GOGA Nicolae VOICU Stefan
Academic Honesty Statement
I, Voicu Stefan, hereby declare that the work with the title “Smart MiniBar using
Raspberry Pi for Hotelier Industry”, to be openly defended in front of the diploma theses
examination commission at the Faculty of Engineering in Foreign Languages, University
"Politehnica" of Bucharest, as partial requirement for obtaining the title of Engineer is the
result of my own work, based on my work.
The thesis, simulations, experiments and measurements that are presented are made
entirely by me under the guidance of the scientific adviser, without the implication of persons
that are not cited by name and contribution in the Acknowledgements part.
The thesis has never been presented to a higher education institution or research board
in the country or abroad.
All the information used, including the Internet, is obtained from sources that were
cited and indicated in the notes and in the bibliography, according to ethical standards. I
understand that plagiarism is an offense and is punishable under law.
The results from the simulations, experiments and measurements are genuine.
I understand that the falsification of data and results constitutes fraud and is punished
according to regulations.
Stefan VOICU [Date]
[Signature]
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
1
Table of Contents
1 Introduction ………………………………………………………………………………………………………… 2
1.1 Motives ……………………………………………………………………………………………………. 3
1.2 Advantages …………………………………………………………………………………………………… 4
2 Presentation of the Domain ……………………………………………………………………………….. 5
2.1 Internet of Things (IoT) ……………………………………………………………………………… 5
2.2 State of the Art ……………………………………………………………………………………………… 6
3 Smart Minibar Module. Presentation of the system ……………………………………………………. 7
3.1 Raspberry Pi …………………………………………………………………………………………………. 8
3.2 Barcode laser scanner …………………………………………………………………………………… 14
3.3 Ethernet vs. Wi-Fi ……………………………………………………………………………………….. 18
3.4 Graphical User Interface (GUI) …………………………………………………………………….. 19
4 System implementation ………………………………………………………………………………………. 21
4.1 Python ……………………………………………………………………………………………………….. 21
4.2 USB connection of the laser scanner ……………………………………………………………….. 24
4.3 Database …………………………………………………………………………………………………….. 26
4.4 Web programming ……………………………………………………………………………………….. 33
5 Conclusions………………………………………………………………………………………………………. 45
References ………………………………………………………………………………………………………….. 47
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
2
1 Introduction
As the technology is evolving as days go by, the everyday products are starting to be
produced with a lot of modern features which are making the life much easier for everyone.
The home appliances, the everyday accessories are being brought to life using diverse
technologies which are in continuous development.
Recently, I went to a five-star hotel and I was feeling like I want to drink something.
But there was a problem: the beverage I wanted to drink was not present in the minibar, but it
was written in the menu, so it was supposed to be in the minibar. In that moment, the concept
of the Smart MiniBar module was starting to take shape.
The little black box that is supposed to be fixed in the back of the minibar needs only
a connection to the hotel’s network, a barcode laser scanner and it should start working like a
charm.
The main features of the module are that the customers are ordering the products in
the minibar in real time, the employees of the hotel are continuously in touch with the
customer’s needs and the most important feature of the module: the customer can pay less on
the products due to the lower taxes of the products.
Having this module in a hotel is very good because it makes the life easier for the
employees. Just think about the Cleaning Department, how much time is wasted by checking
each room on each floor every day.
For the hardware part I decided to use a Raspberry Pi 3 Model B connected to a Local
Network using Wi-Fi and a USB Barcode Laser Scanner made by Winson connected through
an Ethernet port to the Raspberry Pi. I managed to develop the software of those previously
mentioned using Python programming language for the Raspberry Pi and PHP, HTML,
Bootstrap and MySQL for the Graphical User Interface used on the computer located at the
reception of the hotel.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
3
1.1 Motives
Since the ancient times, the hospitality industry was offering its facilities to the
travelers and this has been a feature from the first civilizations. As the time goes by, the
hotels have been started to be characterized by their level of luxury.
Taking this information into consideration, according to a hotel’s levels of luxury, it
can achieve a number of stars taking into account a well-defined structure of hotel amenities
that the travelers can enjoy.
In this list of hotel amenities we can mention examples as:
• Television
• Computer and Internet access
• Hair dryer
• Swimming pools
• Spa
• Parking
• Conference room
• And the most important one, the minibar
The minibar is imposed in the hotel’s equipment starting with the 3 stars category.
This feature has been designed in order to be installed in the hotel rooms to maintain the
beverages at an optimal temperature without producing any vibrations or noise. Every hotel
manager can choose what products can be sold in the minibar, according to each room type.
But the customers are going to consume those products and the minibar is going to get
empty. Having in mind this problem I have found a very good solution: a Smart Minibar
module that can help firstly the customers and secondly the staff of the hotel in order to be a
perfect harmony between each other: the customers have every product at any moment and
the staff is informed in real time about each minibar.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
4
1.2 Advantages
The main advantage of the device is that the customers have all the products in the
minibar as they are starting to consume any of them.
Another advantage is that the staff of the hotel is receiving live information about the
status of the minibars in each room. Besides that, the Front Desk Clerk has the possibility to
obtain an invoice of the current consumption in each room.
From the prices point of view, the customers can obtain the products cheaper from the
minibar due to the lower taxes applied on this kind of products which are a lot lower than the
restaurant taxes.
As well, thanks to the frequent refills, the consumption will grow however the
language spoken in the hotel is unknown by the customers because there is no need of verbal
communication.
This module comes with a series of functionalities like:
• Scanning capability of the products that include a barcode label
• Status view for the minibars in the hotel
• Editable products table – add and edit function for the products
• Log table for viewing the entire activity of the minibars
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
5
2 Presentation of the Domain
2.1 Internet of Things (IoT)
The Internet of Things is a network of everyday items embedded with electronics,
software, connectivity and sensors or actuators which allows those objects to connect and
transmit data.
In 2016, IoT has evolved due to the fusion of multiple technologies such as wireless
communication, real-time analytics, machine learning, sensors and embedded systems.
According to Carnegie Mellon University in Pittsburgh, Pennsylvania, the concept of a
network of smart devices was discussed in 1982 with a modified Coke machine which
became the first Internet-connected appliance. [1]
The applications of these devices are extending continuously. These can be found in
multiple domains like in shops, in urban planning, energy/heat/water management and even
in-home security systems.
Most devices that are using network connectivity for remote monitoring are designed for
the consumer use.
In agriculture, “the IoT is set to push the future of farming to the next level. Smart
agriculture is already becoming more commonplace among far mers, and high tech farming is
quickly becoming the standard thanks to agricultural drones and sensors”. [2]
These systems are using technologies that are enabling the IoT like Near-field
Communication (NFC), QR Codes or barcodes, RFID (Radio-frequency identification), Wi-
Fi or Bluetooth. Similar to these, there are wired technologies like Ethernet or Medium-range
wireless – LTE or 4G. [3]
Internet of Things has a big impact on companies, end users and on community in
general, and is continuously developing more and more. It is a big technology innovation that
makes the life easier and the companies more productive. It also offers the possibility to
enhance and extend fundamental services like transport, logistics, education, tourism,
healthcare, security and it represents a new technology domain that can be improved and
developed, so it has the potential to create new jobs for unemployed people.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
6
We can take as an example a company that represents a big industry on the market. After
a management meeting there was a sales act. If there is someone that is missing this
important meeting, there is no problem because the internet provides the video conference
feature. The closest factory is alerted and it is already customizing the product, creating it and
after this whole process, delivering it with the smallest delay and doing everything possible
so that the client will be satisfied. [3]
2.2 State of the Art
In the hotelier industry, Marriott International launched the IoT Hotel Room having as team
two leading companies – Samsung and Legrand.
“The IoT Guestroom Lab — powered by Marriott’s Innovation Lab at the company’s
corporate headquarters — explores concepts that have the potential to elevate the guest
experience, create more efficient hotel-room design and construction and contribute to
Marriott’s global sustainability efforts and goals. The Lab allows multiple responsive IoT
systems, devices and applications to communicate with one another to serve guests and
optimize hotel operations. […] The technology inside the IoT Guestroom Lab allows, for
instance, a user to ask a virtual assistant for a 6:30 a.m. wake-up alarm, to start a yoga routine
on a full-length mirror, request additional housekeeping services and start the shower at the
desired temperature stored in their customer profile — all by voice or app.”1 [4]
1 Kostuch. (2017, November 15). http://www.hoteliermagazine.com/marriott-launches-
internet-things-hotel-room/ . Retrieved from Hotelier Magazine:
http://www.hoteliermagazine.com/marriott-launches-internet-things-hotel-room/
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
7
3 Smart Minibar Module. Presentation of the system
In this chapter I will explain the entire system of the Smart Minibar module and I will
explain the working operation of each hardware part. As well, the programming languages
that were used in order to develop this system will be introduced in this chapter and the
implementation of the features of this product will be explained in the next chapter.
First of all, I will explain the entire process step by step up starting from the first input
to the final output. I will be using the following use case diagram, so the working principle
will be understood better.
Fig. 1 – Use Case Diagram for using the module
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
8
3.1 Raspberry Pi
Developed in United Kingdom by Raspberry Pi Foundation, the Raspberry Pi is a
small single-board computer having as objective the teaching of basic computer science.
In February 2012, the Raspberry Pi was created by the Raspberry Pi Foundation,
having the main target the teaching basic computer science in schools, initially having two
devices: the Model A (having a 700 MHz CPU and 256 MB of RAM) and the Model B
(having the same CPU and 512 MB of RAM), these two being different from the
specifications point of view. The price for that products was ranging from $25 to $35 and
those devices were very reliable. In the early of 2015, the Raspberry Pi 2 appeared with a
better CPU and more RAM memory. [5]
The Raspberry Pi 3 Model B, which I am using in this project, was released in
February 2016 and it has:
• Quad Core ARM Cortex-A53 64-bit 1.2 GHz CPU
• 1 GB RAM, GPU VideoCore IV 3D
• Wi-Fi adapter 802.11n
• Bluetooth 4.1 and LE
• 40-pin GPIO
• 1x HDMI port
• 4x USB 2.0 ports
• Stereo Audio Out (3.5mm jack)
• 1x CSI port for Raspberry Pi Camera
• 1x DSI port for Touchscreen Display
• MicroSD slot. In the memory card slot, I am using a 16 GB MicroSD from SanDisk.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
9
Running mainly on Raspbian, a Linux version created for Raspberry Pi, it can be
programmed to achieve any functions. The simplest function that Raspberry Pi can deliver is
the Smart TV module. Connecting the board to the TV through an HDMI cable, you can
browse the internet or watch videos.
The Raspberry Pi comes with more operating systems and you can install one
depending on your preference. Some examples of alternative operating systems are Microsoft
Windows 10 IoT Core, ARCH (a command line Linux), OpenELEC (the best OS for using
the board as a home theatre PC), RiscOS and Pidora. [6]
The easiest way to install an OS to a Raspberry Pi is to download and run the NOOBS
software which is provided on the official Raspberry Pi’s website on the internet. The
MicroSD card is a must have because all your files are stored on it. Personally, I recommend
at least a 16 GB memory because you can fill up this SD card very fast with applications and
libraries for Python.
After copying all the files for the NOOBS software on the MicroSD card, you should
connect the board to an output display using the HDMI cable and I recommend installing a
keyboard and a mouse too. After all these things are ready, you must power up the Raspberry
Pi using the Micro USB cable. You can plug it in your phone charger or in one of your PC’s
USB ports.
Installing Raspbian on your device is very simple because you only need to follow all
the instructions shown on the display. After everything is done you can start working with it.
With the GPIO (General purpose input-output) 40-pin feature and having the
possibility to write source code and run Python, you can connect any sort of sensors or any
kind of inputs and outputs and develop and build Internet of Things applications that can
change the world of technology. This port transforms the Raspberry Pi into a microcontroller
and it can be used for very big projects.
The only inconvenience is that you have a limited slots for sensors or outputs and you
have to connect them having in mind the scheme of the board.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
10
Being a computer that is connected to a network, the Raspberry Pi can be accessed
remotely with the very common system called Secure Shell (SSH). For doing this thing you
must know your Raspberry Pi’s IP address using the ifconfig command in the Terminal.
Using PUTTY, a very useful free software which you can download for free from the
internet, you can access remotely the Raspberry Pi using its IP address and the port 22 which
is the special port for SSH. The standard syntax for accessing the board is pi@IP-ADDRSS,
Port: 22. In my case, the IP address for the Raspberry is 192.168.0.105, so the Hostname will
be “pi@192.168.0.105” and the port will be 22. After these settings are finalized, a command
window will pop-up and it will ask you for a password, which by default is “raspberry”.
Fig. 2 – PuTTY software
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
11
After doing those configurations, a command window will pop-up. This window is actually
the terminal of the Raspberry Pi which you connected. You can enter any Linux command in
this terminal and it should look like in the following screenshot:
Fig. 3 – SSH terminal window
Instead of using the HDMI cable, a good solution is to use of the VNC Viewer which
is pre-installed on the Raspberry Pi. It uses the same port as SSH (port 22) and for installing
on another computer it can be downloaded free from the internet from this website:
After the installation, it needs a server which is the Raspberry Pi itself. To activate the
server, it must be typed the command in the terminal of the PuTTY like so:
When the server is started, it is required a connection to it using the VNC Viewer
program. For this step, it’s required to enter the IP address of the Raspberry Pi followed by
“:1” in the correct text field.
Because it is an SSH connection, it will ask for a password which is the same like in
the PuTTY setup: raspberry .
vncserver :1
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
12
Fig. 5 – VNC Viewer software
After doing all these setups, the connection between the HDMI cable and the display
will be replaced by this program and it will look like in the following picture:
Fig. 6 – Raspberry Pi remote using VNC Viewer
Also, the VNC Viewer offers the feature to help the previous connection and it is not
required to remember the Raspberry Pi’s IP address.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
13
Having all of this, I have managed to develop a Smart MiniBar Module using this
little board and an input type peripheral – the USB barcode scanner.
Fig. 7 – Raspberry Pi (front)
Fig. 7.1 – Raspberry Pi ( rear)
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
14
3.2 Barcode laser scanner
A barcode scanner is an electronic device that can read and output printed barcodes.
This system has a light source, a lens and a light sensor that is transforming optical signals
into electrical ones. [7]
A barcode is an optical representation of data that describes something about the
object which has that specific machine-readable image. [7]
There are two types of barcodes: 1D (one-dimensional) or 2D (two-dimensional). We
are focusing on the 1D barcodes (UPC-A and UPC-E) because most of the products in a
minibar has a 2D barcode printed on them.
The general working principle behind the checking of the format is that the coding
systems have a very well-defined structure. For example, a character from the 8-bit ASCII
table must contain exactly 8 bits, otherwise the computer would detect an error. [7]
Most of the detected errors can modify this very well-defined structure and can be
found by the scanners. The bar codes, called self-checking, with this feature need a minimum
of two printing errors for a character to be read wrongly. [7]
The symbologies are bi-directional so that the bar code can be read starting from any
direction, either from left to right or reversed with no difference in the output. To have a bi-
directional symbology, a bar code must have a start character, the message characters and a
stop character. The start character is the unique character that is located on the left of the
barcode and the stop character, similar to the start one, is located to the right of the barcode.
A UPC-A or UPC-E barcode consists of 95 evenly spaced columns. When a barcode
scanner scans a barcode, it is actually scanning through all the columns and it is checking to
see if each of these columns is reflecting a lot of laser light or virtually none. If a column is
not reflecting light, the computer considers it a 1 and if it is reflecting light, the computer
reads a 0. Each 1’s and 0’s are grouped in 15 sections. The numbers on the bottom of the
barcode are using 12 of these sections. The other 3 sections are used as guards: left guard,
center guard and right guard. This guards let the scanner to know where the barcode begins
and ends and also, the center guard lets the computer to know where is the sixth number on
each side begin and end. The numbers on the left side are identified based on one set of codes
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
15
and the numbers on the right side are identified based on another set of codes. This is
important because the scanner needs to know if the barcode is being read from left to right or
upside down. [8]
Fig. 8 – Bar code operation of working
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
16
When choosing a bar code symbology, there are some circumstances that need to be
taken into account, such as:
• The accessible area for the symbol
• The type of data that is going to be encoded
• The printing equipment
Because the most of the bar code readers can determine more symbologies, there is a
big number of companies that are using more symbologies on the same label. When doing
this, they can do considerable cost savings when more requirements are accomplished using
one label. For example if a label contains Code 128 and UPC, the first one is being read in
the plant and the UPC symbology at the point of the distribution.
For this project I am using an USB barcode scanner from Winson, model WNL-
5000g-USB. Winson barcode scanners are compatible with almost all common systems, as
Windows, Mac OS, Linux.
The working mode of this barcode reader as continuous reading or single reading,
scan the same barcode or not, delay the time to upload data or not. As well, this barcode
scanner supports multi-barcodes including UPC-A and UPC-E.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
17
Fig. 9 – Bar code reader
Fig. 9 – Bar code reader USB cable
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
18
3.3 Ethernet vs. Wi-Fi
In computer networking the Ethernet port is mainly used in Local Area Networks
(known as LAN), Metropolitan Area Networks, and WAN (Wide Area Networks). It is a
technology that allows a computer to connect to a network using a cable with a specific cable
plug.
In order to connect any module to a database, we must have a connectivity function.
To get the project to the working state, we are going to choose one of the Raspberry Pi’s
connection types: Ethernet or Wi-Fi
The Ethernet connection is very reliable because it is supposed to transmit data
through an Ethernet cable.
An advantage of this type of connectivity is that it can reach the maximum speed that
the Ethernet adapter is designed without keeping in mind the distance to the router or to the
point of access. The main disadvantage in using this connection is that the customer has to
pull cables through the building in order to make it usable.
In a similar way, Wi-Fi is the technology that allows a computer to connect at high
speed to a network without any cable requirements.
According to its properties, a wireless connection uses radio signals to transmit
information between a device configured with a Wi-Fi adapter and the point of access.
The wireless connection is not as reliable as the Ethernet connection but the customer
doesn’t need to have cables in the building, which is a big advantage. With respect to the
distance from the router, the speed might be lower regarding the 802.11n technology of the
adapter, but for its purposes, it doesn’t require a fast connection. A disadvantage of this
function is that you might need other devices such a repeater if the Wi-Fi signal doesn’t reach
from the router to the module, but using a repeater doesn’t suppose pulling cables. [9]
Because our module doesn’t require any high speed connectivity, I considered to
choose the Wi-Fi connectivity due to its advantages over the Ethernet connection regarding
the cables. The signal problems can easily fixed using a repeater and this type of system has
to be a very reliable one.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
19
Due to the security reasons, it is recommended for the hotel to have a dedicated local
network for this module so the everyday customers can’t have access to it. If there is no
dedicated local network, hackers can have access in the hotel’s network and can do a mess
with the entire system.
3.4 Graphical User Interface (GUI)
“User interface design is a subset of a field of study called human-computer
interaction (HCI). Human-computer interaction is the study, planning, and design of how
people and computers work together so that a person’s needs are satisfied in the most
effective way”2 [10]
The user interface is the component of the software that allows people to have direct
contact to the device or the application. This interface is composed of two elements – input
and output. [10]
The input part is defined by what is introduced in the application or device in order to
be processed. As an example we can consider the keyboard, mouse, touchpad or even a
human’s finger on a touchscreen display.
The output part is defined by what the computer displays the result of the input that
was processed previously. As an example we can take the display of the computer, the
printer, or even an LED.
In order to create the Graphical User Interface for my project I used the Web
Programming because it is very easy to maintain a website and you do not have to install
anything. The only requirement is only a server which is in charge to host the website and the
database, and the project is working.
To make everything look cleaner and smoother I have used Bootstrap which is an
open-source library for developing HTML, CSS and JavaScript and it’s helping the developer
2 Galitz, W. O. (2002). The Essential Guide to User Interface Design – Second Edition. New
York: John Wiley & Sons, Inc., p. 4
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
20
with some already implemented ideas of web programming design. Those are Web
Programming languages which you are going to read about later.
Having all of this, our interface is actually a friendly user interface in which the user
can request an invoice of the consumption or force reset the minibar status (input) or can
check the real-time consumption in the minibars placed in the hotel’s rooms (output) in order
to request a fresh refill of a specific product or of the entire minibar or even check a log of the
entire system in which the user can see when an invoice was generated or a product was
scanned by the customer. The next images may suffer modifications according to the Hotel’s
preferences
Fig. 10 – GUI Log Table (Home Screen)
.Fig. 10.1 – GUI Status Screen
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
21
4 System implementation
As any other working device on the market, we need software, because without this
part, our devices would be only some electronic parts that you couldn’t use, so they wouldn’t
have a purpose.
In the following sub-chapters you will know how I managed to implement the
SmartMinibar module. For the back-end part, Python programming language was the best
choice for me because a developer can configure very easily a Raspberry Pi using this
solution thanks to the open-source libraries and the Python communities.
Being a network dependent device, the module requires a server and a database. I
have managed to use Apache2 Server for Windows which is free on internet
(https://httpd.apache.org/) and it is a very good tool because you can use it as a web server,
database server, it has PhpMyAdmin interface where you can manage the database behind the
application and it installs by default the PHP plugin for programming in PHP language inside
the HTML code for the Graphical User Interface.
4.1 Python
Python is an object-oriented interpreted programming language created by Guido van
Rossum and released in 1991. [11]
It is a general purpose programming language that can be extended to C or C++ and it
can provide sufficient speed for “intensive tasks”. As in the majority of the programming
languages it has the if-else / if-elif-else / for structures and as you read previously, OOP
capabilities: you can write functions, classes, modules which you can organize in packages,
like in Java or C#. [11]
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
22
The Python interpreter runs the program as the code is written. If there is an error
inside the code, it prints an error message and it rises and exception. Due to the fact there is
no compilation, debugging and testing can be very easy and quickly. [11]
As you read previously, Python can be used as an object-oriented language. It can be
implemented all the concepts that are associated to the OOP like: classes, exceptions,
instances, methods, inheritance, overloading and even automatic memory management.
To run any Python program, it is required the Python interpreter which can be
downloaded for free from www.python.org. This software includes the Python interpreter,
standard modules and other files that are required for Python programs.
As well, the documentation is always a must have, so Python includes a standard set
of manuals like Python Tutorial, Python Library Reference, Python Language Reference,
which are available on the web site.
Interactive mode is a very easy way to run Python programs. To start the interactive
mode, all you have to do is to write the command “python” in the Command Prompt or
Terminal and it will look like in the following picture:
Fig. 11 – Raspbian Terminal window
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
23
For creating Python scripts, it is even easier. All you have to do is to make a text
document with the “.py” extension and you can write the code inside this file. When this step
is complete, you can run the code with the command “python <filename>.py”. Make sure that
the path of the Python program is correct. [12]
I have used Python version 2.7 for the implementation of the barcode scanning
capability on the Raspberry Pi board and the connection with the database is implemented
here too. For this project I am using this terminal in order to debug the Python program
which is running in the Raspberry Pi. Without this debugging it would be very difficult to
figure out all the errors and the malfunctions of the implemented program.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
24
4.2 USB connection of the laser scanner
As you probably already read previously, the barcode scanner has a serial connection
to the module. Unlike the computers, the module is not installing automatically the drivers
into the Raspberry Pi, so you have to access the USB port manually and map the scanner’s
read buffer with the real characters.
The following part of the Python source code declares the actual path to the serial
connection file.
With a barcode is scanned, the computer will generate a code of numbers. It has a
very similar behavior of a keyboard.
The following numbers can be mapped like in the ASCII table, because it has no
natural order of characters:
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
25
The code “2” acts like the SHIFT button on the keyboard , so it will write the alternate
symbols of the previous characters or the capital letters. So, if there is the “2” code before the
numbers shown in the upper part, it will have the same code, but the numbers will mean
different characters like in the following mapping:
The code “40” will tell the computer that there is the finish of the bar code, so it will
stop reading.
In the following screenshot you will see the Python code that implements the shifting of the
characters and the ending of the reading phase of the barcode reader.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
26
4.3 Database
In Computer Science, a database is a set of data located in a computer that can be
accesed in several ways.
This data is structured in tables, which are formed by rows and columns. When there
exists new information, the present data in the database is being updated, expanded or
deleted. [13]
According to techtarget.com, databases were introduced in 1960s and is evolving
since that moment. In 1980s, the object-oriented database was introduced and today this
technology evolved with SQL, NoSQL and Cloud databases. [13]
In my project I am using a simple SQL database with essential data in order to keep
everything updated and in real time that is connected to a Database Server using the
application called WAMP that was mentioned previously. The device connects to this server
using the port 3306 which can be modified at any moment according to the hotel
management’s preferences.
In order to connect the Raspberry Pi to the database I have in implemented the Python
source code some lines that are responsible to to this connection using “pymysql” library.
Using the “connect” method with the parameters like the IP address of the database
server, the port, the database name and the specific credentials I can connect the module to
the database server. The “cursor” is responsible to fetch the results of the SQL queries.
In the Hotel database, we can find tables like rooms, products, join_rp, consumption
and log. Each of this table contributes in a way to my application.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
27
The rooms table contains all the rooms that exist in real time in in the hotel, including
their id (which is the primary key of this table), room number and the specific IP addresss
that is updating at any reboot of the Raspberry Pi. This IP address is saved using a Python
function in the Raspberry Pi. From this, we can understand that in each room we can find a
Raspberry Pi.
Because I have only a single Raspberry Pi that serves as a module for the minibar, I
have only a single active room in my database. This room is presented as an example and the
table can be developed more further. Because of this, in the Python code we declare a
variable to be the number.
Since I have many-to-many relationships between this table and the products table,
this table helps the system to update in real time all the new data.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
28
Each room is getting the IP address value for the database from the Python code.
Using the “netifaces” library, I am getting the IP address used by the Wi-Fi adapter. The
rooms table is then updated based on the room number which is a static variable in Python
code on the Raspberry Pi. Having this implementation, all the rooms are synchronized and we
have an IP address of each module located in each room.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
29
The products table has all the products that can be brought to the customer and that
can exist in the minibar. We can see here that is set a default quantity that represents the
maximum quantity of each product that can fit in the minibar. Using this table, the Raspberry
Pi knows which product was scanned by the customer by reading the barcode column that is
corresponding to each product. All this fields recorded in this table can be edited by the user.
As well, the user can also create a new product using the Graphical User Interface.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
30
The join_rp table represents the relationship between the rooms and products tables.
The roomid from the rooms table and the productid from the products table are primary keys,
so are represented as the reference values. The roomid and productid columns from the
join_rp table are foreign keys that are helping the relationship to be done. The quantity
column of this table is an Integer type column and is collecting the default quantities of the
products from the products table. When the refill card (key) is scanned, all the quantities here
will be back to the products table values. This was implemented using Python code and SQL
in the Raspberry Pi.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
31
The consumption table, similar to the join_rp table, is the result of the Many-to-
Many relationship between the products and rooms table. The only difference is that the
default quantity of the products is 0 because I increment this field using Python. This table
helps me to determine the total consumption in a specific room and ignore the minibar refill
operation in order to make an invoice with the total of products consumed.
In order to get the product id, I am using a two arrays that contain the product names
and the products’ id. With the help of these arrays I can get the product’s id in order to
complete the SQL statement.
The log table is related to the rooms table and contains all the descriptions of the
activites using the module including the exact date and the room id. This table is populated
from the Raspberry Pi or the GUI using SQL syntaxes.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
32
In the implementation of the module, the connection of the database connection is
implemented in the Python source code. Firstly we must declare the IP address of the
database server and its port. Also, the name of the database is mandatory to be declared in the
program. The “user” and “passwd” variables are the credentials for the database server
access.
The only difference of the connection type is that it uses a different adapter, so you
will have a different IP. The declarations of the database name and of the port will be the
same.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
33
4.4 Web programming
Web programming languages are used in the development of the web pages. The
basic language of this kind is the HTML programming language, but in addition to this, PHP
and JavaScript are often used.
In my project, I managed to design the user interface as a web page where the entire
system of the minibar modules can be controlled from one computer located at the reception.
As well, I decided to use PHP because we can develop easily the back-end part of the
page and connect it to the database in order to output the status of the minibars or to generate
some inputs for the invoice or refill requests.
The Cascading Style Sheets (CSS) is in charge with the style and the design of the
page. Here we can change the colors of the background or of the items, modify the position
of the elements, organize them in containers and many other designing activities.
Also, I have used Bootstrap, a very powerful framework for CSS which is provided
with very beautiful designing libraries that can help you to build a very nice website.
First of all, I have created a PHP file named “ Hotelmethods.php ” that contains all the
functions that are being used for the Graphical User Interface. This file was updated by the
time I had advanced with the project. Also, it must be included in almost all the pages
because I am using those functions everywhere in this project.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
34
For example, the function called “ dbConnect ” is used for establishing a connection
between PHP and the Database. It takes as parameters the IP Address, user name for the
server access, password and the database name.
The main page (index.php) of the user interface consists of a log of activities that
contains all of the product scans, refills or reception generated invoice or status reset
indicating the exact time that the event happened, the room number and the name of the event
with specific details. Also, all the pages are equipped with a sidebar that helps for a easier. It
has also a JavaScript code that keeps refreshing the log table so that the information is
available in real time. The PHP code is helping with the back-end connection to the database,
and with the help of the echo function, it generates an HTML table which contains the log
data.
This code represents the dependencies for the index.php page and for all of the project
pages.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
35
As you read previously, each page that contains data which is designed to be
displayed in real time has a JavaScript code that auto-refreshes the information.
Inside this code, the logload.php page is actually the table with the log data which is
meant to be refreshed in order to not refresh the whole page.
The logload.php is a PHP code that connects to the database using the “dbConnect”
function, and displays the log table using the echo function calling a HTML code that
displays a table using the “displayLogTable()” function implemented in “Hotelmethods.php”
logload.php
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
36
The displayLogTable() function takes as a parameter the connection to the database in
order to execute the specific SQL queries. The HashMaps are implemented in order to make a
connection between the roomid and the room name, or between the product id and the
product name. This maps are helping to display the values correctly according to the specific
table from the database.
Implementation of displayLogTable function
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
37
There is also a dedicated PHP file named sidebar.php which is included in all the
pages of the interface that is in charge with displaying the sidebar of the interface where you
can select different options like choosing a room to check the quantities of the products,
check the status of all the rooms or even the list of the products that a minibar can be supplied
with.
For this page we don’t need any connection to the database, so there is no need for
any PHP code and I am using only HTML, CSS and Bootstrap for design.
For this task, I have decided to use Bootstrap navigation bar, because in my opinion,
as a user and developer, it looks very attractive. Also I have decided to use some lists with
links that helps the user to browse when the event of clicking of them is being completed.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
38
For the room dedicated pages like 101.php, where the staff of the hotel from the
reception can check the quantities of the products in a specific room, I have succeeded
developing it using the same dependencies as each page, a back-end PHP code for the
connection to the database and for processing the database with some updates that are
assigned to the reset button present here (Fig. 1). For each button we start a new connection
to the database and the close it after the event for a better reliability. The table with the
information about the minibar was generated using HTML tags (<table>, <tr>, <th>, <td>)
which are being called by the echo function from PHP like is showed in previous examples.
The Generate Invoice button takes the user to a auto-generated PDF page named
“bill.php” which is generated using PHP code and a special library called FPDF. For this, I
have to connect to the database in order to process the invoice with the specific products that
are consumed by the customers. After that, I have to include the FPDF dependency and create
the invoice like generating a table without borders by adding cells ($pdf->Cell). Each line of
code where I am adding a cell will add another cell after the previous one. When I set the font
for all the cells that I have added ($pdf-> SetFont), I will start a new row by changing one
parameter of the Cell function. If everything is good, I confirm all the changes and display
the pdf with the command $pdf-> Output();. After that, I took the information from database
in order to complete the invoice.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
39
When the invoice has been generated, the status of the minibar will be back to the
initial phase, theoretically refilled by the specific staff of the hotel and this event will be
displayed in the log with the message ‘Invoice created’ with the specific room and at the
current time and date.
These lines of code are responsible for the generation of the invoice. Here, I am using
HashMaps and SQL connections in order to display correctly the table values. The total price
is calculated by the product between the “Unit price” and the total quantity from the
“consumption” table which is responsible for the counting of the consumed products in total.
Using the “index” variable we count the products for the “No.” field in the invoice. The
presented invoice is fictional and it has informational purposes. I am assuming that the
invoice must be modified following a hotel’s model. The main purpose of this feature is that
the receptionist can print an invoice for all the services that the hotel is selling to the
customer including the price of the stay, room service and other facilities that a hotel can
give.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
40
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
41
The products table is outputted by the function called “displayProductsTable”
implemented in the methods file which is included here too.
Here, I am using an SQL syntax for selecting all the fields from the products table.
After this operation, the table is generated using the table tags from the HTML syntax. With
the help of the while loop I can go through the products table row by row and I can select
only the desired data.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
42
With the help of the implemented function called “selectRoom”, I can quickly get the
room id because it takes as parameters the connection variable and the desired room number.
To implement this function, I am using an SQL syntax to select all the rooms from the rooms
table and then I am mapping the room number to its room id. After this implementation this
function returns the room id.
After calling this function, a beautiful products table will be displayed in the
Graphical User Interface. Also, this page contains forms for adding a new product or editing
an existing one. The product id is mandatory to be typed in the correct field for making this
functionality work.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
43
For the implementation of this page I have used the displayProductsTable function
having the connection parameter and two HTML forms using the method “POST” in order to
send the request to the server.
The Add and Edit buttons are implemented using PHP code and inside the
implementation, two methods named “addProduct” and “editProduct” from
“Hotelmethods.php” are called in order to accomplish the task.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
44
Similar to other methods in this project, the “addProduct” and “editProduct” functions
are using HashMaps for maping the name and the ids and SQL syntaxes for inserting data
into the products table, join_rp table and rooms table in order to synchronize everything.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
45
5 Conclusions
Having all of the previously mentioned components and using all of these technologies I have
succeeded in building a very useful and very easy to use module which has a very big
potential to begin a business because it’s the only existing module of this type that exists on
the world market. It represents a powerful feature for a hotel that provides an environment of
smooth services.
The Raspberry Pi is a very good way to begin the developing of a project because it offers a
good environment for a developer. Thanks to its capabilities, I have succeeded in developing
a very useful module for the hotels using the Python language and its capability to connect
wirelessly or wired to a local network. Having USB ports was also a nice feature because it
didn't require much work in connecting the barcode scanner to the board's GPIO port.
The USB laser barcode scanner is very useful because it reads almost instantly the desired
data and it sends it using a serial connection which is very fast.
The link between the serial file of the scanner and the Python code was implemented very
simple using one line of code according to this specific chapter. The most difficult part was to
figure out the transformation from the bytes that the USB scanner is sending, to the actually
characters that are being read. There is a complicated combination of codes that represents
the start and the end of the scanning and the actual data that is being read.
From the improving point of view, this project can be further brought to the next level by
building a custom microcontroller board that is only running the module’s source code and
nothing more because for this kind of project there is no need for an operating system like
Linux. It just needs only the running file and a way of connectivity to a network via Ethernet
or Wi-Fi. Also, it needs a running server and a custom API for a better integration to the
potential hotels that might buy this product. In industrial quantities, this way of developing
the module would be a lot cheaper and it could be easier to patent this concept.
This Smart Minibar module in a hotel would help both the hotel's clients and the staff,
benefiting from a more dynamic and easy work environment because the clients would have
all the products refilled with fresh ones at any time, even cheaper due to the lower taxes. The
staff of the hotel would have a real-time information about the customer’s minibars in their
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
46
rooms. Also, the Graphical User Interface is very user-friendly, and it provides the possibility
to generate an invoice containing the total of products’ cost consumed by each hotel
customer.
On the first hand, having the Smart Minibar module in a hotel would increase the profit by
transforming the simple consumption of a product taken from the minibar into a fun activity,
not only consuming it because the customer needs to. You cannot scan your own products in
any place and a hotel’s room would be the perfect choice to do that.
Secondly, this invention would increase the happiness of the hotel’s staff because those
people would skip a good part of their already existing job. Just think about the fact you will
receive the same amount of money for a less work.
In my opinion, the hospitality industry will be present on this planet forever because people
are willing to travel on vacation or even with some business interest. In a high-class hotel the
minibar will be frequently used, and this module would be very useful to the people.
Diploma Thesis, Stefan VOICU, Faculty of Engineering in Foreign Languages, UPB, 2018
47
References
[1] C. C. D. C. Machine, "MU CS Department Coke Machine," 02 2014. [Online].
Available: https://www.cs.cmu.edu/~coke/history_long.txt.
[2] A. Meola, "Why IoT, big data & smart farming are the future of agriculture," 20
December 2016. [Online]. Available: http://www.businessinsider.com/internet-of-
things-smart-agriculture-2016-10.
[3] GSM Association, "Understanding the Internet of Things (IoT)," July 2014. [Online].
Available: https://www.gsma.com/iot/wp-
content/uploads/2014/08/cl_iot_wp_07_14.pdf.
[4] Kostuch, "http://www.hoteliermagazine.com/marriott-launches-internet-things-hotel-
room/," 15 November 2017. [Online]. Available:
http://www.hoteliermagazine.com/marriott-launches-internet-things-hotel-room/.
[5] C. Lyons, "A History Of The Raspberry Pi," 4 March 2015. [Online]. Available:
http://novadigitalmedia.com/history-raspberry-pi/.
[6] Raspberry Pi Foundation, The Official Raspberry Pi Projects Book, 2015.
[7] R. Bhaskar, Bar Codes, New Delhi: Tata McGraw-Hill Publishing Company Limited,
2001.
[8] C. Petzold, Code: The Hidden Language of Computer Hardware and Software,
Microsoft Press, 2000.
[9] A. Shekhar, "Wi-Fi vs Ethernet: Which Internet Connection Is Better And Why?," 21
April 2016. [Online]. Available: https://fossbytes.com/wi-fi-vs-ethernet-comparison-
features/.
[10] W. O. Galitz, The Essential Guide to User Interface Design – Second Edition, New
York: John Wiley & Sons, Inc., 2002.
[11] C. Fehily, Python, Berkley: Peachpit Press, 2002.
[12] Python Software Foundation, "The Python Tutorial," 2001-2018. [Online]. Available:
https://docs.python.org/3/tutorial/index.html.
[13] A. L. a. A. H. Margaret Rouse, "database (DB)," February 2017. [Online]. Available:
https://searchsqlserver.techtarget.com/definition/database.
Copyright Notice
© Licențiada.org respectă drepturile de proprietate intelectuală și așteaptă ca toți utilizatorii să facă același lucru. Dacă consideri că un conținut de pe site încalcă drepturile tale de autor, te rugăm să trimiți o notificare DMCA.
Acest articol: Smart MiniBar using Raspberry Pi for Hotelier Industry [631885] (ID: 631885)
Dacă considerați că acest conținut vă încalcă drepturile de autor, vă rugăm să depuneți o cerere pe pagina noastră Copyright Takedown.
