Design and Implementation
I choose system development research method to development a new system for TinyOS-2.x as figure 17. This is a way of testing wireless sensor network theory. Demonstration of system will prove the theory.
Step 1: Get background knowledge of my topic. For instance, theory of wireless sensor network, TinyOS and so on. After this step I could find out the tasks (problems) in my project.
Introduction of this report introduce this step.
Design system architecture and define system functionality and components and so on. To find the general ideal to solve those problems. Chapter 3.1 shows the details of design architecture.
Due to my project is making a software system. I need to draw class diagram for each function before implementation.
I separate the whole system into several parts. Each part corresponding to one or two functions. At last I combine all the functions together.
Making evaluation of this system, which is I have developed. The system evaluation is based on Experiment. Chapter 4 describes the running result of this system. The purpose of evaluation is to prove the validity and reliability of this system.
The system receives data from gateway, which is primary data. The data includes temperature, humidity, light, sound, and time. To collect those quantitive data, I chose measurement and observation.
In the testing chapter I will describe how to analysis those data. Basically I will use excel to make statistics chart.
Desgin and Implementation
Display nodes’ map topology at home and Plot sampling values versus time in real time
Graphical user interface and Data Acquisition system design is based on the Octopus. Due to Octopus just a general solution, which is means it is not specific for our research, So I need to modify it and add some other functions. First of all I will explain the global communication structure of this system, which is illustrate in figure 18.
As shown above PC connect with gateway by serial communication and network communication. There are eight components in PC. Each component at least corresponds to a Java Class. The communication protocol between gateway and GUI is also defined as java class. Here I will explain the details about each component and the relationship among the components. The relationship among components we can be seen from class diagram.
First of all, figure 19 shows the class diagram of graphical user interface. The arrow line describe the relationship between two classes.
All of the classes in this class diagram are created based on Octopus. There are many other classes also developed for this system for some special function. Those classes have not shows in this class diagram. I will explain it in next section.
This is the main class, and program starts to execute from this Class.
All the panels are created and added into a JFrame. The threads are also created and started. This Class has modified by me. It because I need add some more JPanels on this JFrame. For instance, NewRequestPanel, SelectPanel and so on.
This class implements a interface, Runable. It means that this class is a thread.
There are two important methods in this Class, except constructor.
The one is main method is run(), which is called when the thread start to execute. Another method is messageReceived() that is used to receive message from the serial port.
Mote Class & MoteDatabase Class
One object of Mote class represents of a mote, according to the packets received from real mote.
A link list is created in Mote Database class. The link list is used to store the instance of mote object.
This class is used to describe a map of wireless sensor network. The map as shown in figure 20.
The red cycle is described as coordinator (gateway).
Those blue cycles are described as common mote.
Basically there are five methods in this class, which are shows in below:
Paint (): when the Panel need to repaint, this method will be invoked.
Desgin and Implementation
drawCircleMote(): Checking if it is gateway, then decide to chose which color for cycle.
g2.setPaint(Color. red); // gateway
g2.setPaint(Color. blue); // mote
drawMoteText(): this method is used to draw text from a mote.
drawParentRoute(): this method is used to draw the route between a mote and its parents.
drawParentRouteLabel(): display some information about route.
This class extend a LinkList, which is a container. It store objects, and one object corresponding to a mote.
This Class is automatically generated by mig. It defined the structure of a message, which is designed for communication between GUI and gateway and from gateway to regular mote. It is used for request from user. the structure of this message shows in figure 21.
This class defined the structure of a message, which is designed for the communication from regular mote to the gateway, and from gateway to GUI. The message include moteId, count, reading, quality, parented, reply. The message structure shows in figure 22 next page:
moteId: the message can be transmitted by many motes before it arrives to gateway.
Count: It is a kind of sequence number, incremented at each reading of the sensors.
Reading: it is the value read from the sensors.
Quality and parented: they are the related to the connection of the mote which has emitted the packet, and its parent.
Reply: it is used for checking if a packet is a reply or just a reading.
This class is used to display the value of a mote in real time. The curve display is shown in figure 23.
This class is used for user to send request to network. We can see that Mote0 have been selected by user from top of figure 24. the check box is used to broadcast request of this mote.
The “Auto” button is corresponding to a time-driven mode. “Query” button is a query-driven mode.
To Sleep button is used to make the mote in sleep state. The “wake up”
button is used to wake up the mote.
The user can adjust the Sleep duty cycle, wake up duty cycle, Sampling period and threshold of the mote. It as shown in the middle of figure 24.
The ‘Read the sensor’ button is used to request a reading from mote.
There are three buttons in below of Read the sensor button, those are Add Selected button, Add All button, and Clear button. The function of them are use to display motes value in chart.
User can use Legend Panel to control the map panel. When a new legend is chosen, the map will automatic update.
In the middle of the Legend Panel in figure 25, there is a slider to choose time out. This time is about how long time the route appear on the map. The code is shown below:
The CSV database file is created when the checkbox “Log in a file” is checked.
Display nodes’ deployment map at home in real time.
3-D picture with person shows in newMapPanel. This function is based on Hairong Yan’s algorithm (person detection algorithm). There are totally 15 saturation of this apartment, which are shown in table 5.
In order to shows the person in 3-D picture, I created a new panel, which is called NewMapPanel. This class is similar with MapPanel. The difference between NewMapPanel and MapPanel shows in below:
1. The cycle (mote) have fixed location in NewMapPanel.
2. 3-D picture as background in NewMapPanel, which is able to change.
NewMapPanel is working like MapPanel, it also relate with other classes..
The instance of NewMapPanel in attribute of OctopusGui class, Scout class, and LegnedPanel class.
The instance of LegendPanel class, MoteDatabase class, Mote class and RequestPanel class in attribute of NewMapPanel class.
Class diagram of 3-D as shown in figure26.
In order to give the fixed location for each mote, I need to defined the location for each mote in Mote class. The program as shown in below:
NewMapPanel class have two methods are used to check moteId, which are drawCircleMote() and drawCircle(). when moteId is gateway then getting the x value and y value. Afterwards draw the red cycle in corresponding location.
When moteId is equals 1, then getting the x1 and y1. Afterwards draw the blue cycle in corresponding location. By using this way all the motes will be displayed on this Panel.
Skype call, SMS and Email
Calling, message sending, and email sending function have implemented by Saad Mubeen at last year. There are three reasons for me to improve his work.
At first, he implement these three function in TinyOS-1.x, as we know the code cannot direct using in TinyOS-2.x.
Secondly, he did not using thread for each function, which is means that his code working in sequence. Those functions can not working concurrently. We need to turn this program into separate, independently running subtasks.
Thirdly, Users can not type in telephone number. They only can call the fixed telephone number.
JSkypeSMSTest Class: the function of sending message through skype is implemented in this class.
JSkypeTest Class: the function of calling through skype is implemented in this class.
SendEmail Class: the function of sending email is implemented in this class. The java application to send email using google gmail account
SelectPanel Class: this class extend JPanel, it is added into OctopusGui.
OctopusGUi Class: this class extend JFrame.
I have draw the basic class diagram, before I implement these functions. SelectPanel class have three instances, and it own can be a instance of OctopusGUI. As we can see from figure 27.
1. Make the code suitable for TinOS-2.x:
¾ Software requirements:
Install Java SE Development Kit (JDK) 6.
Download Javamail 1.4 to use SMTPS protocol.
Skype.jar include into java package.
Package “net” include into java package. This is the original package developed by Lamot and contains java files related to Skype API changes.
Install skype and Virtual Audio Cable.
¾ Setting of Environment variables:
There is a simple way to set environment variables. It is shown in handover Document .
¾ The java code shows in appendix.
Using a thread for each function:
Each independent subtask is corresponding to a thread. Each thread runs by itself and has the CPU to itself, so we can say those threads running concurrently.
Generally there are two ways to achieve multiple threads. The one is inheriting from thread. Another one is implement runnable interface. Due to the common resource is big, so I chose the second one.
Implement runnable interface following steps:
Step 1: Create JSkypeSMSTest class implementing runnable interface.
Step 2: Making run method in this class, and method type is public
Step 3: Create a object of JSkypeSMSTest class.
Step 4: Create a new thread, passing the object as target.
Step 5: Call start method on the thread.
Figure 28 gives the example code of these five steps.
3. New GUI for Skype call, Sms and Email
I have set a default telephone number for user. It is as shown in figure 29.
User can press CA directly call this number.
The user can also press the button to call any numbers, which they want. User can press C to remove numbers, which they before typed in.
There are two send button on this panel. The one is used to send message, another one is used to send mail.
Figure 29 shows the graphical user interface of calling, message sending and Email sending function.
Telephone number (0-9) buttons:
After user press one button. for instance, button ‘1’, then this part of code will be executed, which is shows in below:
jtf1.setText(jtf1.getText()+”1″);// jtf1 is a instance of JTextField
After user type in the whole telephone number, who need to press ‘CA’ to call this telephone through Skype. The code shows in below:
String number=”Call +”+jtf1.getText();//get the the whole telephone number
new JSkypeTest(number);// the parameter (number) passing to constructor of JSkypeTest class
User can clear the jtf1 by press ‘ C ‘ button. the code shows in below:
The layout manager have not used in SelectPanel class. The position of components are seted by setBounds() method.
Dissemination parameters or commands to sensor networks.
To control the mote by user, PC need send data back to mote. There are many ways to solve this problem. For examples, by serial communication, by network communication (TCP/IP protocol) or by GSM and so on. I have implemented two modes, the one is by serial communication and another one is network communication.
Mode 1: PC to gateway by serial communication
Design: I have draw the flowchart of this task before programming. The flowchart as shown in figure 30.
Table of Contents
List of Figures
List of Tables
1.2 PURPOSE AND AIMS
2 Theoretical background
2.1 WIRELESS SENSOR NETWORK
2.2 IEEE 802.15.4
2.3 JAVA COMMUNICATIONS ARCHITECTURE FOR TINYOS APPLICATIONS
3 Design and Implementation
3.1 DISPLAY NODES’ MAP TOPOLOGY AT HOME AND PLOT SAMPLING VALUES VERSUS TIME IN REAL TIME
3.2 DISPLAY NODES’ DEPLOYMENT MAP AT HOME IN REAL TIME.
3.3 SKYPE CALL, SMS AND EMAIL
3.4 DISSEMINATION PARAMETERS OR COMMANDS TO SENSOR NETWORKS.
3.5 DEVELOPING A MIDDLEWARE FOR THE SYSTEM’S INNER AND EXTERNAL COMMUNICATION
3.6 DATA ACQUISITION
3.7 DATA REPLAY
5 Conclusions and Discussions
5.1 SUMMARY OF CONTRIBUTION AND RESULT
5.2 ANSWER TO RESEARCH QUESTIONS.
5.3 LIMITATION AND FUTURE WORK
GET THE COMPLETE PROJECT