Friday, June 27, 2008

Temperature Monitor Network

Task Description:
"Implement a temperature sensing application that works as follows. Each sensor will monitor the temperature in its area, sensing every 20 seconds. If a sensor senses that the temperature has risen above a given threshold(e.g., 80 degrees), it will do as follows:
1. It will sense more frequently, every 5 seconds, until the temperature drops below the threshold.
2. It will report its readings to an application running on the host computer attached to the base station.

3. It will trigger its neighbors to report their readings to the base station for the next 1 minute."[1]

Analysis:
I need to combine task 2 with part of task 4 for implement this task. But the sensor needs to send a message to not only the bast station but also its neighbor so that I have to spend a little time to think about the possible conflicts. In addition, I added one small functionality to this task: the base station can set or change the temperature threshold.

I also drew a work-flow chart like before:

From the above chart, we know that there are four threads involved in the spot side and two threads in the base station side.

Base Station Side
1. Set Threshold Thread
This thread can get user's command input and broadcast this command in the entire network. The format of user's input should be like this: degree XXX.XX

2. Receiver Thread
When the base station receives the temperature reported from a free-range spot, it should print it out.

Free-range Spot Side
1. Threshold Receiver Thread
I set up a internal parameter to store the value of threshold. The spots should change the threshold's value after they get the command from the base station.

2. Temperature Detecting Thread
This thread is derived from task 2. The LEDs will blink in different color according to the degree of current temperature. If current temperature's degree is great than the given threshold, the spot should accomplish two things including reporting this degree to the base station and sending a trigger to their neighbors.

3. Trigger Receiver Thread
When a spot receive a trigger from its neighbor, it will store current time-stamp into a hashtable.

4. Trigger Handle Thread
It's a endless thread to check all existing elements of the above hashtable one by one. If any elements have been kept in this hashtable for a minute, it should report current temperature to the base station and remove this element.

Implementation:
1. A spot receivers a trigger from its neighbor
...
((RadiogramConnection)dgConnection).setMaxBroadcastHops(1);
...
dg.reset();
dgConnection.receive(dg);
tmp = dg.readUTF();
...

2. A spot sends current temperature to the base station
...
((RadiogramConnection)dgConnection).setMaxBroadcastHops(4);
...
dg.reset();
dg.writeUTF("T"+strDegree);
dgConnection.send(dg);
...

3. Testing
I spent most time on testing this task. I use the following use cases:
a. Set the default threshold as 60
All spots reported current temperature to the base station because current temperature is higher than 60.

b. Turn off the spot after it sends a trigger to its neighbor
The triggered neighbor spot exactly reported current temperature to the base station one minuter later.

c. Continuously change the threshold by command line
All spots worked very well based on different thresholds.

Difficulty and Challenge:
This task seems easy for me because I already accumulated some experience about Sun Spot. Basically, I didn't encounter any big trouble while programming. About challenge, I have to say testing is still a time-consumption part.

Time Distribution:

Task

Description

Deadline

End Date

Total Time (hrs)

5

Advanced Temperature Monitor

07/11/2008

06/30/2008

15.7

Sub Task

Time

Experiments about using mesh routers

0.5

Finish a host application containing two threads

1.5

Finish a spot application including four threads

3.2

Test all applications

8

Miscellaneous Task (updating the blog, documents and so on)

2.5



[1]Quoted from the section "Task 5" of Class Requirement Document
Written by Professor Sami Rollins