Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

15th international conference on Sciences and Techniques of Automatic control STA'2014-PID3518-SIS

& computer engineering - STA'2014, Hammamet, Tunisia, December 21-23, 2014

Remote control of a domestic equipment from an Android application


based on Raspberry pi card

Hayet Lamine Hafedh Abid


Department Technology Informatics of ISET of Sfax Department Electrical of ENIS
High Institute of technology’s studies of sfax, (ISET Sfax) Laboratory of Sciences and Techniques of Automatic &
Sfax, Tunisia computer engineering (Lab-STA) Sfax, Tunisia
lamine_hayet@yahoo.fr abidhafedh@gmail.com

Abstract—In this paper, we propose a Remote control of a automation application requires for its operation, able to
domestic equipment from an Android application based on capture information and operate a subsequent order. For this,
Raspberry pi card. Home automation has been recalled in the we must be able to transfer information between different
first stage. In the second stage an application has been developed devices. The system allows programming of automatic sources
based on the android system. The different diagrams have been of comfort and safety of energy saving: the automatic opening
presented. Different codes have been developed to allow the and closing of the shutters, automatic watering depending on
communication between the remote user, the web server, the the climate, lighting management based on the presence and
raspberry pi card and the home components. Also an interface brightness, etc. The home automation system includes three
card has been developed to assure the communication between
main compoments which are:
the home components and raspberry pi card. The application has
been installed on a Smartphone, a web server and a raspberry pi • Controller / Control Interface: as a monitor, computer, or
card to order the shutter of windows. The experimental results phone, for example, that can give orders to units that one
are successful. wishes to control (program, parameterize)
Keywords—Android system, Web server, Raspberry pi card, • A mode of transmission: wired connections (example
Electronic components. Ethernet), radio waves, infrared, etc.

I. INTRODUCTION • An apparatus as an electrical outlet, a lamp or a heater,


which is compatible with the transmission mode, and
Home automation includes all electronic components, connected to the control system.
building physics, middle ware, informatics technology and
telecommunications used in buildings, more or less Although smart tools have been accessible in the past, their
"interoperable" and to centralize the control of different use has been very limited because they require
systems and subsystems of the house and company (heating, intercommunication. One suggested solution is to connect all
shutters, garage door, entrance gate, electrical outlets, etc.) [1], smart devices using hard electric wiring [3]; however, the
[2]. Home automation has been developed to provide technical resulting portability problem then produces an order for a
solutions to meet the comfort needs such that energy wireless network able of accepting the devices. Organizations
management, optimization of lighting and heating. Home have therefore developed management, supplementary
automation could be improved through an amelioration of services, and gateways for smart devices [3]. Smart home
communication network that uses a pair of twisted lines, radio network technology has been installed in various systems,
signals, or fiber optics in a bus-based network or an internet such as power line and radio frequency systems [4].
protocol as standards. The main contribution of this paper is to
implement an electronic card which can control, through the III. REMOTE CONTROL EXAMPLE OF DOMESTIC EQUIPMENT
Internet under the android environment, household equipment FROM AN ANDROID APPLICATION:
such as air conditioning, heating. The application consists to
We offer the example of a system for controlling a remote
develop programs that allow communication between a remote
shutter, using a "Raspberry pi" card for receiving commands
user using a smartphone, a web server and raspberry pi card
from an Android application on mobile phone. Our electronic
that communicates with one or more interface cards to control
system is composed of a "Raspberry pi" card for receipt of
the equipment in the home. This paper is organized as follows:
commands sent by the user and according to the order nature,
Section 2 recalls the home automation. The section 3 describes
the card will raise or lower the electric shutter. The
remote control example of domestic equipment from an
implementation of this system requires:
Android application.
- The Programming of a Raspberry pi card capable of
II. HOME AUTOMATION receiving commands (orders) sent by a remote user to raise or
lower an electric shutter linked with this card.
Home automation is an electrical system that enables
communication with remote controls or buttons to make the - The development of a mobile application "Android" in
control of the house easier. They are used to control a simple order to control our system.
gesture one or more actions (Examples: lower heating, lighting The solution that we present can also be adopted for other
adjustment, lowering motorized shutters ...). A home equipment such as lamps, air conditioners…

978-1-4799-5906-8/14/$31.00 ©2014 IEEE 903


A. Solution Overview
The following diagram (Fig. 1) illustrates the components
of the system, and the interactions between them.

Fig. 3. Use case of "Remote order shutter"

Remote open shutter: allows the remote user to open the


shutter remotely.
Remote close shutter: allows the remote user to close the
shutter remotely.
See current status: allows the remote user to see the current
state of the shutter to perform the correct order.
Register command: Saves the “open / close” order in the
Fig. 1. Solution overview schema database with state = 0.
For the design of our system, we used the Unified Check order status: to check the status of the command
Modeling Langage (UML). stored in the base just after recording, and in this state a failure
/ success message is returned.
1) Representation of use case diagrams:
a) The actors Return message: allows you to return a success message or
There are four actors: the main actor is the remote user, fails after checking the status of the order recorded, if
two secondary actors which are the web service and the successful this message confirms that the command sent by
"Raspberry pi" card, the fourth is an external actor : user the user has been made (the state of the order was changed
manual. from 0 to -1), on failure this message confirms that the
command sent by the user was failed (status of the order has
• Remote User: this actor has the right to control the left = 0 after verification).
shutter from its Android application and remotely using his
mobile phone. Recuperate current status: Retrieve the current state of the
shutter, otherwise the last command has performed with
• Raspberry pi card: this actor will access every X seconds success is the current state of the shutter.
to the database to verify the existence of a new order “open /
close” saved. d) Use case of subsystem Raspberry pi:
• Web Service: its role is to register the commands from
the remote user in the database, retrieve the current state of the
shutter, and return a failure / success message under the JSON
as a response on the commands performed by the user.
• Manual user: This actor will open or close the shutter
manually.
b) General use cases:

Fig. 4. Use case of subsystem Raspberry pi

Check new order: Checks every x seconds, if there is a


new command for opening / closing recorded in the database
with status = 0 (new orders awaiting processing), depending
Fig. 2. General use cases
on the nature of the order (open / close), the card will open or
close the shutter.
Authenticate: allows the user to access the application after Open the shutter: to raise the shutter.
entering his login and password.
Close the shutter: to bring down the shutter.
Remotely control shutter: allows the remote user to control
the remote shutter, he can bring them up or down. Modify shutter state: change the status of the last new
command retrieved to -1 (command completed successfully)
c) Use case of "Remote order shutter": after closing or opening the shutter successfully.

904
Save manual order: Saves the manual control opening or 4) Transition-state diagram
closing in the database with the nature of the control (open /
close), its date, and with a status = -1 (command completed
successfully) .
Open manual shutter: Allows the manual user to open the
shutter manually.
Close manual shutter: Allows the manual user to close the Fig. 8. Transition-state diagram
shutter manually.
The diagram above shows the different states of a
2) The class diagram: command: the state « On hold » when the control (open /
close) sent by the user is waiting for treatment, the state
« performed » when the command is successful, and the state
« failed » when it is impossible to carry out the control of the
user.
5) Activity diagram :

Fig. 5. The class diagram

3) Sequences diagrams
a) Sequence diagram of "Remote open shutter"

Fig. 9. Activity diagram

B. Proposed technologies for the programming part :


1) Architecture at three levels (3-tiers)

Fig. 6. Sequence diagram of "Remote open shutter" Fig. 10. Architecture at three levels (3-tiers)

b) Sequence diagram of subsystem "Raspberry pi" card The architecture we adopted for our application (side:
Android application, web service and database) is the three-
tier architecture, which is a stack of three levels: The
presentation of data (Level 1), Treatment business data (Level
2) and access to persistent data (Level 3).
2) Two-tier architecture (2-tier):

Fig. 7. Sequence diagram of subsystem "Raspberry pi" card Fig. 11. Two-tier architecture (2-tier)

905
We have used this architecture side « Raspberry pi » card
and the database.
3) The REST architecture:
REST (Representational State Transfer) is a type of
architecture that is used more and more to make a web service.
It is not precisely defined by a standard. REST is based on
requests transmitted by standard protocols (http, ftp,...), it
often returns a file in XML or JSON format.
4) JSON:
JSON (JavaScript Object Notation) is a data structure
format. The data are considered as objects with properties and
sub-properties. This formalism is close enough is based on
XML and JavaScript. Fig. 13. The inputs / outputs of the Raspberry pi card

5) MySQL: We also offer an electronic interface card which provides


MySQL is a relational database management system communication between the "Raspberry pi" card and the
(RDBMS). It is distributed under a dual GPL and proprietary shutter. This card allows one hand to operate two relays in a
license. It is one of the database management software most well-designed combination (where the outputs of the
used in the world. Raspberry pi card (GPIO) are activated) to rotate the engine
each time in one direction and the other, to offer the user
C. Proposed solution for the hardware part: manual two struts push to open or close his shutter manually.
The solution that we have adopted consists of the PH V1 N

exploitation of the Raspberry pi card. It is a single nano- Motor

computer card ARM processor designed by designer David VCC/VDD


220 V

RL3
Braben video games, as part of its foundation "Raspberry pi". NTE-R22-5
PH V1 N
The following photo presents the Raspberry pi card : Enternet R1 Q1
2N3392
10k VCC/VDD
220 V

RL4

Isolation and Adaptation card


NTE-R22-5
I/O M AP RASBERY

R1 Q1
2N3392
10k
Sensor

GND 1/0

VCC/VDD

RL1
NTE-R22-5

Lamp
R2 Q1
2N3392
10k V1

220 V

GND

Fig. 14. Basis of interface card

D. The Android Client and Extract codes:


1) The Android client:

Fig. 12. The Raspberry pi card

This computer has the size of a credit card, allows the


execution of several variants of the free operating system
GNU / Linux and compatible software. It is supplied bare
(single motherboard, without housing, power supply,
keyboard, mouse and screen) with the aim to reduce costs and
enable the use of recovery equipment. Around the central part, Fig. 15. Navigation diagram
there are different connectors for connecting devices to
interact with the computer. In this section there are some interfaces of our Android
The range of connections offered by the "Raspberry pi" application.
card is given by the following figure:

906
First, the user is prompted to enter his login and password
in order to use the application, in case the internet connection
is not present, an error message is displayed to invite him to
check its connection internet. If there is not a connection
problem, “Please wait” message appears, in this case the
system checks the validity of the login and password, if they Fig. 18. The shutter current state
are incorrect, an error message invites him to check them.
After authenticate correctly, the user is redirected to the
main interface (Fig. 16) where it can choose « Help » to see
the instructions to know more information about the
application, or command its shutter (Fig. 17).
Fig. 19. Successful opening

When the user tries to open its shutters already open, a


message appears to warn him that his shutter is already open,
and the same for the closure.
2) Extract code of the activity component command
button:
For the development of the Android application we used
the tool Bundle ADT (Android Developer Tools), which is the
complete package and recommended to start project
development "Android". It embeds Eclipse, the ADT plugin
pre-installed and the Android SDK.
Fig. 16. Main interface
package com.domotique;
// import ….
public class Commandshutter extends Activity {
private Button btnOpen;
private Button btnClose;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_command_shutter);
main();
}
private void main() {
btnOpen= (Button) findViewById(R.id.btnOpen);
Fig. 17. Shutter order interface
btnClose = (Button) findViewById(R.id.btnClose);
This interface provides the user the ability to control its cd = new
shutter: ConnectionDetector(getApplicationContext());
recuperateState();
By pressing the ON button, the user can open the shutter. addListener();}
Pressing the OFF button, the user can close the shutter. …..
private void addListener () {
By accessing this interface a window showing the current btnOpen.setOnClickListener(new
state of the shutter, and based on this state the user will choose OnClickListener() {
either to raise or descend its shutter (Fig. 18). public void onClick(View v) {
In cases where the internet connection is not present, an // verify internet connection
error message is displayed to invite him to check his internet ….
connection. if (testAction.equals("Open"))
{
For each order « opening / closing » the user receives a
success or failure response (Fig. 19). Toast.makeText(getApplicationContext(), " the shutter is
already open ", Toast.LENGTH_LONG).show(); }
« Please wait » message is displayed to the user while else {
waiting for the response. myTaskOuvrir m = new myTaskOuvrir();
m.execute(); }
}
else { …..}

907
} change the state of this command to -1 (that is to say
}); command completed successfully).
….} //library gpio
Note: myTaskOuvrir is a class type AsyncTask
import com.pi4j.io.gpio…..
(Asynchronous task). It allows for asynchronous tasks. In our
//To open the shutter
case, it will be responsible for displaying the « Please wait »
message, recover the value of the HTTP request sent by the // create gpio controller
client (example « Open »), preparing the response as JSON final GpioController gpio = GpioFactory.getInstance();
(example « The shutter is opening successfully »), and finally // provision gpio pin #01 as an output pin and turn on
reveal the response as is shown in Fig. 19. final GpioPinDigitalOutput pin =
gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01,
3) Extract code to command shutter (open) in the REST "MyLED", PinState.HIGH);
Web Service: // turn off gpio pin #01
We used the PHP language to develop the web service and pin.low();
the XAMPP to test it on the local network before the host on
the Internet. IV. CONCLUSION
function api_post($var) This work deals with smart home. The remote control
{ includes software and hardware components such as web
switch ($var) server, smart phone, Raspberry pi card and an interface card.
{ Many codes have been developed and stored in the web
case ("Open") : server, smart phone and the raspberry pi card. An interface
card has been realized to update signals between the actuator
….
sensors and the raspberry pi card. The application has been
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
installed and tested. This work can be generalized to remote
… command of multiple domestic equipments. In addition, it
$sql = 'INSERT INTO ordershutter '. may be more autonomous, more practice, and quite scalable
'(nat_comm,date_comm) '. saw the giant step and progress in the areas of technology and
'VALUES ( "Open", NOW() )'; communication in our time.

sleep(7);
$req =mysql_query("SELECT * from ordershutter ORDER References :
BY num_cmd ASC"); [1] Li, B., Hathaipontaluk, P., and Luo, S., “Intelligent oven in smart home
while ($row=mysql_fetch_array($req)) { environment,” International Conference on Research Challenges in
Computer Science (ICRCCS ’09), pp. 247–250, Shanghai, 28–29
$state_cmd=$row['state_cmd'] ; December 2009.
} [2] Choi, J., Shin, D., and Shin, D., Research on Design and Implementation
if ($state_cmd==-1) of the Artificial Intelligence Agent for Smart Home Based on Support
{ Vector Machine, Berlin/Heidelberg: Springer, p. 417, 2005.
$msgr=array('response'=>' The shutter is opening [3] Chen, C.-Y., Tsoul, Y.-P., Liao, S.-C., and Lin, C.-T., “Implementing
successfully '); the design of smart home and achieving energy conservation,”7th IEEE
International Conference on Industrial Informatics (INDIN 2009), pp.
}….} } 273–276, Cardiff,Wales, 23–26 June 2009.
mysql_close($conn); [4] Li, J., Da-You, L., and Bo, Y., “Smart home research,” Proceedings of
break; the Third International Conference on Machine Learning and
case ("close") : Cybernetics, vol. 2, pp. 659–663, Shanghai, 26–29 August 2004.
….. [5] Bartram, L., Rodgers, J., &Woodbury, R.Smart homes or smart
occupant? Supporting aware living in the home. In Proc. HCI-
} INTERFACT 2011.
} [6] Pearson Education France – L'Art du développement Android, 2e éd. –
?> Mark Murphy) 2010
[7] Jean Engels., « «corrigé des exercices de l’ouvrage PHP 5 – Cours et
4) Extract from java code programming Raspberry pi exercices », Editions Eyrolles, 2005.
Card using gpio [8] Li Ma, Lei Gu1, and Jin Wang1,” Research and Development of Mobile
Application for Android Platform”, International Journal of Multimedia
and Ubiquitous Engineering Vol.9, No.4 (2014), pp.187-198.
We have developed a Java application that runs on the
[9] Ameena Saad Al-Sumaiti, Mohammed Hassan Ahmed, and Magdy M.
Raspberry pi card, this application has been programmed to A. Salama, “Smart Home Activities: A Literature Review”, Electric
remotely access every x seconds to MYSQL database to verify Power Components and Systems, 42(3–4):294–305, 2014
the existence of a new command (sent by the remote user) [10] Morris ME, Adair B, Miller K, Ozanne E, Hansen R, et al., “Smart-
awaiting processing. Home Technologies to Assist Older People to Live Well at Home”, Sci
Journal of Aging Science, Volume 1, issue 1, 2013
In case there is a new command (open / close) registered,
this application allows one hand to perform the processing of
the order, and also to re-access the database after treatment to

908

You might also like