Download (Notes). - Brunel University London

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CS3108B Ubiquitous Application Development
Lab RFID – Location Awareness with RFID
Introduction
This is the last of the lab series (labs 9 and 10) and moves away from the user interface to a more
ubiquitous, sensor based environment. We are going to use RFID devices to provide the user with
specialised interaction with the environment. RFIDs provide an excellent location sensor. Take a look
at the RFID reader we will be using today at http://www.phidgetsusa.com/RFID_Reader_tags.asp.
Three lab experiments will be undertaken: (1) Location aware file system, (2) Ambient Advertisement
(similar to Minority report) and Group Identification, and lastly (3) Security Tracking. The aim of the
lab is to gain an introduction to development with sensor networks, together with some experience of
how such networks could be used.
Before attempting the lab, ensure that you have an RFID tag or Key-ring.
Location-aware file systems
We are all used to logging into a computer and having access to a file-system (e.g. H: drive).
System managers are used to providing such access to the file-system over the network and allowing
users to access files from remote locations. Problems can arise with this approach when: (a) the
network bandwidth is low and/or files are large (PERFORMANCE) and (b) the network connection is
not continuous (AVAILABILITY). The first experiment looks at another approach – location aware
file-systems and synchronisation. We are going to develop a system that copies files into a local
directory when your RFID is detected. In order to undertake this task we are going to assume that
you are an International Business man based in TOKYO, who also works in LONDON.
1. Create directory “Location”, with sub-directories TOKYO and LONDON.
2. Copy one or more files into TOKYO.
3. Download the Phidget examples into your “Location” directory (from http://www.phidgets.com/
downloads  windows  Java  Examples. Look at the downloaded code and directories.
JNI is added to the directory name – what is this?
4. Make a note of your identify (e.g. your RFID code)
In order to carry out (4) you will need to copy an example program and the Phidget.jar file into your
“Location” directory. The files can be found in
http://people.brunel.ac.uk/~csstdjb/UBICOMP/Location.zip.
5. Once you have copied the files, compile and run the file:
H:> cd \JavaJNI\Simple Examples
H:> make.bat
To run:
java -classpath .;phidget21.jar RFIDExample
6. Connect up the RFID reader and move your tag near to the reader.
7. Make a note of your code!
Let us review the RFID code:
/*
* Copyright 2007 Phidgets Inc.
*/
All rights reserved.
import com.phidgets.*;
import com.phidgets.event.*;
public class RFIDExample
{
Version 1 © David Bell
Page 1 of 5
public static final void main(String args[]) throws Exception {
RFIDPhidget rfid;
System.out.println(Phidget.getLibraryVersion());
rfid = new RFIDPhidget();
rfid.addAttachListener(new AttachListener() {
public void attached(AttachEvent ae)
{
try
{
((RFIDPhidget)ae.getSource()).setAntennaOn(true);
((RFIDPhidget)ae.getSource()).setLEDOn(true);
}
catch (PhidgetException ex) { }
System.out.println("attachment of " + ae);
}
});
rfid.addDetachListener(new DetachListener() {
public void detached(DetachEvent ae) {
System.out.println("detachment of " + ae);
}
});
rfid.addErrorListener(new ErrorListener() {
public void error(ErrorEvent ee) {
System.out.println("error event for " + ee);
}
});
rfid.addTagGainListener(new TagGainListener()
{
public void tagGained(TagGainEvent oe)
{
System.out.println(oe);
}
});
rfid.addTagLossListener(new TagLossListener()
{
public void tagLost(TagLossEvent oe)
{
System.out.println(oe);
}
});
rfid.addOutputChangeListener(new OutputChangeListener()
{
public void outputChanged(OutputChangeEvent oe)
{
System.out.println(oe);
}
});
rfid.openAny();
System.out.println("waiting for RFID attachment...");
rfid.waitForAttachment(1000);
System.out.println("Serial: " + rfid.getSerialNumber());
System.out.println("Outputs: " + rfid.getOutputCount());
System.out.println("Outputting events. Input to stop.");
System.in.read();
System.out.print("closing...");
rfid.close();
rfid = null;
System.out.println(" ok");
if (false) {
System.out.println("wait for finalization...");
System.gc();
}
}
Version 1 © David Bell
Page 2 of 5
}
When we run the program the main method is executed (what does it do?). After starting up and
printing some text the program listens for any RFIDs within 10cm radius. Once one is detected, a
method is called – which one?. Two important parts of the program are covered - start-up and RFID
detection.
We now want to add some code that copies the contents of our TOKYO directory into out LONDON
directory when our RFID is recognised. Copy RFIDExample.java to RFIDExample2.java. The code
below will perform the copy, but you need to check that your own RFID id is recognised (i.e. copy
ke.get_TagNumber() into a String and compare with your tag using compareTo(“your tag”);
try{
Runtime.getRuntime().exec( "cmd.exe /C COPY TOKYO LONDON" );
} catch(Exception e) {
System.out.println("Exec did not work "+e);
return;
}
Compile and test your program!
You may have noticed a problem – the program repeatedly copies the file/s from TOKYO to
LONDON. Add some code that ensures that the file/s are only copied once! In order to make
the system more usable, you would need to think about improving the syncronisation (direction, file
change rules etc.).
When you are happy that your program works (i.e. check the LONDON directory) and have added
some code that restricts the file copying to once. A try/catch block is required when an exception may
be thrown by a methods (see http://java.sun.com/docs/books/tutorial/essential/exceptions/).
We are now ready for the second part of the lab –
Ambient Advertisement and Group Identification
The lecture series started with a clip of the science fiction film Minority Report. Part of the clip shows
Tom Cruise walking past a display that was able to tailor the advertisements to him. We are going to
try and replicate this system using RFIDs.
The first step is to choose the product that you wish to advertise to yourself, your friends or both.
The system could include intelligence, for example:




Should the advertisement change at different points in the day – or – on different days?
Should the advertisement change depending on where you have been prior to passing the
advert?
Should the advertisement change depending on who you are with (or when a group pass by)
Think of some others!
Let us now develop our ambient advertiser. Copy RFIDExample2.java to RFIDExample3.java.
You now need to make the following changes:
1. Re-apply the code (RFID2.java) that detects that you are next to the advertisement.
2. Change the command execution code to start a browser and open a particular web site (your
advertisement).
Runtime.getRuntime().exec( "cmd.exe /C START " + adUrl);
It is now time to work in a group!
Version 1 © David Bell
Page 3 of 5
We have talked about ubiquitous systems being able to provide intelligent to a space. One example
of such intelligence is the detection of a group of people and executing a system to support the group.
In this experiment we are going to separate into two groups:
1. Football Commentators (http://www.liverpoolfc.tv)
2. News Reporters (http://www.bbc.co.uk)
We now need to change RFID3.java to open one of the above web sites when all members of the
group have been detected. Discuss within your group how to do this?
Hint! Maybe add a HashMap of people:
HashMap<String, String> people= new HashMap<String,String>();
The map could store the tag id and a Y/N flag. It could be initialised at start-up with the required IDs
and N. As each tag is detected the flag could be set to Y.
Alternatively, implement a counter that opens the web page when a preset number of people are
detected (remember to consider duplicate RFIDs).
The third and final part of the lab….
Security Monitoring (Optional and difficult)
We are now going to look at the darker side of sensors and monitoring – security! Before embarking
on the development tasks, let us consider a quote from Peter Wright (a former Assistant Director of
MI5 – the British Security Services) – see Stajano, 2002 p.152:
Later, MI5 brought in a complicated system of enciphering Watcher
communications. I pointed out that this made no difference, since
signals would now stand out even more against the Police, Fire and
Ambulance service communications, all of which were en clair
(uncoded). They did not seem to understand the Russians were getting
most of the information from the traffic itself, rather than the content of
the messages. Traffic analysis would tell them when and where a
following operation was being conducted, and by cross-checking that
with their own record they could learn all they needed to know.
This type of traffic analysis can equally be applied to sensor networks. Let us assume that that one
PC is the Tower of London outside the Crown Jewels room. Develop a system that detects if the
same person enters this area more than 5 times – when this happens an alarm is raised!
Copy RFID3.java to RFID4.java and make changes to your code.
1. Define a HashMap<String, Integer>
2. Update the HashMap when an RFID is detected
If you want to build a distributed sensor network, the HashMap could be replaced with an iSpace. On
detecting the RFID the iSpace could be updated – adding a row <id>,<timestamp>. If we want to
determine the movements over time, what is the main problem with the iSpace example provided.
Code listing: Browser Ads, Counter
// Declarations
private int Detected=0;
private String adUrl="http://www.porsche.com";
// Within listerner
Version 1 © David Bell
Page 4 of 5
try{
// Code for both copying and starting a browser
Runtime.getRuntime().exec( "cmd.exe /C COPY TOKYO LONDON" );
if (Detected==0){
Runtime.getRuntime().exec( "cmd.exe /C START " + adUrl);
Detected++;
}
} catch(Exception e) {
System.out.println(
"Exec did not work "+e);
return;
}
}
Version 1 © David Bell
Page 5 of 5