際際滷

際際滷Share a Scribd company logo
embedded report
ABSTRACT
Raspberry Pi is a credit card sized computer that plugs into a computer monitor or TV, and uses a
standard keyboard and mouse. It is a capable little device that enables people of all ages to explore
computing and to learn how to program in languages like java and python. It is capable of doing
everything you would expect a desktop computer to do, from browsing the internet, playing high
definitionvideo,makingspreadsheets,wordprocessingandplayinggames. Inthisproject,we are using
the raspberrypi controllertomonitorany deviceswirelesslyoveranetwork.We have chosenwifi as we
can directlyinterface themwithyourcomputer.Itmeansthatyoudont need any additional module or
antenna. We needtodesigna webpage usinghtml,phpandjavascriptwhichisthe displayingscreenfor
thisproject.We write the maincode using the java scriptand phpand html for calling the code which is
in java script. We need LEDs to check the output if its working right and few resistors to support the
LEDs. We inputthe code inthe raspberrypi itself sothatwe can use the controlleranywhere andwe can
getthe outputbysimplyconnecting it to any external display device. We can even control the devices
on laptops and even on mobile phones. This would help a lot for the home automation.
ACKNOWLEDGEMENT
We, group #8: Kushal Singampalli (FS3620), Prandurangarao Challagundla (FQ8137) and Gopikanth
Srikar Manoj Tatavarthi (FR5950) have completed our project, WiPi home, a wifi based home control
unit as our main project for the course ECE 5620 for winter 2015 semester, under the supervision of
our professor Dr.Syed Masud Mahmud in Wayne state university. We thank our instructor for all the
help and for the course he taught us.
CONTENTS
1. Components
2. Projectdescription
3. Hardware connections
4. Configuringthe raspberrypi
5. Writingthe code
6. Inputtingthe code
7. Testing
INTRODUCTION
We wantedtodo somethingtocontrol devices wirelessly. Upon some research, we chose raspberry pi
controller as it is compatible for wireless transfer of data. A raspberry pi controller, though it is
compatible forwirelessdatatransfer,itdoesnothave a wirelessadapteronboard. Soa simple wireless
adapter plugged in to it through a usb port would add an additional feature. Then we start the project
by configuringthe raspberrypi,enablingthe wirelessadapterbycodingand then deploying the written
code in javascript forcallingthe functions. We have usedhttp andphp languagesfordesigning the web
page and a web server is required to interface the device and the web page. So we have used a web
serverbyname Apache webserver that interfaces both the raspberry pi and the web page as well. We
thenconnectthe hardware to testthe code.We donthave to connectthe whole circuitbutjusta single
connectionwoulddo.If the testgivesoutpositive result,we thenscriptthe maincode for calling all the
8 LEDs. Then comes the main task of globalizing this wireless network from local to control the device
from any device that has Internet in it. By using a port forwarding on the router, we can achieve this.
Thus we can make this project work.
BACKGROUND:
Our project has so much to deal with. Beginning from the controller, we had many challenges to be
facedduringthe processof beginningtill finishing it. We wanted to control the devices wirelessly, but
we do not really know which controller to use. There were a variety of controllers to choose from like
PICmicro controller,ArduinoUno,Raspberrypi andothers.Butwe chose Raspberry pi as our controller
as we found that its features enables to explore more in our project. We basically wanted to do
something wirelessly, as the raspberry pi has this feature of being compatible for wireless transfer of
data, we thoughtthiswouldbe the bestforus. So we boughtan external wirelessadapterthatconnects
the raspberry pi through USB. Thus we can enable the wireless feature on our raspberry pi. Then
choosing the hardware like LEDs, resistors to support LEDs were the next two tasks that we did. We
chose 270 ohmsresistorsastheyglowthe LEDs brightenough.We used a router that we have at home,
so we dinthave any trouble creatingalocal within our raspberrypi and our laptop. The toughest part is
coding.We are not savvywithcodinga raspberrypi. So we went through few instructions and tutorials
on youtube andotherwebsiteswhere theytaughtusthe basic commands and other commands for the
desiredoperations.Andaswe wantedtouse a website as an interface instead of an application, as it is
difficultforusat thispointof time to getexpertiseincomputerlanguagestobuildanapp.So we chose a
website as basic http would be enough to design the skeleton and CSS for the page style, PHP for the
page interactions with the server and Java script for the interactions with the user. Thus just the basic
knowledge in these four languages can help us in building a website for our project.
REPORT:
HARDWARE USED:
1. Raspberry pi controller
2. WiPi wireless adapter
3. Wireless router
4. Bread board
5. LEDs
6. Resistors
7. Connecting wires
8. Display device
9. HDMI cable
10. Key board
11. Mouse
LANGUAGES USED:
1. HTTP
2. CSS
3. PHP
4. JAVA
SERVER USED:
1. Apache web server
PROCEDURE:
1. Configuring the raspberry pi:
2. Configuring the wireless adapter
3. Testing the Wireless connectivity
4. Writing the raspberry code
5. Installing a webserver
6. Creating an interface
a. HTML
b. PHP
c. JavaScript
d. CSS
7. Deploying the written codes to Raspberry pi
8. Connecting the hardware
9. Testing the project
10. Globalizing the interface
PROCESS IN DETAIL:
1. Configuring the raspberry pi:
Raspberry pi comes with many features but we have to configure it as per our
requirements like creating directories and other files which we need for our project.
Firstpart is installingaWiPi library.Itsimplifiesalotusingthe raspberry pi GPIOs that is
general input/output, a single command instead of a long process. It also means that
youcan use itin anyof our C codes.But,howeverwe dintuse Cprogrammingas we felt
that programmingandcontrolling our raspberry pi with GPIOs would help us deal with
the controller to some more extent and would even help us in debugging the errors if
we get any. This is a software that was made by Gordan that with a library. It allows us
to control the GPIOs directlyinasingle commandline. Buthowever,this processisa lot
slower than using a C program. We first need to install it on our RasPi using a ./build
command which enables us to use the GPIO utility. Now we type gpio mode 0 out
commandto testit and if no errorpops up,then its fine else we have to build a library
again.
2. Testing the GPIO
We can simply connect any LED to any gpio pins(##) on the raspberry pi and
select it as an output. We input a command gpio mode ## out for it, where ## is the
pin number and out is for output. Now, we use gpio g write ## 1 to turn on the
LED and gpio g write ## 0 to turn it off. Thus we can make sure that the wipi
library is installed correctly on our raspberry pi.
3. Configuring the wireless adapter
We are using an external wireless adapter to enable the wireless connectivity
feature of our raspberry pi. We bought a wipi, as told before, we connected it to a usb
slotgivenonraspi.Now,we needtoconfigure itandevenconnectitto our local.Before
doing this, we have turn on our wireless router and make sure that our devices are
connected to it other than the raspi as we are configuring it now. Initially, we turn on
our raspi and log in to it using our credentials. We have to configure our wireless
adapter and connect it to our local. We need to know the network SSID and the
passwordto connectit.Afterloginginourraspi,we thengive the command sudo nano
/etc/network/interfaces which takes us to the interfaces page where we can see a
program for it. In it, we can observe some space for the local credentials written as
wpa-ssid where we give our local SSID and wpa-psk where we enter our local
password in a double inverted commas  . Then we have to hit control+x to exit the
page where x represents exiting the page. It will ask us if we want to save it, we will
save it. Then we have to restart our raspi, so we give a command sudo shutdown
now r where r represents the restart function.
4. Testing the Wireless connectivity
Once the raspi issuccessfullyrebootedafterconfiguringthe wirelessinterfaces,
we check its connectivity with our local. So after logging in, we give a command
ifconfig a whichgivesusthe detailedlistof raspi connections. In the wlan section
we can find the inet address for our raspi and even we can observe that the raspi is
communicatingwiththe local bysendingandreceivingpackets. If the local isconnected
to internet though Ethernet cable, we can check the internet connectivity by opening
our browserandcheckingsome randomwebsite andwaittosee if its loading. Thus we
can configure the wireless adapter on a raspberry pi.
5. Installing a web server
Controlling the LEDs remotely with SSH is pretty good but the interface isnt
veryuserfriendlyandtypingthe gpiocommandsisannoying.Sowe thought a graphical
interface would be better for project. First thing that came up was designing an
application, but we it takes a lot of time for us to learn the languages required for
designinganapplication.We went looking for alternatives for it on internet and found
that creating a website is the best and little easier way to create an interface as it is
compatible withall devicesandwe onlyneedfour basic languages. But before that, we
need to install a web server on our raspberry pi. We dont need any database for it,
other than just the HTTP server and its PHP extension. Lets get to installing the web
server on the raspberry pi. Give in a command sudo apt-get update which updates
the present server on the raspberry pi. And once its done, type sudo apt-get
install apache2 php5 liapache2-mod-php5 which installs the apache webserver
with its php extension. It will take sometime to install, and when it finishes, open the
browser and type the IP address of the raspberry pi or simply localhost in the address
bar of the browser. It should show us a message saying it works! which means that
the web server is installed correctly without any errors. Now, we create a index.php
page with the installed php extension by giving a command sudo nano index.php
where nanoisthe command usedtocreate somethingandindex.php is the file that we
are going to use in future.
6. Creating an interface
a. HTML: We are using the html to design the basic skeleton of the page. This is what
design the page that we are going to see and all the other calling functions.
b. PHP: The interactions with the server and the pages generation are done using the
PHP language. This is the page that contains 8 buttons that we are going to use for
controlling 8 devices; here LEDs are our devices for this project. This is the code that
turns on or turns off the LEDs.
c. JavaScript:Nowwe have to detectwhenand what the user is clicking on out of these
8 buttons. And thats where the Java script is useful. Here, we have simply added
calling events to all the 8 buttons. So when each time any of these buttons are
pressed,itusesafunction that asks gpio.php file for it and returns the answer. To be
clear,the functionof Java scripthere isto simply change the color of the button from
red to green.
d. CSS: We have used the CSS just for the basic black background. Thats it.
7. Deploying the written codes to Raspberry pi
Whenthe interface isready,we needtodeployit to our raspi for the interface to work.
We need to transfer the written codes from our laptop to our device i.e. raspberry pi.
We have used a software for windows operating system by name WinSCP for
transferringfiles.Thisisone of the mostefficient and easiest software to use. We have
gone through internet for this and decided to use this software. We can fine the inet
address of our raspi by opening the wireless routers home page. Now, in WinSCP we
enterthe inetaddressasthe hostidand our raspi login id as the user and the password
as password. And before transferring the files, we have to create a new directory, we
named it as www. So command it as sudo chown R pi /var/www where R means a
recursive call andwwwisthe folderthatwe are planningtocreate.Thenwe have to get
access to transferfilesfromortothe raspi.Thuswe deploythe files to our raspberry pi.
8. Connecting the hardware
The above circuitshowsthe diagram forconnectingthe raspberrypi,LEDs and resistors.
We have randomly used gpio pins 27, 25, 24, 23,22, 18, 17 and 4. We connect the GND
to the ground of the bread board and the LEDs and resistors are connected in series
with each other and in parallel among each other.
The above picture is the circuit that we made with 8 different LEDs.
9. Testing the project
Thus, after all the above steps, we test our project by connecting the raspberry pi and
the laptop or the mobile phone, that we want to use to test the project, be connected
to the same local network. Now, we turn on the raspberry pi which directs us to page
that asks for login id and password.
The above picture is the page that gets displayed when we turn on the raspberry
Pi. Now we have to check its connectivity with the local network, so we input the
command and check the wlan status.
Thenwe start our raspi and check forour index page andthe output. The below picture
isthe screenshotof the real time view of our projects index page on a mobile phone.
We can observe the feedback in the picture, i.e. LEDs 0, 2, 5, 7 are turned on, so they
are green in color and LEDs 1, 3, 6, 8 are in off state, so they are red in color where
192.168.1.101 is the inet address of the raspberry pi.
The below picture is the real time output of our project.
10. Globalizing the interface
Our projectisnowworkingona local networkwhere the operatingmobilephone orthe
laptop has to be connected to the same local network to which the raspberry pi is
connected. In order to globalize it, we have to do the port forwarding so that we can
operate our raspberry pi device from anywhere and from any network connected to
Internet.Forthis,we triedtoopena port on our router, port 80 to be specific as its the
http port.We triedaddingourraspberrypisinetaddressto the port forwarding so that
when we type the ip to which raspberry pi is connected colon the forwarding port
number slash index.php redirects it to the raspberry pis inet address. For suppose,
214.256.219.147 is our IP and we are using port 8080 for forwarding it, then we can
simplytype 214.256.219.147:8080/index.php for controllingthe raspberrypi fromany
device thathas Internetinit. Butwe faileddoingitaswe openedaport in our routerfor
forwarding it but we could not open a port in the gateway and as its the ultimate one
for the data transfer, we can globalize it but if the university gives us an open port.
CODE:
1. INDEX File
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Raspberry Pi Gpio</title>
</head>
<body style="background-color: black;">
<!-- On/Off button's picture -->
<?php
//this php script generate the first page in function of the gpio's
status
$status = array (0, 0, 0, 0, 0, 0, 0, 0);
for ($i = 0; $i < count($status); $i++) {
//set the pin's mode to output and read them
system("gpio mode ".$i." out");
exec ("gpio read ".$i, $status[$i], $return );
//if off
if ($status[$i][0] == 0 ) {
echo ("<img id='button_".$i."' src=/slideshow/embedded-report-56029777/56029777/&
alt='off'/>");
}
//if on
if ($status[$i][0] == 1 ) {
echo ("<img id='button_".$i."'
src='data/img/green/green_".$i.".jpg' alt='on'/>");
}
}
?>
<!-- javascript -->
<script src="script.js"></script>
</body>
</html>
2. GPIO
<!-- This page is requested by the JavaScript, it updates the pin's status and
then print it -->
<?php
//Getting and using values
if (isset ($_GET["pin"]) && isset($_GET["status"]) ) {
$pin = strip_tags($_GET["pin"]);
$status = strip_tags($_GET["status"]);
//Testing if values are numbers
if ( (is_numeric($pin)) && (is_numeric($status)) && ($pin <= 7) && ($pin
>= 0) && ($status == "0") || ($status == "1") ) {
//set the gpio's mode to output
system("gpio mode ".$pin." out");
//set the gpio to high/low
if ($status == "0" ) { $status = "1"; }
else if ($status == "1" ) { $status = "0"; }
system("gpio write ".$pin." ".$status );
//reading pin's status
exec ("gpio read ".$pin, $status, $return );
//printing it
echo ( $status[0] );
}
else { echo ("fail"); }
} //print fail if cannot use values
else { echo ("fail"); }
?>
3. SCRIPT
//JavaScript, use pictures as buttons, sends and receives values to/from the Rpi
//These are all the buttons
var button_0 = document.getElementById("button_0");
var button_1 = document.getElementById("button_1");
var button_2 = document.getElementById("button_2");
var button_3 = document.getElementById("button_3");
var button_4 = document.getElementById("button_4");
var button_5 = document.getElementById("button_5");
var button_6 = document.getElementById("button_6");
var button_7 = document.getElementById("button_7");
//this function sends and receives the pin's status
function change_pin (pin, status) {
//this is the http request
var request = new XMLHttpRequest();
request.open( "GET" , "gpio.php?pin=" + pin + "&status=" + status );
request.send(null);
//receiving information
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
return (parseInt(request.responseText));
}
//test if fail
else if (request.readyState == 4 && request.status == 500) {
alert ("server error");
return ("fail");
}
//else
else { return ("fail"); }
}
}
//these are all the button's events, it just calls the change_pin function and
updates the page in function of the return of it.
button_0.addEventListener("click", function () {
//if red
if ( button_0.alt === "off" ) {
//use the function
var new_status = change_pin ( 0, 0);
if (new_status !== "fail") {
button_0.alt = "on"
button_0.src = /slideshow/embedded-report-56029777/56029777/"data/img/green/green_0.jpg";
return 0;
}
}
//if green
if ( button_0.alt === "on" ) {
//use the function
var new_status = change_pin ( 0, 1);
if (new_status !== "fail") {
button_0.alt = "off"
button_0.src = "data/img/red/red_0.jpg";
return 0;
}
}
} );
button_1.addEventListener("click", function () {
//if red
if ( button_1.alt === "off" ) {
//use the function
var new_status = change_pin ( 1, 0);
if (new_status !== "fail") {
button_1.alt = "on"
button_1.src = "data/img/green/green_1.jpg";
return 0;
}
}
//if green
if ( button_1.alt === "on" ) {
//use the function
var new_status = change_pin ( 1, 1);
if (new_status !== "fail") {
button_1.alt = "off"
button_1.src = /slideshow/embedded-report-56029777/56029777/"data/img/red/red_1.jpg";
return 0;
}
}
} );
button_2.addEventListener("click", function () {
//if red
if ( button_2.alt === "off" ) {
//use the function
var new_status = change_pin ( 2, 0);
if (new_status !== "fail") {
button_2.alt = "on"
button_2.src = "data/img/green/green_2.jpg";
return 0;
}
}
//if green
if ( button_2.alt === "on" ) {
//use the function
var new_status = change_pin ( 2, 1);
if (new_status !== "fail") {
button_2.alt = "off"
button_2.src = "data/img/red/red_2.jpg";
return 0;
}
}
} );
button_3.addEventListener("click", function () {
//if red
if ( button_3.alt === "off" ) {
//use the function
var new_status = change_pin ( 3, 0);
if (new_status !== "fail") {
button_3.alt = "on"
button_3.src = "data/img/green/green_3.jpg";
return 0;
}
}
//if green
if ( button_3.alt === "on" ) {
//use the function
var new_status = change_pin ( 3, 1);
if (new_status !== "fail") {
button_3.alt = "off"
button_3.src = /slideshow/embedded-report-56029777/56029777/"data/img/red/red_3.jpg";
return 0;
}
}
} );
button_4.addEventListener("click", function () {
//if red
if ( button_4.alt === "off" ) {
//use the function
var new_status = change_pin ( 4, 0);
if (new_status !== "fail") {
button_4.alt = "on"
button_4.src = "data/img/green/green_4.jpg";
return 0;
}
}
//if green
if ( button_4.alt === "on" ) {
//use the function
var new_status = change_pin ( 4, 1);
if (new_status !== "fail") {
button_4.alt = "off"
button_4.src = "data/img/red/red_4.jpg";
return 0;
}
}
} );
button_5.addEventListener("click", function () {
//if red
if ( button_5.alt === "off" ) {
//use the function
var new_status = change_pin ( 5, 0);
if (new_status !== "fail") {
button_5.alt = "on"
button_5.src = /slideshow/embedded-report-56029777/56029777/"data/img/green/green_5.jpg";
return 0;
}
}
//if green
if ( button_5.alt === "on" ) {
//use the function
var new_status = change_pin ( 5, 1);
if (new_status !== "fail") {
button_5.alt = "off"
button_5.src = "data/img/red/red_5.jpg";
return 0;
}
}
} );
button_6.addEventListener("click", function () {
//if red
if ( button_6.alt === "off" ) {
//use the function
var new_status = change_pin ( 6, 0);
if (new_status !== "fail") {
button_6.alt = "on"
button_6.src = "data/img/green/green_6.jpg";
return 0;
}
}
//if green
if ( button_6.alt === "on" ) {
//use the function
var new_status = change_pin ( 6, 1);
if (new_status !== "fail") {
button_6.alt = "off"
button_6.src = /slideshow/embedded-report-56029777/56029777/"data/img/red/red_6.jpg";
return 0;
}
}
} );
button_7.addEventListener("click", function () {
//if red
if ( button_7.alt === "off" ) {
//use the function
var new_status = change_pin ( 7, 0);
if (new_status !== "fail") {
button_7.alt = "on"
button_7.src = "data/img/green/green_7.jpg";
return 0;
}
}
//if green
if ( button_7.alt === "on" ) {
//use the function
var new_status = change_pin ( 7, 1);
if (new_status !== "fail") {
button_7.alt = "off"
button_7.src = "data/img/red/red_7.jpg";
return 0;
}
}
} );
CONCLUSION
Technologyisdevelopingatdayby day at fastrate, YesteryearsLivestockcartsare replacedbyMotor
vehiclesandtheyare replacedwithvehicleshighspeedandgearslaterautomaticgearshiftandnow its
like yourcar drivingitself. Soautomationis the future everythingyouposseswill be automatedwhynot
your house? The whole beauty of thisprojectliesingainingboththe technical,practical andcoding
experience andknowledge. Thisprojectcanthususedas a demoforfuture enhancementsinnear
future.

More Related Content

Viewers also liked (10)

PPSX
Landriel gallardo capdevila 2do c
Valuma Fernandez
PPTX
2015 bgs pre_p_short
s叩ndor szalai
PDF
Passage 12 Extract
Laurel Prince
PDF
Transcripts (Christopher Brown)
Christopher Brown
PPT
T uerk edebiyati_tarihi
cenap demiralay
PPTX
S4 tarea4 hemoa
Adry Hern叩ndez
PPT
Chapter03
Muhammad Ahad
PPT
Chapter14
Muhammad Ahad
PPT
Chapter06
Muhammad Ahad
Landriel gallardo capdevila 2do c
Valuma Fernandez
2015 bgs pre_p_short
s叩ndor szalai
Passage 12 Extract
Laurel Prince
Transcripts (Christopher Brown)
Christopher Brown
T uerk edebiyati_tarihi
cenap demiralay
S4 tarea4 hemoa
Adry Hern叩ndez
Chapter03
Muhammad Ahad
Chapter14
Muhammad Ahad
Chapter06
Muhammad Ahad

Similar to embedded report (20)

PPTX
Raspberry pi home automation idea
shashi gautam
PPTX
Up and running with Raspberry Pi
Shahed Mehbub
PDF
RaspberryPi_Workshop and Programming with python.
gnanithanagula
PDF
Raspberry Pi Based GPS Tracking System and Face Recognition System.
Ruthvik Vaila
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
PPT
Raspberry-Pi
Rehan Fazal
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
PPTX
Raspberry Pi Introductory Lecture
Syed Umaid Ahmed
PDF
Raspberry pi overview
Matthew Karas
PDF
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Mohamed Abdallah
PPTX
Project-make a public website server using raspberry pi
Fahim Hossain
PDF
Embedded Web Server based Home Automation using Raspberry PI
Editor IJMTER
PPTX
introduction to Raspberry pi
Mohamed Ali May
PPTX
Raspberry Pi - Unlocking New Ideas for Your Library
Brian Pichman
PPTX
Capstone_Project.ppt
Dhruvkumar Panchal
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
PDF
Amity Raspberry Jam
Vishal Aditya
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
PPTX
Introduction to Raspberry Pi
ehrenbrav
Raspberry pi home automation idea
shashi gautam
Up and running with Raspberry Pi
Shahed Mehbub
RaspberryPi_Workshop and Programming with python.
gnanithanagula
Raspberry Pi Based GPS Tracking System and Face Recognition System.
Ruthvik Vaila
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
Raspberry-Pi
Rehan Fazal
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
Raspberry Pi Introductory Lecture
Syed Umaid Ahmed
Raspberry pi overview
Matthew Karas
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Mohamed Abdallah
Project-make a public website server using raspberry pi
Fahim Hossain
Embedded Web Server based Home Automation using Raspberry PI
Editor IJMTER
introduction to Raspberry pi
Mohamed Ali May
Raspberry Pi - Unlocking New Ideas for Your Library
Brian Pichman
Capstone_Project.ppt
Dhruvkumar Panchal
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
Amity Raspberry Jam
Vishal Aditya
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
WiseNaeem
Introduction to Raspberry Pi
ehrenbrav
Ad

embedded report

  • 2. ABSTRACT Raspberry Pi is a credit card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing and to learn how to program in languages like java and python. It is capable of doing everything you would expect a desktop computer to do, from browsing the internet, playing high definitionvideo,makingspreadsheets,wordprocessingandplayinggames. Inthisproject,we are using the raspberrypi controllertomonitorany deviceswirelesslyoveranetwork.We have chosenwifi as we can directlyinterface themwithyourcomputer.Itmeansthatyoudont need any additional module or antenna. We needtodesigna webpage usinghtml,phpandjavascriptwhichisthe displayingscreenfor thisproject.We write the maincode using the java scriptand phpand html for calling the code which is in java script. We need LEDs to check the output if its working right and few resistors to support the LEDs. We inputthe code inthe raspberrypi itself sothatwe can use the controlleranywhere andwe can getthe outputbysimplyconnecting it to any external display device. We can even control the devices on laptops and even on mobile phones. This would help a lot for the home automation.
  • 3. ACKNOWLEDGEMENT We, group #8: Kushal Singampalli (FS3620), Prandurangarao Challagundla (FQ8137) and Gopikanth Srikar Manoj Tatavarthi (FR5950) have completed our project, WiPi home, a wifi based home control unit as our main project for the course ECE 5620 for winter 2015 semester, under the supervision of our professor Dr.Syed Masud Mahmud in Wayne state university. We thank our instructor for all the help and for the course he taught us.
  • 4. CONTENTS 1. Components 2. Projectdescription 3. Hardware connections 4. Configuringthe raspberrypi 5. Writingthe code 6. Inputtingthe code 7. Testing
  • 5. INTRODUCTION We wantedtodo somethingtocontrol devices wirelessly. Upon some research, we chose raspberry pi controller as it is compatible for wireless transfer of data. A raspberry pi controller, though it is compatible forwirelessdatatransfer,itdoesnothave a wirelessadapteronboard. Soa simple wireless adapter plugged in to it through a usb port would add an additional feature. Then we start the project by configuringthe raspberrypi,enablingthe wirelessadapterbycodingand then deploying the written code in javascript forcallingthe functions. We have usedhttp andphp languagesfordesigning the web page and a web server is required to interface the device and the web page. So we have used a web serverbyname Apache webserver that interfaces both the raspberry pi and the web page as well. We thenconnectthe hardware to testthe code.We donthave to connectthe whole circuitbutjusta single connectionwoulddo.If the testgivesoutpositive result,we thenscriptthe maincode for calling all the 8 LEDs. Then comes the main task of globalizing this wireless network from local to control the device from any device that has Internet in it. By using a port forwarding on the router, we can achieve this. Thus we can make this project work.
  • 6. BACKGROUND: Our project has so much to deal with. Beginning from the controller, we had many challenges to be facedduringthe processof beginningtill finishing it. We wanted to control the devices wirelessly, but we do not really know which controller to use. There were a variety of controllers to choose from like PICmicro controller,ArduinoUno,Raspberrypi andothers.Butwe chose Raspberry pi as our controller as we found that its features enables to explore more in our project. We basically wanted to do something wirelessly, as the raspberry pi has this feature of being compatible for wireless transfer of data, we thoughtthiswouldbe the bestforus. So we boughtan external wirelessadapterthatconnects the raspberry pi through USB. Thus we can enable the wireless feature on our raspberry pi. Then choosing the hardware like LEDs, resistors to support LEDs were the next two tasks that we did. We chose 270 ohmsresistorsastheyglowthe LEDs brightenough.We used a router that we have at home, so we dinthave any trouble creatingalocal within our raspberrypi and our laptop. The toughest part is coding.We are not savvywithcodinga raspberrypi. So we went through few instructions and tutorials on youtube andotherwebsiteswhere theytaughtusthe basic commands and other commands for the desiredoperations.Andaswe wantedtouse a website as an interface instead of an application, as it is difficultforusat thispointof time to getexpertiseincomputerlanguagestobuildanapp.So we chose a website as basic http would be enough to design the skeleton and CSS for the page style, PHP for the page interactions with the server and Java script for the interactions with the user. Thus just the basic knowledge in these four languages can help us in building a website for our project.
  • 7. REPORT: HARDWARE USED: 1. Raspberry pi controller 2. WiPi wireless adapter 3. Wireless router
  • 8. 4. Bread board 5. LEDs 6. Resistors
  • 9. 7. Connecting wires 8. Display device 9. HDMI cable
  • 10. 10. Key board 11. Mouse LANGUAGES USED: 1. HTTP 2. CSS 3. PHP 4. JAVA SERVER USED: 1. Apache web server
  • 11. PROCEDURE: 1. Configuring the raspberry pi: 2. Configuring the wireless adapter 3. Testing the Wireless connectivity 4. Writing the raspberry code 5. Installing a webserver 6. Creating an interface a. HTML b. PHP c. JavaScript d. CSS 7. Deploying the written codes to Raspberry pi 8. Connecting the hardware 9. Testing the project 10. Globalizing the interface PROCESS IN DETAIL: 1. Configuring the raspberry pi: Raspberry pi comes with many features but we have to configure it as per our requirements like creating directories and other files which we need for our project. Firstpart is installingaWiPi library.Itsimplifiesalotusingthe raspberry pi GPIOs that is general input/output, a single command instead of a long process. It also means that youcan use itin anyof our C codes.But,howeverwe dintuse Cprogrammingas we felt that programmingandcontrolling our raspberry pi with GPIOs would help us deal with the controller to some more extent and would even help us in debugging the errors if we get any. This is a software that was made by Gordan that with a library. It allows us to control the GPIOs directlyinasingle commandline. Buthowever,this processisa lot slower than using a C program. We first need to install it on our RasPi using a ./build command which enables us to use the GPIO utility. Now we type gpio mode 0 out
  • 12. commandto testit and if no errorpops up,then its fine else we have to build a library again. 2. Testing the GPIO We can simply connect any LED to any gpio pins(##) on the raspberry pi and select it as an output. We input a command gpio mode ## out for it, where ## is the pin number and out is for output. Now, we use gpio g write ## 1 to turn on the LED and gpio g write ## 0 to turn it off. Thus we can make sure that the wipi library is installed correctly on our raspberry pi. 3. Configuring the wireless adapter We are using an external wireless adapter to enable the wireless connectivity feature of our raspberry pi. We bought a wipi, as told before, we connected it to a usb slotgivenonraspi.Now,we needtoconfigure itandevenconnectitto our local.Before doing this, we have turn on our wireless router and make sure that our devices are connected to it other than the raspi as we are configuring it now. Initially, we turn on our raspi and log in to it using our credentials. We have to configure our wireless adapter and connect it to our local. We need to know the network SSID and the passwordto connectit.Afterloginginourraspi,we thengive the command sudo nano /etc/network/interfaces which takes us to the interfaces page where we can see a program for it. In it, we can observe some space for the local credentials written as wpa-ssid where we give our local SSID and wpa-psk where we enter our local password in a double inverted commas . Then we have to hit control+x to exit the page where x represents exiting the page. It will ask us if we want to save it, we will save it. Then we have to restart our raspi, so we give a command sudo shutdown now r where r represents the restart function. 4. Testing the Wireless connectivity Once the raspi issuccessfullyrebootedafterconfiguringthe wirelessinterfaces, we check its connectivity with our local. So after logging in, we give a command
  • 13. ifconfig a whichgivesusthe detailedlistof raspi connections. In the wlan section we can find the inet address for our raspi and even we can observe that the raspi is communicatingwiththe local bysendingandreceivingpackets. If the local isconnected to internet though Ethernet cable, we can check the internet connectivity by opening our browserandcheckingsome randomwebsite andwaittosee if its loading. Thus we can configure the wireless adapter on a raspberry pi. 5. Installing a web server Controlling the LEDs remotely with SSH is pretty good but the interface isnt veryuserfriendlyandtypingthe gpiocommandsisannoying.Sowe thought a graphical interface would be better for project. First thing that came up was designing an application, but we it takes a lot of time for us to learn the languages required for designinganapplication.We went looking for alternatives for it on internet and found that creating a website is the best and little easier way to create an interface as it is compatible withall devicesandwe onlyneedfour basic languages. But before that, we need to install a web server on our raspberry pi. We dont need any database for it, other than just the HTTP server and its PHP extension. Lets get to installing the web server on the raspberry pi. Give in a command sudo apt-get update which updates the present server on the raspberry pi. And once its done, type sudo apt-get install apache2 php5 liapache2-mod-php5 which installs the apache webserver with its php extension. It will take sometime to install, and when it finishes, open the browser and type the IP address of the raspberry pi or simply localhost in the address bar of the browser. It should show us a message saying it works! which means that the web server is installed correctly without any errors. Now, we create a index.php page with the installed php extension by giving a command sudo nano index.php where nanoisthe command usedtocreate somethingandindex.php is the file that we are going to use in future.
  • 14. 6. Creating an interface a. HTML: We are using the html to design the basic skeleton of the page. This is what design the page that we are going to see and all the other calling functions. b. PHP: The interactions with the server and the pages generation are done using the PHP language. This is the page that contains 8 buttons that we are going to use for controlling 8 devices; here LEDs are our devices for this project. This is the code that turns on or turns off the LEDs. c. JavaScript:Nowwe have to detectwhenand what the user is clicking on out of these 8 buttons. And thats where the Java script is useful. Here, we have simply added calling events to all the 8 buttons. So when each time any of these buttons are pressed,itusesafunction that asks gpio.php file for it and returns the answer. To be clear,the functionof Java scripthere isto simply change the color of the button from red to green. d. CSS: We have used the CSS just for the basic black background. Thats it. 7. Deploying the written codes to Raspberry pi Whenthe interface isready,we needtodeployit to our raspi for the interface to work. We need to transfer the written codes from our laptop to our device i.e. raspberry pi. We have used a software for windows operating system by name WinSCP for transferringfiles.Thisisone of the mostefficient and easiest software to use. We have
  • 15. gone through internet for this and decided to use this software. We can fine the inet address of our raspi by opening the wireless routers home page. Now, in WinSCP we enterthe inetaddressasthe hostidand our raspi login id as the user and the password as password. And before transferring the files, we have to create a new directory, we named it as www. So command it as sudo chown R pi /var/www where R means a recursive call andwwwisthe folderthatwe are planningtocreate.Thenwe have to get access to transferfilesfromortothe raspi.Thuswe deploythe files to our raspberry pi. 8. Connecting the hardware The above circuitshowsthe diagram forconnectingthe raspberrypi,LEDs and resistors. We have randomly used gpio pins 27, 25, 24, 23,22, 18, 17 and 4. We connect the GND to the ground of the bread board and the LEDs and resistors are connected in series with each other and in parallel among each other. The above picture is the circuit that we made with 8 different LEDs.
  • 16. 9. Testing the project Thus, after all the above steps, we test our project by connecting the raspberry pi and the laptop or the mobile phone, that we want to use to test the project, be connected to the same local network. Now, we turn on the raspberry pi which directs us to page that asks for login id and password. The above picture is the page that gets displayed when we turn on the raspberry Pi. Now we have to check its connectivity with the local network, so we input the command and check the wlan status.
  • 17. Thenwe start our raspi and check forour index page andthe output. The below picture isthe screenshotof the real time view of our projects index page on a mobile phone. We can observe the feedback in the picture, i.e. LEDs 0, 2, 5, 7 are turned on, so they are green in color and LEDs 1, 3, 6, 8 are in off state, so they are red in color where 192.168.1.101 is the inet address of the raspberry pi. The below picture is the real time output of our project. 10. Globalizing the interface Our projectisnowworkingona local networkwhere the operatingmobilephone orthe laptop has to be connected to the same local network to which the raspberry pi is connected. In order to globalize it, we have to do the port forwarding so that we can operate our raspberry pi device from anywhere and from any network connected to
  • 18. Internet.Forthis,we triedtoopena port on our router, port 80 to be specific as its the http port.We triedaddingourraspberrypisinetaddressto the port forwarding so that when we type the ip to which raspberry pi is connected colon the forwarding port number slash index.php redirects it to the raspberry pis inet address. For suppose, 214.256.219.147 is our IP and we are using port 8080 for forwarding it, then we can simplytype 214.256.219.147:8080/index.php for controllingthe raspberrypi fromany device thathas Internetinit. Butwe faileddoingitaswe openedaport in our routerfor forwarding it but we could not open a port in the gateway and as its the ultimate one for the data transfer, we can globalize it but if the university gives us an open port.
  • 19. CODE: 1. INDEX File <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Raspberry Pi Gpio</title> </head> <body style="background-color: black;"> <!-- On/Off button's picture --> <?php //this php script generate the first page in function of the gpio's status $status = array (0, 0, 0, 0, 0, 0, 0, 0); for ($i = 0; $i < count($status); $i++) { //set the pin's mode to output and read them system("gpio mode ".$i." out"); exec ("gpio read ".$i, $status[$i], $return ); //if off if ($status[$i][0] == 0 ) { echo ("<img id='button_".$i."' src=/slideshow/embedded-report-56029777/56029777/& alt='off'/>"); } //if on if ($status[$i][0] == 1 ) { echo ("<img id='button_".$i."' src='data/img/green/green_".$i.".jpg' alt='on'/>"); } } ?> <!-- javascript --> <script src="script.js"></script> </body> </html>
  • 20. 2. GPIO <!-- This page is requested by the JavaScript, it updates the pin's status and then print it --> <?php //Getting and using values if (isset ($_GET["pin"]) && isset($_GET["status"]) ) { $pin = strip_tags($_GET["pin"]); $status = strip_tags($_GET["status"]); //Testing if values are numbers if ( (is_numeric($pin)) && (is_numeric($status)) && ($pin <= 7) && ($pin >= 0) && ($status == "0") || ($status == "1") ) { //set the gpio's mode to output system("gpio mode ".$pin." out"); //set the gpio to high/low if ($status == "0" ) { $status = "1"; } else if ($status == "1" ) { $status = "0"; } system("gpio write ".$pin." ".$status ); //reading pin's status exec ("gpio read ".$pin, $status, $return ); //printing it echo ( $status[0] ); } else { echo ("fail"); } } //print fail if cannot use values else { echo ("fail"); } ?>
  • 21. 3. SCRIPT //JavaScript, use pictures as buttons, sends and receives values to/from the Rpi //These are all the buttons var button_0 = document.getElementById("button_0"); var button_1 = document.getElementById("button_1"); var button_2 = document.getElementById("button_2"); var button_3 = document.getElementById("button_3"); var button_4 = document.getElementById("button_4"); var button_5 = document.getElementById("button_5"); var button_6 = document.getElementById("button_6"); var button_7 = document.getElementById("button_7"); //this function sends and receives the pin's status function change_pin (pin, status) { //this is the http request var request = new XMLHttpRequest(); request.open( "GET" , "gpio.php?pin=" + pin + "&status=" + status ); request.send(null); //receiving information request.onreadystatechange = function () { if (request.readyState == 4 && request.status == 200) { return (parseInt(request.responseText)); } //test if fail else if (request.readyState == 4 && request.status == 500) { alert ("server error"); return ("fail"); } //else else { return ("fail"); } } } //these are all the button's events, it just calls the change_pin function and updates the page in function of the return of it. button_0.addEventListener("click", function () { //if red if ( button_0.alt === "off" ) {
  • 22. //use the function var new_status = change_pin ( 0, 0); if (new_status !== "fail") { button_0.alt = "on" button_0.src = /slideshow/embedded-report-56029777/56029777/"data/img/green/green_0.jpg"; return 0; } } //if green if ( button_0.alt === "on" ) { //use the function var new_status = change_pin ( 0, 1); if (new_status !== "fail") { button_0.alt = "off" button_0.src = "data/img/red/red_0.jpg"; return 0; } } } ); button_1.addEventListener("click", function () { //if red if ( button_1.alt === "off" ) { //use the function var new_status = change_pin ( 1, 0); if (new_status !== "fail") { button_1.alt = "on" button_1.src = "data/img/green/green_1.jpg"; return 0; } } //if green if ( button_1.alt === "on" ) { //use the function var new_status = change_pin ( 1, 1); if (new_status !== "fail") { button_1.alt = "off"
  • 23. button_1.src = /slideshow/embedded-report-56029777/56029777/"data/img/red/red_1.jpg"; return 0; } } } ); button_2.addEventListener("click", function () { //if red if ( button_2.alt === "off" ) { //use the function var new_status = change_pin ( 2, 0); if (new_status !== "fail") { button_2.alt = "on" button_2.src = "data/img/green/green_2.jpg"; return 0; } } //if green if ( button_2.alt === "on" ) { //use the function var new_status = change_pin ( 2, 1); if (new_status !== "fail") { button_2.alt = "off" button_2.src = "data/img/red/red_2.jpg"; return 0; } } } ); button_3.addEventListener("click", function () { //if red if ( button_3.alt === "off" ) { //use the function var new_status = change_pin ( 3, 0); if (new_status !== "fail") { button_3.alt = "on" button_3.src = "data/img/green/green_3.jpg"; return 0;
  • 24. } } //if green if ( button_3.alt === "on" ) { //use the function var new_status = change_pin ( 3, 1); if (new_status !== "fail") { button_3.alt = "off" button_3.src = /slideshow/embedded-report-56029777/56029777/"data/img/red/red_3.jpg"; return 0; } } } ); button_4.addEventListener("click", function () { //if red if ( button_4.alt === "off" ) { //use the function var new_status = change_pin ( 4, 0); if (new_status !== "fail") { button_4.alt = "on" button_4.src = "data/img/green/green_4.jpg"; return 0; } } //if green if ( button_4.alt === "on" ) { //use the function var new_status = change_pin ( 4, 1); if (new_status !== "fail") { button_4.alt = "off" button_4.src = "data/img/red/red_4.jpg"; return 0; } } } ); button_5.addEventListener("click", function () {
  • 25. //if red if ( button_5.alt === "off" ) { //use the function var new_status = change_pin ( 5, 0); if (new_status !== "fail") { button_5.alt = "on" button_5.src = /slideshow/embedded-report-56029777/56029777/"data/img/green/green_5.jpg"; return 0; } } //if green if ( button_5.alt === "on" ) { //use the function var new_status = change_pin ( 5, 1); if (new_status !== "fail") { button_5.alt = "off" button_5.src = "data/img/red/red_5.jpg"; return 0; } } } ); button_6.addEventListener("click", function () { //if red if ( button_6.alt === "off" ) { //use the function var new_status = change_pin ( 6, 0); if (new_status !== "fail") { button_6.alt = "on" button_6.src = "data/img/green/green_6.jpg"; return 0; } } //if green if ( button_6.alt === "on" ) { //use the function var new_status = change_pin ( 6, 1);
  • 26. if (new_status !== "fail") { button_6.alt = "off" button_6.src = /slideshow/embedded-report-56029777/56029777/"data/img/red/red_6.jpg"; return 0; } } } ); button_7.addEventListener("click", function () { //if red if ( button_7.alt === "off" ) { //use the function var new_status = change_pin ( 7, 0); if (new_status !== "fail") { button_7.alt = "on" button_7.src = "data/img/green/green_7.jpg"; return 0; } } //if green if ( button_7.alt === "on" ) { //use the function var new_status = change_pin ( 7, 1); if (new_status !== "fail") { button_7.alt = "off" button_7.src = "data/img/red/red_7.jpg"; return 0; } } } );
  • 27. CONCLUSION Technologyisdevelopingatdayby day at fastrate, YesteryearsLivestockcartsare replacedbyMotor vehiclesandtheyare replacedwithvehicleshighspeedandgearslaterautomaticgearshiftandnow its like yourcar drivingitself. Soautomationis the future everythingyouposseswill be automatedwhynot your house? The whole beauty of thisprojectliesingainingboththe technical,practical andcoding experience andknowledge. Thisprojectcanthususedas a demoforfuture enhancementsinnear future.