Wireless Sensor Network (WSN) Lab Syllabus

eggplantcinnabarΚινητά – Ασύρματες Τεχνολογίες

21 Νοε 2013 (πριν από 3 χρόνια και 6 μήνες)

225 εμφανίσεις


1

Wireless Sensor Network (WSN
)

Lab

Syllabus


Instructor: Dr.
Sang W. Kim

Spring 2006

Iowa State University


1.
Introduction:


The purpo
se of the WSN labs is to i
ntroduce
State
-
of
-
the
-
Art

Wireless Sensor Networks
technology
. S
tudents
will
get
intuitive under
standing of the concept and
current
progress
of

WSN
as well as hand
-
on experience with
MICA wireless network platform.



The WSN lab consists of three sections,
by which students
progressively

get familiar
with MICA hardware and TinyOS operating system by
design and implementation of
WSN application
s
.


Upon completing this
lab

a student will:


1.

Understand what
is WSN and

its
impact

2.

Understand
structure of
MICA
hardware and the operating system running on
MICA motes


TinyOS

3.

Be able to describe how MICA hardw
are and software work coordinately

4.

Be able to
implement example

WSN applications on MICA platform

5.

Be able to develop new
WSN
applications according to
design
requirement



2. Major topics:



Lab

1

Experiment
1



A overview of WSN



MICA mote platform and TinyO
S



Implementation of “
Os
cilloscope”


Lab

2

Experiment 2



Implementation of

OscilloscopeRF


application



D
esign
and implement
your
own


OscilloscopeRF


application



Lab 3

Experiment 3



Implementation of Surge application



Develop
featured
sensor board

accor
ding to requirements
, test it using Surge



3. Grading Policy:




Prelab




Lab

experiment results



Final lab report



2

Wireless Sensor Network (WSN) Lab
1



1.
L
ab Objectives:


This lab shows how t
o compile, download application

onto
a MICA mote

and run
WSN appl
ications on TinyOS.

You will implement “
Oscilloscope
” application on
MICA
hardware
and TinyOS platform.


The program

(NesC code)

to be run
ning

on the motes is
located at
nest/apps/oscilloscope.

The application consists of a single module that reads
data fr
om
a
n

ADC (
Analog to Digital Converter
)
and sends out

packets of the
sensor reading to
its

51
-
pin connector, data packets
are sent to

a programming
board

and then forwarded to PC
. This application

does not transmit the data over
the radio. However, it wou
l
d be simple to extend it to do
so.

You

will run a JAVA
program also called
o
scilloscope

on the

PC to monitor the sensor data.



What will you do?


1.

Overview of

WSN and MICA/TinyOS platform;

2.

Compile and download “
oscilloscope


program to a

MICA radio board;

3.

Run “
oscilloscope
” JAVA GUI program on you PC

in order

to monitor the
senso
r

reading from the MICA mote (a radio board
with a sensor board
plugged in), as the system setup shown in Figure 9;

4.

Identify which sensor is being used in “
oscilloscope
” and
conside
r how to
switch to

other sensors.


2
.
Prelab



It is
highly recommended to go through the Prelab content
before you start.



Before you come to 1
st

lab
,

you are recommended to go through the following
websites

to get
an
idea about
what
MICA platform and Ti
nyOS Operating system

are
:



http://www.xbow.com/Products/productsdetails.aspx?sid=3

http://www.tinyos.net/t
inyos
-
1.x/doc/tutorial/lesson1.html

http://www.tinyos.net/tinyos
-
1.x/doc/tutorial/lesson2.html


Th
ere are many helpful contents and schematics on how to run

a WSN
application on M
ICA motes
.


2.1
How can I use TinyOS?


There are 3 steps you must follow in order to use TinyOS, you will NOT BE
ABLE TO ACESS TinyOS until the following procedures is completed.



3

TinyOS has bee
n installed on all computers in

this lab.



2.
1 Make TinyOS ac
cessible to your account:


Go to My Computer
-
> C drive
-
> right click “tinyos” folder
-
> properties
-
>
Security
-
> Advanced
-
> Owner
-
> Click on your user name
-
> Select “Replace
owner on subcontainers and objects”
-
> Click “OK”
-
> Click “Yes” if a dialog

pop
out
-
>Wait until this process finish.


Double click the “Cygwin” icon on desktop, execute this command:


chmod 755 /etc/profile


Close the cygwin window and reopen it by double clicking the cygwin icon,


If you do not see the “Permission denied” messa
ge, then you are OK to use
TinyOS now; otherwise, please repeat the previous steps.



2.
2

You need to set the $TOS_HOME environmental variable, to do this, in
cygwin window, type


export $TOS_HOME=c:
\
tinyos
\
cygwin
\
opt
\
opt
\
tinyos
-
1.x


Then $TOS_HOME is lin
ked to


C:
\
tinyos
\
cygwin
\
opt
\
tinyos
-
1.x

, so that if you
type “cd $TOS_HOME” then you will actually enter the

C:
\
tinyos
\
cygwin
\
opt
\
tinyos
-
1.x
” directory, this is the home directory of TinyOS.
This is to save your time in the lab.



2.2
What is Cygwin?


Cy
gwin is a Linux
-
like environment for Windows. It consists of two parts



A DLL

(Dynamic Link Library)
,cygwin1.dll,
which acts as a Linux API

(Application Program Interface)

emulation layer providing substantial Linux
API functionality.



A collection of tools
, which provide Linux look and feel.



We execute TinyOS command in Cygwin shell because TinyOS is based
on Linux platform and we are working in Windows.



2.3
What does Cygwin look like?


There is a Cygwin icon on your desktop, double
clicking

it and you wi
ll see a
Cygwin window looks like this:



4


Figure 1


You can open multiple Cygwin windows at a time and execute different
commands

in each one

simultaneously.


If you have any question on hardware and software during the lab, please
contact instructor be
fore proceed.



3
. Lab
1

Procedure


3.1 Reading:
O
verview of

WSN

(
the scope of WSN, application scenarios,



popular technology employed in W
SN)


5


Figure
2




Figure
3


6




Figure
4








Figure 5



7



Figure
6




Figure
7

Radio bo
ard with sensor board


8




Figure 8


3.2

Deta
ils




Now you will do experiment to get hand on experience of WSN.
First you
will implement “
Oscilloscope
” application and learn how to compile,
download (install) and run WSN application on MICA motes.




The application we use in this lesson is found in
$TO
S_HOME/
apps/Oscilloscope
. It consists of a single module that reads
data from the photo

(light)

sensor.
The radio board read sensor data from
a sensor board, the

radio board
sends
packet
s

t
o the
programming board
through a 51
-
pin cable, the programming board then forwards this packet
to PC through
se
rial port. I will run a JAVA GUI program “
Oscilloscope

allows
PC to monitor the sensor reading.
In this lab t
he mote only sends
the packets ove
r the serial port

to PC, no radio communication
involved.

The system set up is shown in Figure 9.



9



Figure 9


Why

there are two “Oscilloscope” program involved?


Yes,
there are two “
Oscilloscope
”.
One is
,

the “Oscilloscope” NesC program
to be running
on
the radio board and
another is
the “Oscilloscope” JAVA GUI
programs running on PC
for display.



3.3

Experiment 1 procedure




Step

1

-

Open a cygwin window

by double clicking the “cygwin” icon on
the desktop.
You need to set the $TOS_HOME environmental vari
able to
save your time in the lab. To do this, t
ype


export $TOS_HOME=c:
\
tinyos
\
cygwin
\
opt
\
opt
\
tinyos
-
1.x


to link $TOS_HOME to


C:
\
tinyos
\
cygwin
\
opt
\
tinyos
-
1.x

, so that if you type
“cd $TOS_HOME” then you will actually enter the

C:
\
tinyos
\
cygwin
\
opt
\
ti
nyos
-
1.x
” directory, this is the home directory of
TinyOS.





Step

2

-

Compile and install the
Oscilloscope

application on a MICA
radioboard
.

Type


cd $TOS_HOME
/
apps/Oscilloscope

,
and then

type “
make mica2
”, which
will compile
Oscilloscope

application and generat
e
the
executable code
for

10

Mica mote (
which is actually a
main.exe file under

$TOS_HOME
/
apps/Oscilloscope
/build/mic
a2/)
.


If you got “Permission Denied
” e
rror, try executing “make mica2”
again.




Step

3

-

First we

install the


Oscilloscope
” executable file

(main.exe) on a
MICA radio board
, follow the next 5 steps:



3.
1
.
C
onnect

a
MICA

programming board to your PC’s
CO
M1

serial port
using the
serial
cable;

3.
2.
Connect the power cord
to your programming board
so you
can

use
external power supply when downloading

(installing)

prog
ram.
(The
reason that we use external power is, i
f we do not use the external power
while

d
ownloading program, it will use the AA batteries on the radio board,
however, l
ow

battery
level
on MICA
radio board

may cause flash
errors
when downloading program
)

;

3.
3.

Plug the MICA s
ensor board onto the MICA radio
board

with label
ed

“OscP”
,

which

stand
s for ““
Oscilloscope

Photo” since we are using photo
sensor now.

3.4.

Use
the 51
-
pin cable to connect a MICA
sensor

board to the
programming board
;


3.
5.
Turn on the radio board.



Attention:

Do not touch the

sounder (the small black box) on MTS310
sensor
board when attaching MTS310 to the radio board
, or

when y
ou
plugging your 51
-
pin cable to MTS310, it is

easy to damage the sounder
without care.






Now the system setup will look like:



11


Figure 10




Step

4

-

Return to the cygwin window

you just opened
,
t
ype “
pwd
” to
check your current directory. M
ake sure you still in
$TOS_HOME/
apps/Oscilloscope

directory, type

MIB510=COM1 make
mica2 install

, this will download

(install)

the
main.exe

exe
cutable code
onto MICA radioboard

connecting to the programming board
. If program is
downloaded successfully, you will see an output like this:


$ MIB510=COM1 make mica2 install


compiling Oscilloscope to a mica2 binary

ncc
-
o build/mica2/main.exe
-
Os
-
board=micasb
-
target=mica2
-
I../Oscilloscope
-
W

all
-
Wshadow
-
DDEF_TOS_AM_GROUP=0x7d
-
Wnesc
-
all
-
finline
-
limit=100000
-
fnesc
-
cfi

le=build/mica2/app.c Oscilloscope.nc
-
lm


compiled Oscilloscope to build/mica2/main.exe


9886 bytes in ROM



430 bytes in RAM

avr
-
objcopy
--
output
-
target=srec build/mica2/main.exe build/mica2/main.srec

make[1]: Entering directory `/opt/tinyos
-
1.x/apps/OscilloscopeRF'


installing mica2 binary

uisp
-
dprog=mib510
-
dserial=COM1
-
dpart=ATmega128
--
wr_fuse_e
=ff
--
erase
--
uplo

ad if=build/mica2/main.srec

Firmware Version: 2.1

Atmel AVR ATmega128 is found.

Uploading: flash


Fuse Extended Byte set to 0xff


12

make[1]: Leaving directory `/op
t/tinyos
-
1.x/apps/Oscilloscope
'


Otherwise, you will get an error report in
dicating the type of error that
occurred during downloading.

The most

common error is “flash error”,
in
this case you need to check if the programming board is powered by
external power supply
and if 51
-
pin connector is plugged properly.




Step

5

-

Now ope
n another two cygwin windows,
in one of them type

“cd
$
TOS_HOME/
tools/java
” , this will lead to

the JAVA

directory

to run JAVA
program in TinyOS
, then

type:


java net.tinyos.sf.SerialForwarder
-
comm serial@COM1:57600


Now it will

open up
a
GUI window that

looks similar to the following:



Figure
11


This
is

SerialF
orwarder Java
program,

which

presents a
n

unified abstraction of reading mote output.


If “Pckts Read” does not increase even after your turn on the radio

board, please click “Stop Server” butt
on twice to restart the serial

forwarder.




Step

6

-
You

need to run a program that connects to the SerialForwarder
and presents data to you in a meaningful form, which will be
Oscilloscope
in this
Lab
.

Leaving the serial forwarder running, in the
other
cyg
win
window,
type “cd $TOS_HOME/
tools/java
” to go to the JAVA
directory, then type:


java net.tinyos.oscope.oscilloscope



13

This will start a GUI to graphically display the data
that received from

SerialF
orwarder program

in a meani
ngful form, as shown in Fi
gure 12
.



Figure 12


The Y axis represents the sensor reading, X axis represent
s

time

domain
.

Click
the
“Scrolling” checkbox if reading is not shown on GUI.




Step 7
-

The
“O
scilloscope
” JAVA

GUI

is simply printing out the packets
that are coming
from the

mote

through the data flow shown in Figure 9
.
Now, save the figure using “PrintScreen” button on the keyboard and save
it in Paint, include this figu
re in your lab

report.




Step
8

-

Identify which sensor is being
displayed

by O
scilloscope

application now.

Try to figure out where

we

(in the nesC code)
specified

this

sensor in the O
scilloscope

module
.



Hint: c:
\
tinyos
\
cygwin
\
opt
\
opt
\
tinyos
-
1.x
\
Oscilloscope.nc




Consider

how
to modify the O
scilloscope

in order to make the Microphone

sensor
of the sensor board

work in O
scilloscope
.

It will be discussed in
Lab2.



14
















































15


Wireless Sensor Network (WSN) Lab
2



1.
Lab objectives


You will implement
OscilloscopeRF

application

and

see

how the data can be
sent over the radio

and d
isplayed on PC
.
You

will
change photo sensor to

the

m
icrophone sensor

in
OscilloscopeRF application

and test it
.
In order to do this
you need

to

modify, recompile and
downl
oad
your new
Oscilloscope
RF

application on
one

mote.
See
if you can
remotely
monitor

voice signal

through
m
icrophone

on
your PC
screen
.

The last objective

is
to

display
the
sensor
readings
by

oscilloscope GU
I from two motes simultaneously:

one of them runs
p
hoto sensor and the other runs microphone sensor.


What will you do:


1.

Compile and

download “
O
scilloscope
RF


program onto a MICA radio
board, this will be your transmitter

mote

which send
s

photo
(light)

sensor
reading

to a basestation
mote
over radio;


Compile and download “
TOSBase


program onto another MICA radio
board, this will be you
r basestation
mote
which receives data from the
transmitter mote and forwards data packets to PC through a programming
board;


Run “
O
scilloscope
” JAVA GUI program on you PC

in order to monitor the
sensor

reading from the MICA mote
, now your system setup
wi
ll look like
Figure 1
;


2.

Modify the “
O
scilloscope
RF


application source code; change the sensor
from photo to microphone. Download i
t onto another MICA radio board;


Display
the microphone
sensor readings
by

O
scilloscope

GU
I
,
as

the
system setup
shown in

Fi
gure 1
, however the transmitter mote is sending
readings from
microphone sensor instead of photo sensors;


3.

Run

and monitor

two motes simultaneously. One

sends
microphone
sensor readings
AND
the other

sends
photo

sensor readings, try to
display both sensor
readings

by

O
scilloscope

GU
I

at the same time,
as
the system setup shown in Figure 2,
, the two transmitter mote
s

are

sending microphone and photo sensor readings
respectively
.


4.

Display the raw data of photo
sensor readings

and compare it with the
displayed

sensor value from
O
scilloscope

GU
I.



16




Figure
1



17




Figure
2


2
.
Prelab


It is
highly recommended to go through the Prelab content in
order to
finish the

lab
in time.



For lab 2 y
ou will need to review


http://www.tinyos.net/tinyos
-
1.x/doc/tutorial/lesson4.html

http://www.tinyos.net/tinyos
-
1.x/doc/tutorial/lesson6.html

in order to understand how to
monitor a sensor remotely using MICA motes.





18

3
.
Lab2 P
rocedure


3.1
Implement
“OscilloscopeRF”
application and display the photo
sensor reading (which is received over radio) by oscilloscope GUI on
the PC.




Step 1
-

Open a cygwin command window,
type


“cd
$TOS_HOME/
apps/OscilloscopeRF

,

then

type “
make mica2
”, which
will compile
Oscilloscope

application and generate

executable code for
Mica mote (which is actually a main.exe file under
$TOS_HOME
/
apps/Oscilloscope
RF/build/mica2/).




Step 2

-

Download the
OscilloscopeRF

program onto the mote with label
“OscP”, where “OscP” stands for “Oscilloscope Photo”.


1. Connect

a
MICA programming board to your PC’s
COM1
serial port
using the serial ca
ble;

2. Connect the power cord to your programming board so you can use
external power supply when downloading (installing) program.

3. Plug one

MICA sensor board onto the MICA radio board with label
“OscP”;

4. Use the 51
-
pin cable to connect a MICA sens
or
board to the
programming board as shown in Figure 3.




Step
3

-

Since all sensor motes are using the same transmission channel,
we will use different moteID to separate each group’s units.


Each group need to assign their moteID respectively. (mote
ID
could

be

any integer between 1 and125. To assign ID for a mote, using


MIB510=COM1 make mica2 install.x
” when downloading program to

Mote. Where x is the mote ID you want to assign to this mote. Please use
the table to assign your moteID.


Group

1

2

3

4

5

6

Photo
moteID

1

3

5

7

9

11

Microphone
moteID

2

4

6

8

10

12


Type “
MIB510=COM1 make mica2 install
.x
”, this will download
OscilloscopeRF

program

on the radio board with “OscP” label.
For
example, if you are group 3, then you should type “
MIB510=COM
1 make
mica2 install
.5

.
This mote will be used as transmitter mote to read photo
sensor data
and send
to the basestation

(receiver)
.




Step
4

-

In the same

cygwin command window,
type


19

“cd
$TOS_HOME/
apps/TOSBase

,
then
type “
make mica2
”, which will
compile

TOSBase application and generate

executable code for Mica
mote (which is actually a main.exe file under
$TOS_HOME
/
apps/
TOSBase/build/mica2/

directory
).

The TOSBase
program will receive pac
ket over radio from the transmitter mote and
forward the packets to PC through the programming board.




Step
5

-

Now we download the
TOSBase

program onto
the
mote with
label “TOS”. Follow these steps:


1
. Plug out the
MICA radioboard
/sensor board set

with
label “Osc
P” (
keep
the
sensor board

plugged on radioboard!) from the 51
-
pin cable, and turn
the radioboard on;

2. Use the 51
-
pin c
able to connect the radio
board

with “TOS” label

to the
programming board. Note there i
s no sensor board attached to this
radio
board;

3.
Make sure the power cord is still connected to the programming board
now.




Step
6

-

Type “
MIB510=COM1 make mica2 install
”, this
will
download
TOSBase program on the radio board with “TOS” label.
This mote will be
used as basestatio
n to receive d
ata from other motes.





Now your system setup will look like:



Figure 3


20



Step
7

-

O
pen

another

two

cygwin windows,
in
one

window type “cd
$TOS_HOME
/tools/java
”, and then type



java net.tinyos.sf.SerialForwarder
-
comm serial@COM1:57600


This will start Se
rialF
orwarder Java
program
,
the
same as in Lab1, looks
like following





Figure 4




Step
8

-

Leaving the serial forwarder running, in the other window,
type
“cd $TOS_HOME/
tools/java
” to go to the JAVA directory, then type:


java net.tinyos.oscope.oscill
oscope


t
his will pop up a
Oscillo
scope Java program GUI
containing a graphical
display of the sensor readings from the mote
, which is reading Photo
sensor now. Note the data is received over radio ins
tead of directly from
the radio
board

through 51
-
pin cab
le

as we did
in Lab1.



21


Figure 5

The Y axis represents the sensor reading, X axis represents time domain.

Click
the
“Scrolling” checkbox if reading is not shown on GUI.




Step
9

-

Your may see several mote records since other group’s
transmitter are also
working.
Make sure your
mote corresponding to your
photo sensor

moteID

is

there.

For example, if you are group 3, you should
see “Mote 5” on the legend bar. Check if yours are
working properly by
cover and uncover the photo sensor

(silver)

on the sensorboa
rd.




Step
10

-

Now, save the figure using “PrintScreen” button on the keyboard
and save it in Paint, include this figure in your lab report




Close both SerialForwa
r
der and O
scilloscope
JAVA program windows (the
JAVA application GUI, not the cygwin command

window)
,
you
will

not

be
able

to download
any NesC program

to a mote
when

“SerialForwarder” JAVA program is running, because they will
conflict at the COM1 port!




Turn off the “Osc
P” radioboard
.


3.2
Now you need to

c
hange the
sensor
from photo
to m
icroph
one

by
yourself
,

and then

download

it to another mote
and test if you can make
the microphone sensor work

using
the same
Oscilloscope JAVA GUI

above
.




22

How can I choose a sensor that I want to use?


To make a sensor work in Oscilloscope, you will power the

sensor (for
example, microphone) and read the ADC channel assigned to this sensor in
order to get
the
sensor data. You can achieve all these functions
by

software,

no hardware modification is required. M
ore specifically, modification will be
made

in the
O
scilloscope.nc file
under $TOS_HOME/app/Oscilloscope
RF

directory.

You can use any editing tools to edit the file, including Editplus,
Notebook or WordPad.


The type of s
ensor

used in Oscilloscope
RF

is defined in
the file
C:
\
tinyos
\
cygwin
\
opt
\
tinyos
-
1.x
\
app
s
\
Oscilloscope
RF
\
Oscilloscope.nc, which
is a component file linking all interfaces of Oscilloscope
RF

application
.


In order to use a new sensor
to replace the default photo

sensor, you
will

take

the following three steps:





Step 1
-

Photo is defined as de
fault in the components; replace it with the
name of the Sens
or module that you want to use
. Default line is


components Main, OscilloscopeM, TimerC, LedsC,
Photo
, UARTComm
as Comm;




Step 2

-

Define the SensorControl in order to power the sensor you want
t
o use, default

line

is

OscilloscopeM.SensorControl
-
>
Photo
;




Step 3

-

Define the ADC in order to read the ADC of the new sensor,
default

line

is



OscilloscopeM.ADC
-
>
Photo
;


Save the file you modified.


All sensor modules are available in
$TOS_HOME
\
tos
\
sensorboards
\
micasb


directory, type “cd $TOS_HOME
\
tos
\
sensorboards
\
micasb” and you will
see the available sensor module filenames.


In the three lines mentioned above, choose the sensor you need (in this
case microphone), and replace “Photo” with the com
ponent filename of
that sensor, note you will use the filename like “filenameC.nc” instead of
“filenameM.nc”. For example, you may use “MicC”
to replace “Photo” here.




Step 4

-

Now we download our new OscilloscopeRF application onto
another mote with label


Osc
M”.



23


1
. Plug
out the “TOSBase” radio/sensor board set
from the 51
-
pin cable;

2
. Plug
a

MICA sensor board onto the MICA radio board with label “O
scM

;
3
. U
se the 51
-
pin cable to connect the

MICA sensor b
oard to the
programming board;

4
.
Make sure Pr
ogramming board is still powered by external power
supply.




Step 5

-

In any cygwin window, type “cd
$TOS_HOME/
apps/OscilloscopeRF
”, then type “
make mica2
”, this will re
-
compile your
OscilloscopeRF application and generate a new executable
file ready for do
wnload, note now this OscilloscopeRF will read
microphone sensor instead of photo, while all other function of
OscilloscopeRF remain unchanged.




Step 6

-

Type “
MIB510=COM1 make mica2 install
.2
”, this will download
OscilloscopeRF

program
(reading microphone
)
on the radio board with
“OscM
” label,
note no

mote ID is assigned to this radioboard now
.




Step 7

-

Plug out the “OscM” radio/sensor board set from the
51
-
pin cable
and turn the radio
board
with “OscM” label
on
.

Turn “OscP” mote off and
turn “OscM” mote o
n.




P
lug
the “TOSBase” radio
board
back
to the 51
-
pin cable so it

can work as
basestation again.




Step 8

-

Now in any cygwin window
,
type “cd $TOS_HOME
/tools/java
”,
and then type


java net.tinyos.sf.SerialForwarder
-
comm serial@COM1:57600




Step 9

-

Go to an
other
cygwin window
,
type “cd $TOS_HOME
/tools/java
”,
and then type


java net.tinyos.oscope.oscilloscope


to start oscilloscope JAVA GUI

in order to monitor the microphone sensor
reading from our “OscM” mote.

Click
the
“Scrolling” checkbox if
reading is not

shown on GUI.


Im
porta
nt: As other group’s mote are also working, you may see
several lines on your GUI, what you need to do is observe the line of
your moteID and test if it is working properly by speaking to your
Microphone sensor.



24



Step 10

-

Now
speak

loudly
to the microphone sensor on the sensor
board
that is
plugged on
the
“OscM
” radio
board, see if you c
an see the
sensor reading changing

from

your Oscilloscope
JAVA GUI on your PC, if
so, you have successfully finished this step. Note you
may have to
speak
closely to the microphone.




Step 11

-

Save the figure using “PrintScreen” button on the keyboard and
save it in Paint, include this figure in your lab report



Do I need to modify JAVA code for display

to monitor microphone

readings
?


No, the Oscill
oscope GUI is already capable of displaying
all kind of
sensor readings. You have to ensure that those readings are correctly
transmitted and received over the network.


3.3 Now

display sensor readings on the oscilloscope GUI from
the
two

motes simultaneo
usly.
M
onitor p
hoto sensor
and microphone
on your

Oscilloscope GUI from

the two

mote
s respectively.



Now the system
should

look like:



Figure 6


25




Turn off both motes
“OscP” and “OscM”

and turn them on at the same
time
.
You should be able to
observe
the
two sensor readings

in GUI

now,
try both sensors and see if the readings are shown correctly on your GUI.


3.4
Try to display the raw data of sensor readings in one
c
ygwin
window
and run Oscilloscope JAVA
GUI program

in another

cygwin window.

To
display th
e raw data of the received packet, you need to run
an
application

called “Listen”
, which is included in the Prelab section. The
“Listen”
is simply printing out the packets that are coming from the
mote.




Make sure your
O
scilloscope JAVA GUI is still runni
ng and displaying the
sensor reading from two motes



Now turn off the “OscM” radioboard so we only monitor “OscP” now, so
the reading from “OscM” should disappear on O
scilloscope

JAVA GUI
.




Open a cygwin window, type “cd $TOS_
HOME
/tools/java” and then type


java net.tinyos.tools.Listen


You should see some output resembling the following:


% java net.tinyos.tools.Listen

serial@COM1:576
00: resynchronising

7e 00 0a 7d 1a 01 00 0a 00 01 00 46 03 8e 03 96 03 96 03 96 03 97 03 97 03 97 03 97 03 97 03

7e 00 0a 7d

1a 01 00 14 00 01 00 96 03 97 03 97 03 98 03 97 03 96 03 97 03 96 03 96 03 96 03

7e 00 0a 7d 1a 01 00 1e 00 01 00 98 03 98 03 96 03 97 03 97 03 98 03 96 03 97 03 97 03 97 03


Each data packet that comes out of the mote contains several fields of data.
Som
e of these fields are generic Active Message fields, and are defined in
$TOS_HOME/
tos/types/AM.h
.

The data payload of the message, which is
defined by

the application, is defined in
$TOS_HOME/
apps/Oscilloscope/OscopeMsg.h
.

The overall message format
for the Oscilloscope application is as follows:



Destination address

(2 bytes)



Active Message handler ID

(1 byte)



Grou
p ID

(1 byte)



Message length

(1 byte)



Payload

(up to 29 bytes):

o

source mote ID

(2 bytes)

o

sample counter

(2 bytes)

o

ADC channel

(2 bytes)

o

ADC data readings

(10 readings of 2 bytes each)

So we can interpret the data packet as follows:



26

dest
addr

handl
erID

groupID

msg len

source
addr

counter

channel

readings


7e 00

0a

7d

1a

01 00

14 00

01 00

96 03 97 03 97 03
98 03 97 03 96 03
97 03 96 03 96 03
96 03


Figure 7

Note that the data is sent by the mote in
little
-
endian

format; so, for example,
the two byt
es
96 03

represent a single sensor reading with most
-
significant
-
byte
0x03

and least
-
significant
-
byte
0x96
. That is,
0x0396

or 918 decimal.



S
ave the
raw data screen

using “PrintScreen” button on the keyboard and
save it in Paint, include this figure in you
r lab report



Interpret the raw data
using the table
and compare the raw sensor
readings with the displayed value on the oscilloscope GUI, see if they
can
match.




























27

Wireless Sensor Network (WSN) Lab
3



1. Lab objectives


This is the
last and also

the

most interesting
part

of WSN lab.
You will
implement
Surge

application wi
th three motes
which send different sensor reading
s

to
one

basestation

mote

in order
to build a small wireless sensor network
. You will
run

the
photo, microphone and

magnetometer

sensor

on

three mot
e
s

and monitor
the
ir

sensor
readings

by Surge GUI
on the

PC.

Surge is a demo of Multihop Sensor Network.
When working with multihop
routing applications, Surge provides the following information to users:



Detects the exist
ence of all the motes in a wireless network.



Display mote information,

including the m
ote identification number (ID),
the number of
packets

received

from each mote, etc



Displays the topology of network

What will you do:

1.

Compile and download “
Surge


progra
m
of basestation on
to
one

MICA
radio
board
, this will be your

basestation mote which receives sensor
reading packet from three transmitter motes.


Compile and download “
Surge


program of photo sensor onto one MICA
radio
board
, this will b
e your

transmitter m
ote which sends photo sensor
reading to basestation mote;


Run “
Surge
” JAVA GUI program on you PC

to monitor the

photo

sensor

reading from the
photo
MICA mote
,
as

the system
shown in

Figure 1;





28



Figure 1


2.

Modify and re
-
c
ompile “
Surge


program
to make i
t read

microphone

sensor
and download it
onto one MICA radio
board
, this will be your
transmitter mote which sends microphone sensor reading to
the
basestation mote;


Modify and re
-
c
ompile “
Surge


program
to make it read

magnetometer

sensor
and download it
onto one MICA radio
board
, this will be your
transmitter mote which sends
magnetometer

sensor reading to
the
basestation mote;


Turn on all three motes.



29

Run “
Surge
” JAVA GUI program on you PC

in order to monitor the photo
microphone

and
magnetometer

senso
r

reading from
three transmitter
mote
s,
as

the system
shown in

Figure 2
;




Figure 2



3.

In the Surge JAVA GUI program

code

of “
C:
\
tinyos
\
cygwin
\
opt
\
tinyos
-
1.x
\
tools
\
java
\
net
\
tinyos
\
surge
\
PacketAnalyzer
\
SensorAnalyzer.java”
, we
set
three threshold values fo
r
photo
,

microphone

and
magnetometer


30

sensor
s

respectively, that is, if the sensor reading goes above or below a
certain pre
-
configured threshold value, an
alarm
icon will show up beside
that sensor to alarm


(This is achieved by a line like
g.drawImage

(pi
mage
x1,y1,x2,

y2

null);
)
.



Try to find the threshold value
s for each sensor

in the Surge JAVA code.



2.
Prelab


It is

recommended to go through the Prelab content in
order to finish the

lab in time
.


Go through the following content
and

try to

figure ou
t how to control these
sensors in TinyOS:


http://www.tinyos.net/tinyos
-
1.x/doc/tutorial/lesson6.html

http://www.xbow.com/Support/Support_pdf_files/MTS
-
MDA_Series_Users_Manual.pdf



3. Lab
3

Procedure


3.1
I
mplement “Surge”
application
and display sensor readings on the
Surge GUI from three motes simultaneously.
Mote 1 will read photo
senso
r data

and send to basestation
, mote 2 will read and send
microphone sensor
data;

mote 3 will read and send magnetometer
sensor data.


1.

Connect the programming board to PC using serial cable, power the
programming board by the power cord.


2.

Plug a sensorboa
rd to the radioboard with label “1”, then connect the
sensorboard with label to your programming board using 51
-
pin cable,
this mote will by our mote 1 which will read and send photo sensor reading
to basestation (mote 0);


3.

GroupID
:

Since we have six grou
ps, we separate each group’s motes into
six different mote groups in order to avoid conflict.


Group

1

2

3

4

5

6

GroupID
in DEC

125

126

127

128

129

130

GroupID
in HEX

0X7d

0X7e

0X7f

0X80

0X81

0X82





GroupID can be changed in


C:
\
tinyos
\
cygwin
\
opt
\
t
inyos
-
1.x
\
app
\
Makerule


31


Open the file named Makerule

using wordpad and modify the line

DEFAULT_LOCAL_GROUP := 0x7d

According to the above table
, for exaple
, if you are group 3, change it
to

DEFAULT_LOCAL_GROUP := 0x7f, then save and close the file.


4.

Open

a cygwin command window,
go to $TOS_HOME/
apps/Surge
directory
,
type “
make mica2
”, this will compile Surge application and
generate executable code

(with your new group ID)

for Mica mote.


5.

Download the
Surge

program to mote 1. This mote will be your
bases
tation. In order to do this, in the same cygwin window, type

MIB510=COM1 make mica2 install.1
”, this will download the Surge
NesC executable program to this mote and the mote ID is assigned as 1.


6.

Plug out the sensorboard/radio
board set from the 51
-
pin ca
ble, turn the
radioboard on;


7.

Connect the radioboard with label “0” to your programming board using
the 51
-
pin cable; this mote will be your basestation. N
ote there is no
sensorboard plugged on mote 0 because basestation
mote
does not
sense or read any se
nsor

data
.
It
will receive data from the other three
motes over radio, and send it to PC through serial port for display.


8.

Open a cygwin command window,
go to $TOS_HOME/
apps/
Surge

directory
,
type “
make mica2
”,
this

will compile
Surge

application and
genera
te executable code for Mica mote.


9.

Download the
Surge

program to mote 0. In order to do this, in the same
cygwin window, type “
MIB510=COM1 make mica2 install.0
”, this will
download the Surge NesC executable program to this mote and the mote
ID is assigned

as 0.

Now the system setup will look like




32


Figure 3


10.

Open
two cygwin windows,
in one window type cd
$TOS_HOME
/tools/java
”, run
serial forwarder

in this window by typing:


java net.tinyos.sf.SerialForwarder
-
comm serial@COM1:57600


This will start Seria
lForwarder JAVA program,


11.

In the other cygwin window
,
type cd $TOS_HOME
/tools/java
, run Surge in
this window by typing:


jav
a net.tinyos.surge.MainClass YOURGROUPID



“YOURGROUPID” is 125 if you are group 1,
126 if you are group 2,
etc.


this will start S
urge Java GUI
containing a graphical display of the sensor
readings from the mote

and
the
display
topology of network
.

It may take up to one minute to initialize the network topology, click “Fit to
screen” if you can not see all sensors,
GUI

will look lik
e:



33


Figure 4





Close “SerialForwarder” and “Surge” JAVA GUI after you make sure the
photo sensor reading is correctly received

(the JAVA application GUI, not
the cygwin command window),
you
will

not

be able

to download
any
NesC program

to a mote
when
“Se
rialForwarder” JAVA program is
running, because they will conflict at the COM1 port!


3.2
N
ow y
ou
already

hav
e mote 1 running Photo sensor

(Light)

and you
are monitoring it

in
Surge

JAVA GUI
.

Y
ou
need to include

mote 2
(
microphone

sensor) and
mote 3
(
magne
tometer sensor)

in Surge
.

Mote 1, 2,

3 will read their
sensor data and send to mote 0 (basestation)

respectively
.


Hint:



How can I choose a sensor that I want to use?


Read Surge.nc
file

in
C:
\
tinyos
\

cygwin
\
opt
\
tinyos
-
1.x
\
apps
\
Surge
\
Surge.nc
,
which are

similar as the modification on
OscilloscopeRF that you did in Lab2.

To make a sensor work in Surge, you will power the sensor (for example,
microphone) and read the ADC channel assigned to this sensor in order to
get the sensor data. You can achieve all t
hese functions by software, no

34

hardware modification is required. More specifically, modification will be made
in the
C:
\
tinyos
\

cygwin
\
opt
\
tinyos
-
1.x
\
apps
\
Surge
\
Surge.nc file
. You can use
any editing tools to edit the file, including Editplus, Notebook o
r WordPad.

The type of sensor used in Surge is defined in the file
C:
\
tinyos
\
cygwin
\
opt
\
tinyos
-
1.x
\
apps
\
Surge
\
Surge.nc, which is a component
file linking all interfaces of Surge application.


In order to use a new sensor replacing photo (default) sensor,
you need to
take the following three steps:




Photo is defined as default in the components; replace it with the name of
the Sensor module that you want to use. Default line is



components Main, SurgeM, TimerC, LedsC, NoLeds,
Photo
,
RandomLFSR,

GenericCo
mmPromiscuous as Comm, Bcast, MultiHopRouter as
multihopM, QueuedSend, Sounder;




Define the SensorControl in order to power the sensor you want to use,
default line is


Main.StdControl
-
>
Photo
;





Define the ADC in order to read the ADC of the new sensor,
default line is



SurgeM.ADC
-
>
Photo
;


All sensor modules are available in
$TOS_HOME
\
tos
\
sensorboards
\
micasb


directory, type “cd $TOS_HOME
\
tos
\
sensorboards
\
micasb” and you will
see all the available sensor module filenames.


Choose the sensor you need

(in this case microphone), and replace

Photo
” with the component filename of that sensor, note you will use the
filename like “filenameC.nc” instead of “filenameM.nc”. For example, you
may use “MicC” as microphone here.


Save the file you modified.


12.

In a

cygwin window, type “cd $TOS_HOME/apps/Surge”, then type “make
mica2”, this will compile Surge application
reading microphone sensor

and
generate executable code for Mica mote.


13.

Download the new
Surge

program to mote 2.



35



Plug out the mote 0 from the 51
-
p
in cable; 2.Plug a sensor board on
the radioboard with label “2”, 3. Connect the sensorboard to
programming board using the 51
-
pin cable.




In the same cygwin window, type “
MIB510=COM1 make mica2
install.2
”, this will download the Surge NesC executable prog
ram to
this mote 2 and the mote ID is assigned as 2.




We have finished the work on mote2, now p
lug out the mote 2
sensorboard/radioboard set from the 51
-
pin cable.




Follow the procedure of changing photo sensor microphone sensor,
modify, recompile and down
load Surge application which reads
magnetometer sensor

instead
. The details step are intentionally
removed here, you need to figure out how to do it by yourself. However,
the only thing n
eeded to note:


Hint for magnetometer sensor


In Surge.nc, y
ou
may
ne
ed to set c
omponent
as
“Mag”,
you will also set
Main.StdControl as

“Mag” and
ADC is
Mag.MagX instead of “Mag”
,

because magnetometer sensor
actually
contains two sensors in X and Y
direction

and we will use the one in X direction.


Save the Surge.nc after
modification.


14.

In a cygwin window, type “cd $TOS_HOME/apps/Surge”, then type “make
mica2”, this will compile Surge application
reading magnetometer sensor

and generate executable code for Mica mote.


15.

Download the new
Surge

program to mote 3.


Plug out mot
e 2 from 51
-
pin cable; plug a sensorboard on mote 3 and
connect it to programming board using 51
-
pin cable,




In the same cygwin window, type “
MIB510=COM1 make mica2

install.3”, this will download the Surge NesC executable program to
this mote 3 and the mo
te ID is assigned as 3.




Plug out mote 3 and plug mote 0 back to programming board as
basestation. Turn on mote 1, mote2 and mote3.




Now the system setup will look like





36


Figure 5




Open
two cygwin windows,
in one window type cd
$TOS_HOME
/tools/java
”, ru
n
serial forwarder

in this window by typing:


java net.tinyos.sf.SerialForwarder
-
comm serial@COM1:57600


This will start SerialForwarder JAVA program,


In the other cygwin window
,
type cd $TOS_HOME
/tools/java
, run Surge in
this window by typing:


jav
a ne
t.tinyos.surge.MainClass YOURGROUPID


this will start Surge Java GUI
containing a graphical display of the sensor
readings from the mote

and
the
display
topology of network
.

It may take up to one minute to initialize the network topology, click “Fit to
sc
reen” if you can not see all sensors,
GUI

will look like:



37


Figure 6


Now you are monitoring three motes with different sensors. This is a very
basic and typical sensor network demo.




Save this Surge GUI figure using “PrintScreen” and include it in your
lab
report.


2.

Try to

find out what is the threshold value of each sensor? If you find it, you
will have a brief idea
a
bout how to
build

your own JAVA GUI for
a

WSN
application.


Hint:



The threshold value

is def
ined in the

Surge JAVA program, you may wa
nt to

c
heck


$TOS_HOME
\
tools
\
java
\
net
\
tinyos
\
surge
\
PacketAnalyzer
\
SensorAnalyzer.java







38

WSN
Lab
Final Project





Objective
:



Develop Design
your own WSN application

based on the existing MICA
hardware and software. Anything that is interesting, pr
actical and easy to
implement with your knowledge of WSN.


Requirement:




Design your application software based on the existing WSN application
such as Surge without any hardware modification.

You may choose your
original applications from the following:


1)

OscilloscopeRF

2)

SenseLightToLog

3)

SimpleCmd

4)

Surge




Submit your p
roject report including introduction of your application,
software
structure

(Hardware modification is not allowed)

and

code
description.



Demonstra
te your final project demo to Instructor/TA
.



Examples:


Example

1
: A night building security monitoring system

based on Surge
;


If photo sensor readings is below certain threshold
value
(as at night all lights
are off in a building), and if microphone sensor reading goes above certain
value (could
be someone unauthorized break into the building), then you
should take some response like send a
n

alarm signal
and when JAVA GUI
receive such alarm message, it will display

a

warning message/icon

at the
corresponding sensor on Surge GUI to inform user
.


E
xample

2
: A battlefield tracking system

based on Surge
;


If Magnetometer sensor goes above or below certain threshold
value
and
microphone
also
detects certain level of sound (vehicle(s) just passed by and
is detected by the both sensor mote
s
),
now you ca
n
show some warning
message/icon alarm icon on Surge GUI
.


Note
:

you don’t have to follow the examples;

Try to
design
an
interesting
application

with
your own idea

based on your current knowledge on WSN.