0% found this document useful (0 votes)
26 views21 pages

Lab Manual Pervasive Computing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views21 pages

Lab Manual Pervasive Computing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

DEPARTMENT OF SOFTWARE ENGINEERING

FACULTY OF ENGINEERING AND TECHNOLOGY


UNIVERSITY OF SINDH, JAMSHORO

Lab Manual
SENG-621 Pervasive Computing

Prof Dr Lachman Das | Rafique Ahmed Bhutto


Department of Software Engineering
FET, Usindh, Jamshoro
Basic Examples 2
SENG – 621: Pervasive Computing
BS(SWE) Part-IV [Morning]

Lab 1
Lab Objective:

Installing, running, understanding and coding in the cupcarbon simulator


Introduction
▪ CupCarbon is a Smart City and Internet of Things Wireless Sensor Network (SCI-WSN)
simulator. Its objective is to design, visualize, debug and validate distributed algorithms for
monitoring, environmental data collection, etc., and to create environmental scenarios such
as fires, gas, mobiles, and generally within educational and scientific projects. Not only it
can help to visually explain the basic concepts of sensor networks and how they work; it
may also support scientists to test their wireless topologies, protocols, etc.
▪ Networks can be designed and prototyped by an ergonomic and easy to use interface using
the OpenStreetMap (OSM) framework to deploy sensors directly on the map. It includes a
script called SenScript, which allows to program and to configure each sensor node
individually.
▪ CupCarbon simulation is based on the application layer of the nodes. This makes it a real
complement to existing simulators. It does not simulate all protocol layers due to the
complex nature of urban networks which need to incorporate other complex and resource
consuming information such as buildings, roads, mobility, signals, etc.

Installing Cubcarbon IoT Simulator


Download cupcarbon.jar (latest version )form following website
http://cupcarbon.com/
note[you need to install JVM 1.8 before running cupcarbon simulator]

Running cubcarbon IoT Simulator


To execute CupCarbon (jar file), double click on jar file
Or, use command window and go to the directory where the jar file is located.Then
execute the following command:

java -jar CupCarbon.jar

In the case of existence of a proxy, use the following command:

java -jar CupCarbon.jar proxy_host_name proxy_number_of_port

Creating First project of Cupcarbon simulator

Go to project menu and give name to save cupcarbon project ( you can choose any directory to save
the projects)

2
Basic Examples 3
SENG – 621: Pervasive Computing
BS(SWE) Part-IV [Morning]
Example 1: Hello World
This example shows how a sensor can display a message “Hello World”. The following
steps show how to do this:

Step 1. Create a new project: this can be done either by clicking on the “New
project” icon of the toolbar or on the menu Project New project. Choose the
name (example: helloworld) and the place where you want to save your project.

Inside this folder, 1 file (helloworld.cup) and 8 other directories will be created.
The content of each directory is given in the following:
a. config: it contains the simulation parameters file, the building list file, the

marker list file and two other directories (sensor and sensor_radios) that
contains the list of sensor nodes (one file by sensor node) and the list of
the radio modules of each sensor.
b. gps: it contains the list of routes
c. logs: it contains the log file
d. results: it contains the simulation results (a csv file)
e. scripts: it contains the SenScript files of the project
f. netevents: it contains the natural event files
g. tmp, network: are used by the simulator

Step 2. Add a new sensor node on the map: click either on the Add Sensor icon of
the toolbar or from the menu bar (Add Add Sensor Node). Then, click on the
map where you want to add the sensor node. Another click will lead to another
new sensor node and so on. To stop adding sensor nodes, just click on the right
button of the mouse. You can also click on the icon of the toolbar, or by
typing on the escape [esc] button of the keyboard.

3
Basic Examples 4
SENG – 621: Pervasive Computing
BS(SWE) Part-IV [Morning]

Step 3. Open the SenScript Window: the SenScript window can be opened by clicking on the
icon of the toolbar or from the menu Simulation SenScript Window.

Step 4. Write the script: add the following script (1) in the text area part of the SenScript
window:
loop
print "Hello W orld" stop

Add the name hello of this script in the File name field (2), then click on the Save button (3) just in the
left part of this field. This will create a file hello.csc in the directory scripts.

Finally, close the SenScript Window.

Step 5. Assign the SenScript file to the sensor node: Select the sensor node on the map (1).
4
Basic Examples 5
SENG – 621: Pervasive Computing
BS(SWE) Part-IV [Morning]
Go to Device Parameters in the left part of the main window (2). Then, select the hello.csc
file in the field Script file (3). And then, click on the apply button just in the right (4).

After assigning the center of the sensor will be colored in orange.

Step 6. Run the simulation: For this example, there is no need to parameterize the simulation, just click on
the run simulation button in the toolbar or in the simulation parameters menu in the left.

5
Basic Examples 6
SENG – 621: Pervasive Computing
BS(SWE) Part-IV [Morning]

Step 7. Simulation results: in this example the simulation results shows a Hello World message displayed
by the sensor.

Example 2: Calculate a+b


This example shows how to calculate the sum of two variables a and b.
[note: Repeat all the steps of Example 1 where only the script must be changed as follows]

loop
set a 7
set b 8 set x a+b
print a "+" b "=" x
stop
The simulation result will display 7 + 8 = 15.

6
Basic Examples 7
SENG – 621: Pervasive Computing
BS(SWE) Part-IV [Morning]

Lab 2
Lab Objective
1. Getting familiar with if-else and for statements in cupcarbon simulator
2. Understanding use of mark, delay and blink functions

Example 1: Marking nodes


A marker node represents in the reality a sensor node with a switched on led. It helps to
do a visible action rather than displaying messages. Marking a node is done by the
SenScript command mark 1. Unmarking sensor node is done by the command mark 0.
To mark a node, use the same steps of Example 1 with the following script:

loop
mark 1
stop

The simulation result will shows a sensor marked with a yellow green center.

Example 2: Marking randomly (game of light)


Add many sensor nodes on the map or generate a randomly network.

Then, use the same steps of Example 1, with the following script:

loop else
rand mark 0
x end
if(x<0.5 delay 1000
)
mark 1

The simulation speed must be equal to 200:

7
Basic Examples 8
SENG – 621: Pervasive Computing
BS(SWE) Part-IV [Morning]

The simulation results show marked and unmarked sensor nodes that change the marking state during
the simulation.

8
SENG – 621: Pervasive Computing
Basic Examples 9
BS(SWE) Part-IV [Morning]

In this example, the simulation will stop only if it reaches the simulation time. To stop
manually the simulation, just click on the button .
Example 3: Blinking and LEDs
Blinking
Use Example 3 with the following script:

loop mark 1
delay 1000
mark 0
delay 1000

Simulate with the simulation speed equal to 1000.


LEDs
Use Example 3 with the following script:

Loop
for i 0 15
led 13 i
delay 1000
end

Simulate with the simulation speed equal to 1000.

Note that the command led 13 0 is the same as mark 0 and the command led 13 1 is the
same as mark 1. The other colors are between the values 2 and 14. The number 13
means that this LED will be connected to the pin 13 of the considered embedded card. It
is not considered in the simulation.

Lab Tasks

Write a senscript to display table of 10 with delay of one second and marking the node when table is
printed.
Script:
___________________________________________
___________________________________________
___________________________________________
___________________________________________
___________________________________________
___________________________________________
___________________________________________
___________________________________________
___________________________________________
SENG – 621: Pervasive Computing
Basic Examples 10
BS(SWE) Part-IV [Morning]

Lab 3
Lab Objective:
1. Getting Familiar with Unicasting, multicasting and broadcasting modes of transmission
2. Using sensor nodes as routers (intermediate node), to relay the data to receiver sensor
node.

Example 1: Sending and Receiving messages

The following example will show a sensor node that will send each second 0 and 1 to another sensor node.
The receiver will be marked if it receives 1 (mark 1) and unmarked if it receives 0 (mark 0).

Step 1. Create a new project: this can be done either by clicking on the “New project” icon of the toolbar
or on the menu Project New project.
Step 2. Add two sensor nodes on the map: click either on the Add Sensor icon of the toolbar or from the
menu bar (Add Add Sensor Node). Then, click on the map where you want to add the sensor nodes so that
they can communicate (i.e., There exists a link between the two sensor nodes).

Step 3. Write the SenScript of the transmitter (sensor node 1): The SenScript of the transmitter can be
obtained directly from the SenScript window by clicking on the menu button Transmitter (Version 1) which
must be completed by adding the id of the receiver (i.e., 2) in the command send. Save the file with the name
transmitter.

loop
send 1 2
delay 1000
send 0 2
delay 1000

Step 4. Write the SenScript of the receiver (sensor node 2): As for the first script, The SenScript of the
receiver can be obtained directly from the SenScript window by clicking on the menu button Receiver (Version
1). Save the file with the name receiver.
loop
receive v
mark v
SENG – 621: Pervasive Computing
Basic Examples 11
BS(SWE) Part-IV [Morning]

Step 5. Assign the SenScript file to the sensor nodes: Select the sensor node 1 on the map (1). Go to Device
Parameters in the left part of the main window (2). Then, select the transmitter.csc file in the field Script file
(3). And then, click on the apply button just in the right (4). Do the same procedure for the second sensor node
by choosing the SenScript file receiver.csc. After doing this, the center of each sensor node will be colored in
orange and the name of the assigned SenScript file will be displayed on the sensor node in gray color.

Step 6. Configure the simulation parameters: To visualize the result of the simulation, in this example one
assign to the simulation speed the value 500 ms (1/2 second) and to the arrow speed the value 1000 ms (1
second). The arrows correspond to the send messages.
you can also turn on the acknowledgement messages by checing ACK checkbox in simulation parameters

Step 7. Run the simulation: Just click on Run Simulation button

The red arrow shows the sent messages. The value in the middle of the arrow represents the sent message. If
the transmitter is sending A and B instead of 1 and 0, then the scripts must be rewritten as follows:
Transmitter 2:

Loop
send "A" 2
delay 1000
send "B" 2
delay 1000

Receiver 2:
SENG – 621: Pervasive Computing
Basic Examples 12
BS(SWE) Part-IV [Morning]

Loop
receive v
if(v=="A")
mark 1
else
mark 0
end

To stop manually the simulation, just click on the button .

Example 2: Sending Broadcast messages


To send a message in a broadcast mode, one needs just to remove the id of the receiver in the send
command. One can also replace it by * or leave id empty. Let consider the same Example 7 with one
transmitter and 4 receivers, as follows:

The codes of the receivers are same. That is to say, one will assign the same SenScript file for each receiver. No
need to create different scripts for each sensor node since they have the same script. We need just to remove
in the script of the transmitter the id of the receiver. The script will be as follows:
Loop
send "A" *
delay 1000
send "B" *
delay 1000
Simulate …

Example 3: Sending messages to a group


Change the MY addresses of the sensor nodes 2 and 3 to the value 12. To do this, select each sensor node and
open the Radio Parameters view in the left of the CupCarbon environment. Modify the value of the field MY to
12 and then click on the apply button in the right of this filed.
SENG – 621: Pervasive Computing
Basic Examples 13
BS(SWE) Part-IV [Morning]

Once the button apply is pressed, one remark, for the corresponding sensor nodes, that between
the brackets situated in the right of the name in the center, the value is changed from 0 to 12. This

value represents the MY address.


To send messages to a group of sensor nodes having the same MY address, we modify slightly the code of the
transmitter, of the previous example, as follows:

Loop
send "A" 0 12
delay 1000
send "B" 0 12
delay 1000

The value 0 of this script means that the message will be sent for sensor nodes having the MY address given in
the followed number. In this example, this number is equal to 12.

Example 4: Routing messages


Lets’ create 4 sensor nodes as follows.
Create the SenScript codes for the transmitter (sensor node 1) and the receiver (here, the sensor node 4).
We will add two routers, the first one, the sensor node 2, will route the received messages to the sensor node

3, and the second router is the sensor node 3, which will route the received messages to the sensor node 4
(the receiver). The code for receiver and transmitter are same as in previous examples (Example 1) while the
codes of the routers are given as follows”

Router 1 (routing to sensor node 3) Router 2 (routing to sensor node 4)Simulate …


loop
receive v loop
send v 3 receive v
send v 4
SENG – 621: Pervasive Computing
Basic Examples 14
BS(SWE) Part-IV [Morning]

Using this method requires


sendtomcreate
* x a new script for each router. It is possible to use another method based
on the command which allows to send the message m to all the neighbors except the neighbor x. The
advantage of this command is to use the same script file for all the routers. Then, the scripts of the previous
example can be rewritten as follows:

The transmitter:

atget id id id = the identifier of the sensor node (in the example id=1)
loop
data p id "A" p = "1#A"
send p send "1#A" in a broadcast mode
delay 1000 wait for 1 second
data p id "B" p = "1#B"
send p send "1#B"
delay 1000 wait 1 second

The router, this script will be assigned to the sensor node 2 and 3:

atget id id id = the identifier of the sensor node (id of the router 2 or 3)


loop
receive rp the received message will be assigned to rp (eg. rp = 1#A or 2#A)
rdata rp rid v rid=1 and v=A (sensor node 2), rid=2 and v=A (sensor node 3)
data p id v p = 2#A
send p * rid send 2#A to all the neighbors except the neighbor rid (ie. 1 or 2)
The receiver:

Loop
receive rp read the received message and assign it to rp
rdata rp rid v rid = 3 and v=A
if(v=="A") if v==A
mark 1 the sensor node will be marked
else otherwise,
mark 0 it will be unmarked
end
SENG – 621: Pervasive Computing
Basic Examples 15
BS(SWE) Part-IV [Morning]

Lab 4
Lab objective:
Reading values of weather sensor and gas sensors.
Adding and sensing mobile nodes in the network.

Example 1: Reading digital sensor values


In this example, we will add two sensor nodes and one mobile. The first sensor node will send a message to its
neighbor (the second sensor node) about the state of its sensing unit each 100 milliseconds (0 if no
detection and 1 if an event is detected). The second sensor node will print the received message and will be
marked if it receives 1 and unmarked if it receives 0. A mobile will be added to pass near to the first sensor
node, exactly near to its sensing unit, in order to be detected.

Let first create the first sensor node that sends each 100 milliseconds the value of its sensing unit. Let call its
script sensor. Let increase its sensing unit so that to obtain the following result:

Script of the sensor node 1


loop
dreadsensor s
send s
delay 100

Then, the second sensor node will just await for messages received from the first one and be marked or not
according to the received message.

Script of the sensor node 2


loop
receive v
mark v

Before adding a mobile, first, we start with adding a route. To do this, we will add two markers and then select
both of them. Then we will type many times on the key ‘u’ of the keyboard until to obtain the following result:

The route must be saved using the button Save in the Marker Parameters view.
SENG – 621: Pervasive Computing
Basic Examples 16
BS(SWE) Part-IV [Morning]

Now, we can add a mobile and assign it the previously created route. This is done using
the field GPS file inthe Device Parameters view.

Once done, the mobile will have a center with the orange color. Then, the project is ready for
simulation.

For the simulation, change the value of the simulation speed to 0 ms and the Arrow Speed to 50 ms.

Go to device parameters panel and check mobility events option

Simulate….

Example 2: Reading analog sensor values


In this example the natural event (a gas) will generate random values following the Gaussian distribution (mean
= 22 and std = 4). The transmitter will read each 100 milliseconds the value of its sensor unit and then send it to
the receiver. The receiver will be marked if it receives a value that is greater than 20. The interface will look like
the following one:
To create a file with 100 natural events generated each second from a Gaussian distribution (mean=22 and
std=4), we will use the Natural Event Generator. The script of the transmitter and the receiver are given as
follows:

Transmitter:
loop Receiver:
areadsensor v loop
if(v!="X") receive y
print v print y
rdata v a b c if(y>20)
send c 2 mark 1
end else
delay 1000 mark 0
end
SENG – 621: Pervasive Computing
Basic Examples 17
BS(SWE) Part-IV [Morning]

The simulation results will show something like the following figures where the sensor node is unmarked after
receiving a value less than 20 and it is marker after receiving the value 23 which is greater than 20.
Unmarked sensor node after receiving the value 14<20 Marked sensor node after receiving the value 23>20

It is also possible to write the received values in a file during the simulation using the command
printfile as follows:

loop
receive y
print y
time t get the current simulation time
printfile t y print in a file the current simulation time and the received value x
if(y>20)
mark 1
else
mark 0
end

The obtained file has the same name as the executing sensor node and it is located in the directory results.
SENG – 621: Pervasive Computing
Basic Examples 18
BS(SWE) Part-IV [Morning]

Lab 5
Lab objective
Getting information about neighboring nodes
Getting information regarding radio parameters (channel Id, My ID, Radio module) of the sensor.
Changing transmission power levels of the sensor nodes.

Example 1: Working with radio parameters


In this example, we will use the same procedure as Example 1. Instead of displaying
Hellow World we will display each second:

1. The Network ID
2. The Channel
3. The MY address
loop
atget nid v1
atget ch v2
atget my v3
print "network id=" v1 " channel id=" v2 " my id is=" v3

delay 1000

Change the simulation speed to 1000 and simulate …

Example 2: Transmission power


In the following, in order to show how to change the power of transmitted signal, let consider the
following example with three sensor nodes:

The first sensor node will send A and B each second and the other sensor nodes will display the
received message (i.e., A and B). After each transmission of the couple A and B we will change the
percentage of the power of the sending message. In the beginning we will put 100% and then we
switch to 60%. The script of this situation is written as follows:

The script of the transmitter:


loop
SENG – 621: Pervasive Computing
Basic Examples 19
BS(SWE) Part-IV [Morning]

atpl 100
send "A"

delay 1000
atpl 60
send "b"
delay 1000
The script of the receiver:

loop
receive x
print x

Simulate with the following simulation parameters:

The results are close to:

100% 60%

Example 3: My coordinates and my neighbors


In this example, we will add 3 sensor nodes as follows and we will display they GPS
coordinates (longitude and latitude).

1. Display the Coordinates of each sensor node: the script that allows to display
the coordinates of a sensor node is given by:
SENG – 621: Pervasive Computing
Basic Examples 20
BS(SWE) Part-IV [Morning]

loop
getpos x
print x
stop

Assign this script to each sensor node and simulate. The result will be as follows:

To recuperate each coordinate separately, use the command rdata. One can use also the comma
nd getpos2 that allows to recuperate the coordinates into 2 separated variable as follows:
loop
getpos2 x y
print x y
stop

Obtaining the list of the neighbors: To obtain the list of the neighbors of the sensor S1 for
example, we can use two commands. The first one is atnd x and the second one is atnd x y. The
first command allows to assign to x the number of neighbors and the second one allows to assign
to x the number of neighbors and to y the list of the identifiers of the neighbors separated by #. In
the following we present two scripts using each of them each of these commands and the results of
their simulation.

Script 1 (atnd x): this will display the number of the neighbors of S1.
loop
atnd x
print x
stop

Simulation result:
SENG – 621: Pervasive Computing
Basic Examples 21
BS(SWE) Part-IV [Morning]

Script 2 (atnd x y): this will display each second the identifier of each neighbor (for good visualization, you
must set the value of the simulation speed to 1000):
loop
atnd n v
for i 0 n
vget x v i
print x
delay 1000
end
stop

Simulation result:

In the following, we will display each second the distance with each neighbor

You might also like