Web Based Home Automation System

coldwaterphewServers

Nov 17, 2013 (3 years and 4 months ago)

112 views


1

The Islamic University of Gaza

Faculty of Enginerring

Computer Department








Proposal

For Graduate Project






Web Based Home
Automation System


Done By :

Ahmed Faris

Ahmad Jargho
u
n

Saa'd Ashour


Submited to :

Eng. Osama Khader






2







Table of Contents

Table of Contents

….……………………………………………………………………...2


Table of Contents ….……………………………………………………………………...
3


1.


Introduction
.
…………………………………………………………
...
……………
..
.
4

1.1 About th
is

Project
……………………………………………………………..
5


1.2
Description
of Problem Domain
………………………………………………
5

1.
3

What is Home Automation
……………………………………………………
5

1.
4

System Overview
…………………………………………………………
.
….
6

1.
5

Research Undertaken
………………………………………………………...
7

1.
6

Resource Requirements
……………………………………………………...
8


2.


Requirements Analysi
s
……………………………………………………



...
9

2.1
Features of a Home Automation System
…………………………………….1
0

2.2
Overview of Requirements
………………………………………………..…1
0

2.
3

General and Non
-
Functional Requirements
…………………………………
.
11

2.
3
.1 Security Requirements
…………………………………………
..

11

2.
3
.2 Pe
rformance Requirements
………………………………………
...
11

2.
3
.3 User Interface Requirements
……………………………………….
12

2.
3
.4 Data Requirements
…………………………………………………
13

2.
3
.5 Hardware Requirements
…………………………………………
...
.
13

2.3.6 Software Requirements
…………………………………………….
14


2.
4

Constraints
……
……………………………………………………………
...
14



2.
4
.1 External Constraints
………………………………………………
..
14



2.
4
.2 Internal Constraints
………………………………………………
...
14


3.


High Level Design
……………………………………………………………
...
……
15

3.1

System Architecture
………………………………………………………….
17



3.1.1
Layers

Archite
cture

…………………………………………...…
17



3.1.2 Technology Architecture
…………………………………………..
17



3.1.3 Project Architecture
………………………………………………..
17



3.
1.4

State Diagram
………………………………………………………
18


3.
2

Architecture Details
……………………………
...
……………………..
.
.…..
19


3.4

System Interfaces
…………………………………………………………….
20



3.4.1 User Interface Design
………………………………………...……
20



3.4.2 System Interfaces
…………………………………………………..
21


4. Low Level

……………………………………………………………….22


4.1
System Architecture
………………………………………………………….
23



4.1.1 Client/Server Archite
cture
…………………………………………
24



4.1.2 Software Required
…………………………………………………
24



4.1.3 System Features
……………………………………………………
25


3




4.2
Architecture Details

……………………………………………………
...
.
26




4.3
Database Design
……………………………………………………
27


4.4
User Interface Desig
n

… …………………………..………………
28



5
.

Implementation
.........................................................................................................
..
31

5
.1
code

Implementation
…………
…………………………………………
…...
32



6
.

Conclusion
s
……………………………………………………………………
..
……
41


6
.1 Possible
Future
Software

Changes
………………………………………
..

.
42

6
.2 Final
T
houghts
…………………………………………………………

….
42


7
.
References
...............................................................................................................
.....
43


































4









Introduction




















5



Section
1

Introduction


1.1


About th
is

Project


The goal of this project is to develop a

secure
Web Based
H
ome
A
utomation
S
ystem
that
will
allow users to remotely
operate

electric home appliances
,

e.g
. turning
on/off lights
,

in the
user’s
home.


The user interacts with the Home Automation
System
through a network, such as
the Internet

or
a
Local Area Network
intranet
by using an ordinary web browser.

This
will provide a user
-
friendly interface
for

the
user
to

access and interact
with the

electric
devices in the home.

Examples of practical uses for such a Home Au
tomation System
are
many. These
include;



energy management



heating control



lighting
control



1.2

Description of Problem Domain


Home autom
ation is a potentially huge growth area and several companies are
currently developing software that enable users to access home devices from the office or
other remote locations.

However, the software these companies are developing to accomplish home
auto
mation have;




Proprietary Interfaces



Are Totally Insecure



Not Web
-
Enabled


Therefore this project
seeks to develop
a
H
ome
A
utomation
S
ystem that will
overcome these limitations
.



1.
3


What is Home Automation?


Home Automation is a way of controlling e
lectrical appliance
s

from a distance
.
C
ommands are sent from one location and
received and acted upon in another location
.

There are several systems
available
for implementing this kind of control. This
project
will
focus on the cheapest and most popular
m
ethod
for home automation,
use
Microcontroller .




6



1.4


System Overview


The
Home Automation System

will allow users to use a
ny Internet web browser
to remotely control their electric home appliances through a simple web page. This
software intends to le
verage existing technologies and to utilise them in a new way.

The proposed
H
ome
A
utomation
S
ystem will be multi
-
user and will exist in a
distributed computer environment such as the Internet but will also be accessible from
within an intranet such as an
office

or in the home itself
.


The basic objectives are:




The software will run on any
w
eb browser

.



The software will switch devices attached to the remote computer on and
off.



The proposed system can best be illustrated with
the following

diagram;















Home










(
Parallel Port Cable)






Web Server
/
PC



















PIC Circuit
























(House wiring)
























Web Browser























Lamp









Figure 1.
1


System Overview





Internet
or
intranet



7


1.5
Research Undertaken

Several lines of research
were conducted

to support the implementation of the
H
ome
A
utomation
S
ystem.

On the techni
cal side,
the
research include
d
;




Security Technologies



This will be of vital importance as the home automation
system will be accessible from remote locations.
A

s
trong authentication
architecture will be required.




Communication

Technologies



A way of

communicating via com ports on a PC
will have to be researched. This will be necessary to communicate from the PC to
the automated device.




Server Technologies



A lightweight web server ha
s

to be researched.



Automation Technologies



The technology requ
ired for switching on and off the
remote devices will have to be researched.



On the non
-
technical side, researching various aspects of the project, which will
include:




User interface design



We will

be
researching existing software products already
ava
ilable and
also
those in development.




Usability of current systems



We

will be looking at the usability of different user
interfaces currently used.




Functionality of current systems



We

also will be examining the functionality of
existing systems.


Th
is project will be challenging in many ways. The development of the online
interface and communication with the automated devices is a new combination of
technologies.

However We

have a lot of experience of working in software/hardware
environment and fee
l the resulting software would
be
benefit

in

Home Automation.








8


1.6


Resource Requirements


The resources required for this project
are as follows
.


Software:

NetBeans IDE


JCreator Pro Edition



Java SDK 1.
5
.
0

Tomcat Apac
he Webserver

Internet Explorer
5
.0

or later



Parallel Port Java Package



Word 2000


Microsoft Frontpage




Microsoft Access 2000





Hardware
:

Parallel Port cable


Kit to collect the circuit



PIC 16F84A

Microcontrolle


12V Transformer


Resis
tors , Transistors , Capacitors & , Leds , & Wires



Personal Computer


Knowledge

:
-

JSP , web programming




Java Programming




Microcontroller Programming concepts




Some Skills of design





















9












Requirements
Analysis
















10




Section
2

Requirements Analysis


There are a number of requirements for this project design. T
he main
requirements are;



The system should be as easy to use as possible and should allow the user to
access all functionality via
a

web
-
based interface
.



The system should be designed in a modular fashion. A modular system allows
for easier implementation

and well as easier modification

at a later stage.



2.1 Features of a Home Automation System





The ability to control
a
device



This is simply the ability to turn On or Off a
device
,

e.g. a lamp
,

from the Home Automation interface.



The ability to a
uthen
ticate user
s



This a
uthenticates user connections to the
Home Automation S
ystem to prevent unauthorised access.



The ability to
assign devices to a logical group



This simply means that a
collection of devices are a
bstracted

to logical groups of devices f
or ease of
operation and organisation of devices. These
logical
groups
in this project
will be
referred to as

R
ooms
’ in the Home Automation System
, which
can

hold any
number of devices
.




2.
2

Overview of Requirements

The basic requirements for
the

Web

Based Home Automation System are:



Security Requirements



As users will have to log into the Home
Automation System from remote locations and from different computers,
security is
a
very important

consideration in this project
.



Performance Requirements


The home automation system must perform
well and be reliable. Because a home automation system integrates
devices in the home it is subject to a high number of possible failures e.g.
power cuts
,

power
surges

etc. The home automation system must
therefore
be able to check and monitor the status of the controlled

11

devices. Also the system must allow users to use these devices even if
the automation link between these devices has broken down.



User Interface

Requirements

-

A very important point is the ease of
use of
the system. The web page has to be intuitive and easy to use.
Furthermore, it must be also taken into account that
the

home automation
system
can be

used

by
people with
physical
disabilities.



Data Requirements



The data for the Home Automation Syst
em will need
to stored and accessed reliably and accurately.



Hardware Requirements



A flexible hardware arrangement will be
desirable for adding new devices to the system.


These requirements will each be elaborated upon in
the next
Section 2.
3

Genera
l and Non
-
Functional Requirements.


2.
3

General and Non
-
Functional Requirements

This section will further expand on the
overview of requirements listed in
Section
2.
2
.

2.3.1

Security Requirements

There are sec
urity risks associated with using the Home Automat
ion System as it is
designed to operate on a network like the Internet
.

When
accessing the system

the user
needs to
be assured
that intruders, such as hacker attempts and third party invasions,
can

not have access to the Home Automation System. The user
th
erefore
needs to be
confident that the
Home Automation System

is secure.

The ability to authenticate user

connections to the system is required
.



To prevent unauthorised access

the user has to log on

to a website in order

to have
access to the Home Automa
tion System. A secure system to validate the username and
password information is required. The system will accept this information as proof of the
identity
and

allow the user
to
access the Home Automation System.



12

2.3.2

Performance Requirements



Speed of the In
ternet connection from the remote computer and the speed
of the connection to the server will affect performance.

The
Home
Automation S
ystem
will be designed to
be capable of operating even with
slow Internet connections

e.g. a standard 56K modem dial up c
onnection
to the network
.



The Home Automation System
will

be designed to operate on a standard
personal computer with a standard web browser installed. Response times
to commands should be minimal from the browser.




The size of the website
HTML

& JSP

code
should be minimi
z
ed to
improve
performance
on
a
slower connections to the Internet.

The means
minimising use of graphics and concentrating on a more functional design.
This will be addressed
in more detail
in
Section 2.3.3

User Interface
Requirements

secti
on.




Efficiency of the software code will have an effect on how quickly
commands to the system are given.

Every effort will be made to design
the code with performance in mind.



Hardware connected to the system
may suffer from a latency factor
between
issuing of a command and when that command is carried out
.
This will be taken into account and may
influence how fast the
commands

are processed

within the system
.

2.3.3

User Interface Requirements



The u
ser interface

of the Home Automation System should be intui
tive and easy
to use.
We

plan to provide a web
-
based interface for users to access the Home
Automation System. This will enable users to use the system more easily, since it
will be accessible through a common web browser from any computer connected
to the

Internet. This eliminates the need for installation and configuration of
proprietary software.



The user interface will feature the use of meaningful
graphics and
icons, which
will allow the user to easily identify options available.

The number and size of


13

these graphics, however, should be kept to a minimum to
improve
performance
on
computers with
slow connections to the Internet
.



As most people are familiar with browsing on the Internet the web based user
interface should have a look and feel that is fami
liar to the
u
ser.



The user interface should consist of several windows and buttons to control the
different control devices e.g. a lamp.



The user will be able to access the status of all devices that are currently installed
and running on the Home Automati
on System.



The Administrator will be able to add/remove devices to the system. The
administrator will also be view
all users and their devices
.


The proposed system will use a web
-
based Graphical User Interface, which will have
the following characterist
ics:



Website


The user will be able to access the main website from any web
browser.



Login screen


This will be the main entrance to the system.
This
will
feature a
pop
-
up screen and
have two text boxes for typing the username and password.



Main Menu



Once the user logs in, a navigation menu will allow the user to
select
all
options available

from the main menu page.







2.3.4

Data Requirements


The data for the Home Automation System will need to be stored and
accessed in a reliable and accurate w
ay.
A

database will store the username and
passwords of several users at any one time. The database will
also
keep track of
the number and recorded status of all available automated appliances.

Several text files

will also
be used to
store
initial start
-
u
p configuration
details

for the Home Automation System. The
following table illustrates the
data
required
;

Database Tables

Administrator Details

User Details


14

Device Details

Levels of Access


Figure 2.1 Data Requ
irements

2.3.5

Hardware Requirements



The hardware requirements for the Home Automation System consist of a

computer controlled
switching mechanism that will control the device to be
automated
.

















Figure 2.
2


PIC16F84A Microcontroller


This hardware is based heavily on the main chip on our
project

that is
PIC1
6F84A

.

Detailed Description
:
16F84 A PIC The versatile 16F84 A FLASH/EEPROM
microcontroller with its easy
-
to
-
l
earn instruction set (only 35 single word instructions)
allows the same device package to be used for prototyping and production. In addition,
with In
-
Circuit
-
Serial Programming™, the designer can update code without the device
being removed from the end a
pplication circuit board. PIC 16F84 A contains 1024x14
word of FLASH program memory, 64 data memory bytes, and 68 bytes of user RAM.
The device also features an 8
-
bit timer/counter with 8
-
bit programmable prescaler,
Watchdog timer with its own on
-
chip RC o
scillator for reliable operation, Power
-
On
-
Reset (POR) Power
-
up Timer (PWRT), Oscillator Start
-
up timer (OST) and a maximum
speed of 10MHz. 16F84 fits perfectly in applications ranging from high
-
speed
automotive and appliance motor control to low
-
power rem
ote sensors, electronic locks,
security devices and smart cards. PIC 16F84 A has 13 I/O pins and is available in the
following package options: 18 PDIP(P), 18 SOIC(SO), and 20 SSOP(SS). PIC 16F84
Features 18
-
pin Enhanced FLASH / EEPROM 8
-
bit


Beside this c
hip we will use some simple elements if circuit such as capacitors and
resistors etc. ,

We wi
ll use parallel port cable to send and receive data from chip to PC



15

2.3.6

Software Requirements




During the
stage

of research

, we use many software to integrate our pr
oject ,
thesed software varies from programming software to designing , to software for
circuits , etc , these software names
discussed before .



2.
4

Constraints


There are several external and internal constraints associated with this project.



2.4.1

External Constraints





Power Cuts

-

One of the external constraints is the possibility of unreliability of
electrical power in the home. The system should be
cap
able
of

operat
ing

and
function
ing

correctly even
after such an event has occurred.




Damage of
devices
:
-

this

condition will be series condition and there is no way
to know the status of the device in this condition .


2.4.2


Internal Constraints




Software
-

The development of this project will be constrained to
using
the Java
programming language

and
related APIs
.




Functionality
-

The functionally of the Home Automation system will be
constrained to operating on only
leds that will act as the devices on home because
the difficulties of high electricity and components that will cannot treate the high
po
wer .





16












High Level
Design

















17


Section
3


High Level Design

The overall design approach of the project will be object
-
oriented design using
Java. The Home Automation System will
be web based and
use several server
-
side Java
technol
ogies

.



3.1 System Architecture


The proposed architecture for the Home Automation System will be Client/Server
based as the system will be accessed remotely and
also
accommodate several users at any
time.

The use of server
-
side Java technologies lik
e Servlets will provide a way to create
a secure, thin
-
client, multi
-
tiered web application. These technologies are ideal as they
can handle transaction and state management, multithreading, resource pooling, and other
low
-
level details.


The diagram belo
w shows a
basic
high level representation of the system.




Figure 3.1
Basic
h
igh l
evel representation








18


3.1.1
Layers

Architecture

The Home Automation System will feature
a three
-
tier architecture.



Front
-
End
layer
: Client Side Graphical User Inte
rface
.

This
layer

will c
onsist of static and dynamically generated web
pages. Dynamic content will be generated by servlets.



Middle
-

layer
: Web Server / Servlets
.


This
layer

will c
onsist

of a lightweight web server
such as

Tomcat to
handle user requests
and responses.




Back
-
End
layer
: Database Server.


This
layer

will c
onsist

of
an Access
2000
database

which

stores
information
about

users and device
s.

Database access logic will
use JDBC
/ODBC

& SQL

to
query, insert and
update information
.

3.1.2 Technolo
gy Architecture

The
use of
Java

will extend the functionality of the web server. Each of
the Java components will handle a specific request from the client. The
web
browser sends each online request to a web server where it will be processed.
Using logic
based on the type of request, the Java will query or update the
database
or text file
as
required

and send
s

the necessary response to the user.

The following server
-
side components will be required;



Log In



Log Out



View
Device
s




Turn On/off Device


19

3.1.3

Project Architecture



The project architecture consists of four parts:


1)


Client implementations: GUI (HTML &
JSP

generated code)

2)


Server implementations: Client request handling.

3)


Database handling: Database connectivity and suppor
t for Server.

4)


Administrator: Adding or removing new devices to the system.




3.
1.4

State Diagram


The state diagram below illustrates the normal states for a User and Administrator
entering the Home Automation System website.







Figure 3.
2

St
ate Diagram






20










3.2

Architecture Details


Java JDBC

technology will be used for database connection.



Figure 3.
3

Java JDBC/ODBC Overview




SQL,

(Structured Query Language) will be used to

update

and query the
databas
e.



HTML
(Hypertext Mark
-
up Language) will be used for web page design
and implementation.



JSP

:
used to do dynamic web pages that control the device and users

.



Java
Special

packages

:

will be used to allow communication between
the server and the
Chip
circuit .






21













3.4


System Interfaces


3.4.1 User Interface Design




The user interface will feature the use of meaningful icons, which will allow the
user to easily identify options available. The buttons and function by which the user is
able
to interact with the Home Automation System are described below.



The different stages that are visible to the User and Administrator are:




Website


The user will be able to access the main website from any web
browser.




Login:

Here the user has to enter username and password. If the
password is wrong or the username doesn’t exist the user is notified.




Main Menu:
Once the user logs in, a navigation menu will allow the user
to select
the
options availabl
e.



The main menu
should
provide the following

functionality
;




Device Status:

The user can look at the device status. This will
indicate whether a device is already on or off. E
.
g
.

a lamp may be
already switched on and therefore can only be turned off b
y the user.



Turn On/Off Device:
The user turns on/off device.



Log Out:
The user logs out. The user is now prevented from
interacting with the Home Automation System. This makes it
impossible to press the back button on the browser and try to return to
th
e main page.




The following items
will be

visible to the Administrator:




Add / Remove Device
:

This page allows the administrator to
add/remove devices



Add / Remove
Users
:


Here the Administrator is able to
add users and
determine their leve
l of access to devices
.


22




3.4.2

System Interfaces


The Home Automation System will interface with an
integrated circuit shown
below :
-






Figure 3.
4

PIC Electrical Circuit

The
circuit as show
n

consists of the main chip PIC , and 9 resistors and 2 capacitor
s and
3 transistors .


23







Low Level
Design






















24



Section

4 Low Level Design



This low
-
level design section details the architecture of
how the Home
Automation System will be designed.



4.1 System Architecture


The proposed architec
ture for the Home Automation System
will
use Java server
-
side technologies
that
will allow a way to create a secure
,

thin
-
client
,

multi
-
tie
red web
application. The system will have to

handle transaction and state management, threading,
resource pooling, an
d other low
-
level details.

The web content for the Home Automation System will be dynamically
generated. This requires that the Tomcat web server do some additional processing of the
request in order to generate a customised response.

During research in
to web servers for this project it was discovered that there are
many different languages used today to generate the required dynamic content which
includes;



CGI



Cold

Fusion



ASP



Server
-
Side JavaScript



PHP



Java Servlet



JSP (
Java

Server Pages
)
.

Having evalu
ated the advantages and disadvantages of each of the languages
above it was decided to use Java
S
ervlets for the server
-
side dynamic content

generation
.
The use of Java servlets
was chosen because it provided the following advantages;

o

plat
form independence

o

run
s

on
in Java Virtual Machine on the
web
server, so it is safe and portable

o

can be used
across operating system
s

o

can be used
across web server
s(java enabled)

o

all requests are handled by separate threads within the web server process




25



4.1.1 Clie
nt/Sever Architecture

The table below shows the proposed Client/Server architecture:


Tier


Installed On




Function


Client

Any number of client desktop
computers.

Web application presentation and
ac
cepts inputs from the user.


Server

Web server



Apache2.0/
Tomcat 4

Execution of the web application
.


Database

Web server



as a data source
on this computer.

Stores user and device information.


4.1.2
Software
Required

The table below shows

software required for the Home Automation System web
application to operate:



Tier


Component


Software
R
equire
d


Client

Operating System

Windows 98,NT,2000,XP,Mac OS

Web Browser

Internet Explorer
4+
and Netscape Navi
gator

6
+

Runtime
Environment

JRE
1.4

Server

Operating System

Windows XP Pro

Web Server

Apache 2.0/
Tomcat 4, Java enabled web
server.

PIC Chip

PIC16F84A

Database

Operating System

Windows XP Pro


26

Database

Access 2000





4.1.
3

System Features

The Home Automation System will have the following features;



The Home Automation System will be developed to operate
across
a LAN

intranet using

a

10BaseT
Ethernet

Hub.

The user (Client) will log into a remote
c
omputer

from the web server
.

The user comput
er and the web server computer
will operate on this LAN.

See Figure 4.1








User



10BaseT Hub



Web server


Figure 4.1 Network Overview





The web server’s IP address will be fixed
. This IP ad
dress cannot change as the
java classes will reference this address in the
ir

code.




The Apache/Tomcat web server will be servlet enabled and will
provide
the
TCP/IP
services required.




The HomeGateway
java
application will run on the web server in order to

accept
user commands. This application needs to be running at all times.



To
control
the

devices,
the web server communicates with
PIC Chip

computer
.




A database called
DB

will be added as a data source on the web server.




A
ccess to website
will require

authentication.


27




The
user
will require a
friendly interface to the Home Automation System.







4.2

Architecture Details



The implementation and design of each of the classes
,

and there is t
he methods
required
for
each of the classes
,

are
listed

below.



Authorisation

Script



Authorises user to the system.

o

checkuser(User p)

o

checklevel(User p)

o

checklevelstatus(String lid)

o

username(User p)





Device Control



Encodes/decodes authorisation to the server for security.

o

taskname(String lid)

o

updatetask
(int status,String id)




Database



Handles the database.

o

getNextRow()

o

updateQuery()

o

getTableQuery()



4.3

Database Design

The database
used in this project is called DB and
will be implemented in
Microsoft Access 2000
.

Access 2000 will be used during

the testing phase of the
project.
Several SQL scripts are required to create the tables and several others
to populate the database with data for testing purposes.


28

There will be basically
4

tables, representing the Automation Devices and
the Users Details
. The tables and brief explanations
are

as follows;



admin
:

describe the admins of the system




user
:
Lists
users and their names

and levels of access
.



job
:
each user and what is the device that can control
.



Task :

describe the devices and their status


A d
iagram
of the DB database tables
is shown below;





Figure 4.
2


DB database tables.

Table Details


Table 1:
admin








ID (Primary Key)

Numeric

Name

Alphabetic

psw

Alphabetic

Address

Alphabetic

Email

Alphabetic




29









Table 2:
user

ID (Primary Key)

Numeric

Name

Alphabetic

psw

Alphabetic

Address

Alphabetic

Email

Alphabetic



Table 3:
jo
b

UID

(
Primary

Key)

Numeric

LID

Numeric



Table 3: task

ID

(
Primary

Key)

Numeric

Name

Alphabetic

Status

Numeric




4.
4


User Interface Design



Th
is

section
will
show screenshots of

the
Home Automation System’s online
user
interface.

The screensho
ts shown are early prototypes and are likely to change
significantly during the development of this project.


4.
4.1


S
creen
s
hot

1


Index Page


This is the starting page “index.html”. A screen shot of the index page is shown
below;




Figure 4.
1
2

i
ndex page screenshot




4.
4.2


S
creen
s
hot

2


Login

Page


30


This is the main login page for users.

The user enters
their

User

name and
Password
.


The default username is;
1

The default password is;
1







Figure 4.
1
3

Login w
eb page screenshot









4.
4.3


S
creen
s
hot

3


Main

Page




This is the main page for selecting
the
automation devices. The user will be able
to view information about the automation devices. Further, the user is capable to view the
status of the au
tomation devices.






Figure 4.
1
4

Main web page screenshot












4.
4.4


S
creen
s
hot

4


Add Device




This page is where the administrator can add device to the Home Automation
System.



31





Figure 4.
1
5

Add Device web page screenshot













4.
4.5


S
creen
s
hot

5


Edit Device


This page is where the administrator can
edit


device
in

the Home Automation
System

e.g.
deleting

a particular device.



Figure 4.1
6

Edit

Device web page screenshot


























32




























Code implementation




33









5.1
Code implementation
:
-



1)

first code below is used to program the pic to meet our goals in this project .


PROCESSOR 16f84

#include "p16f84.inc"

__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC


;****************Bloc
k of variables********************


Cblock 0x0C


var1


number


endc

;******************************************************



ORG 0x00


goto Main


ORG 0x04


goto Main



Main


bSf STATUS,RP0


movlw 0x00


movwf TRISb


mo
vlw 0x07


movwf TRISa



;initially output zeros


bcf STATUS,RP0


34


movlw 0x00


movwf portb




begin


bcf STATUS,RP0


movfw porta


andlw 0x07


movwf var1



andlw 0x03


sublw 0x02


btfsc status,Z


call Light



movfw

var1


andlw 0x03


sublw 0x01


btfsc status,Z


call Gate



movfw var1


andlw 0x03


addlw 0x01


sublw 0x01


btfsc status,Z


call Fan



goto begin



;***********************************************************************
****
***********************




delay



bcf STATUS,RP0



clrf TMR0


movlw 5


bsf STATUS,RP0


movwf OPTION_REG



movlw 10


35


movwf number


q2 bcf INTCON,T0IF

q1 btfss INTCON,T0IF


goto q1



decfsz number,1


goto q2


bcf STATUS
,RP0


RETURN

;***********************************************************************
***

;***********************************************************************
***

;***********************************************************************
***



Light



movfw var1


andlw 0x04


sublw 0x04


btfsc status,Z


goto b2


bcf portb,2


call delay


;return


goto begin



b2


bsf portb,2


call delay


goto begin


;***********************************************************************
***



Ga
te


movfw var1


andlw 0x04


sublw 0x04


btfsc status,Z


goto b1


bcf portb,1


call delay


;return


goto begin


36



b1


bsf portb,1


call delay


goto begin


;***********************************************************************
***



Fan


movfw var1


andlw 0x04


sublw 0x04


btfsc status,Z


goto b0


bcf portb,0


call delay


;return


goto begin



b0


bsf portb,0


call delay


goto begin




;***********************************



END


2)

next this is the code of ja
va files and classes nad fuctions serve the project




Check.java



package code.jsp.project1;


import java.io.*;

import java.util.*;

import java.sql.*;


public class Check{




private Connection c
onnection;



private Statement statement;


37




public Check() throws Exception {






Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


String sourceURL = "jdbc:odbc:p";


connection =


DriverManager.getConnection(sourceURL,"sa",
"sa");








statement=connection.createStatement();




}





//*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/






public boolean checkuser(User p) throws SQLException


{





String id=p.getId();



id=id.trim();



String psw=p.getPsw();



psw=psw.trim();






String sql="select name from user where id='"+id+"' and psw='"+psw+"'";





ResultSet results=statement.executeQuery(sql);//"select name from user"










while(results.next()){




String temp=results.getStri
ng("name");




if(temp!=null)





return true;




}







return false;


}



//*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/






public void checklevel(User p) throws SQLException


{





String id=p.getId();



i
d=id.trim();







String sql="select lid from job where uid='"+id+"'";





ResultSet results=statement.executeQuery(sql);








while(results.next()){




String temp=results.getString("lid");




p.addLevel(temp);





}







38



}




//
*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/






public String checklevelstatus(String lid) throws SQLException


{








lid=lid.trim();






String sql="select status from task where id='"+lid+"'";







ResultSet re
sults=statement.executeQuery(sql);










while(results.next()){




String temp=results.getString("status");




temp=temp.trim();




return temp;





}








return "xxx";








}




//*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*
/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/






public String taskname(String lid) throws SQLException


{








lid=lid.trim();






String sql="select name from task where id='"+lid+"'";







ResultSet results=statement.executeQuery(sql);










while(results.next()){




String temp=results.getString("name");




temp=temp.trim();




return temp;





}








return "xxx";








}





//*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/






public void updatetask(int status,String id) throws SQLException


{








id=id.trim();





39



String sql="update task set status="+status+" where id='"+id+"'";







statement.executeUpdate(sql);


















}




//*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/






public void username(User p) throws SQLException


{








String id=p.getId();



id=id.trim();






String sql="select name from user where id='"+id+"'";







ResultSet results
=statement.executeQuery(sql);










while(results.next()){




String temp=results.getString("name");




temp=temp.trim();




p.setName(temp);





}














}





//*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/






/**public void addGuest(GuestBean guest) throws SQLException{






statement.executeUpdate("insert into guests(firstName,lastName,email)
values ('"+



guest.getFirstName()+"','"+guest.getLastName()+"','"+guest.getEmail(
)+"')");


}*/





//*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/*
\
*/






protected void finalize(){



try{




statement.close();




connection.close();



}



catch(SQLException e){




e.printStackTrace();



}


40


}




/*public sta
tic void main(String at[]){



//System.out.println("qqqqqqqqqqqq");



User u=new User();



u.setId("123");



u.setPsw("123");



//System.out.println(u.getId());



//System.out.println(u.getPsw());



try{






Check c=new Check();



if(c.checkuser(u))





{System.out.println("qqqqqqqqqqqq");}







System.out.println("*************************");



System.out.println(c.checklevelstatus("3"));



}



catch(Exception e){



}


}*/



}




User.java




package code.jsp.project1;


import java.util.*;


public cla
ss User{




private String id;


private String psw,name,email,address;


private Vector levels;




public User(){



levels=new Vector();


}





public void setId(String x){



id=x;


41


}




public String getId(){



return id;


}


//*******************
***********************


public void setPsw(String x){



psw=x;


}




public String getPsw(){



return psw;


}


//********************************************


public void setName(String x){



name=x;


}




public String getName(){



return nam
e;


}






//********************************************


public void addLevel(String x){



levels.add(x);


}




public Vector getLevel(){



return levels;


}



}


3)
Code of Jsp files is attached software with project












42



























Conclusion











43













Section
6

Conclusions


The project
in general
has been very successful.

T
he
software

produced for the
project is functionally correct, reasonably robust, and usable.
The project
has
met
all
of
the
General and Non
-
F
unctiona
l
R
equirements stated
in Section 2
, and in addition, has
been implemented in a modular fashion, which c
an

be
easily
modified or rewritten

at a
later stage
.


The user interface is easy to use, and works in
all

web browser
s
. It does
not
require

any
propriety

interfaces
, applets or plug
-
ins

to operate
. This means that the
Home
Automation System

is accessible from any web browser

and that
the
system

c
ould be
usable from anywhere on the Internet

and therefore
from
anywhere on the planet
!


The
software

is robust.

The design of the
software

means that most errors
a
re

caught in a non
-
fatal manner, meaning that the
software

can continue executin
g

even
after a
bad request.



6
.1

Possible
Future

Software
Changes


As the
software

was being developed, a number of min
or shortcomings in the
system were found. T
here are a number of changes to the design that could be considered

in future additions
to

the software
;





Due

to

the nature of
the

type of

PIC

module used
in

this project
,
the

module

d
id

not have the ability to
respond to a request for

status, so it is not possible to query
devices for status when the
Home Automation S
ystem
is

first
started.
Ther
e
fore
,

w
hen the system starts, the status of devices is
at first
unknown, and so is
assumed to be

Off


for
each

device
.
.



The

performance of the
software

is something that could

also

be improved
by
optimising the code if
given more time.

The performance gains to do this however
would only be noticeable on very slow connections to the Internet (<28.0
k
bps).



44



T
here are a num
ber of classes
such as the
Check

class that could
have
be
en

used

so
that
the overall system
would

be faster
and

more memory efficient.


The changes mentioned here wo
uld not be
too
complex to implement.

T
he modular
design of the system would allow for chang
es to be made without significant changes to
the
existing code.


6
.
2

Final Thoughts


There is plenty of potential for expansion and commercial development for this
project. The areas that were selected for implementation in the Home Automation System
p
rovided enough complexity to make the
software

useful and provide a good proof of
concept.














Section
7

References


1.
‘Home Automation Page’
-

http://www.geocities.com/ido_bartana/

2
.

M
icrocontroller Lecture Notes for "Eng Mo'ayyad Al
-
mobayyed"



3.
Sun Microsystems Java Page
-

http://java.sun.com/

4.
Internet
searching
.














45