Monday, June 9, 2008

Implementation about Temperature Monitor

Task Description:
"Implement an application that monitors the temperature and changes the color of the LEDs on the SPOT based on the following thresholds:
Temperature >= 80: red
Temperature 60-79: green
Temperature"[1]

Analysis:
This task is a simple SPOT application that contains two parts: continuously getting current temperature and indicating actual degrees by different LEDs' colors. It's very easy to catch the temperature by invoking the method getADCTemperature:"Convience Function to get internal temperature sensor on the ADC from the EDemoBoard[2]". Then I need to blink the SPOT in different colors according to given rules. In order to change LEDs colors, I can use the method SetColor or SetRGB that exist in com.sun.spot.sensorboard.peripheral.ITriColorLED. In general, I can get familiar with some basic SPOT libraries by implementing this task.


Implementation:
I realize this task first in an easy way to learn these basic APIs. I attached the main part of my simple code that can also satisfy the requirements of Task 2:


--------------------------------------Code--------------------------------------------

protected void startApp() throws MIDletStateChangeException {
IBoard=EDemoBoard.getInstance();

//initialize all LEDs
ITriColorLED[] led = IBoard..getLEDs();
for(int i=0 ; i < color="#008000">// endless loop
try{
//get current temperature
double dDegree=IBoard.getADCTemperature().getFahrenheit();

//choose correct color according to current fahreheit degree
LEDColor clr1;
if(dDegree>=80){
clr1=LEDColor.RED;
}
else if(dDegree>=60 && dDegree<80){ clr1="LEDColor.GREEN;" clr1="LEDColor.BLUE;" color="#008000">//change LEDs' color
for(int i=0 ; i < style="font-weight: bold;">Performance and Testing:
I deployed my code to one free-range SPOT and it worked. It blinked in a red color in the afternoon when the degree is greater than 90. And I tested it in the morning when the degree is only 69, it correctly flashed in a green color. In order to make it easy to test my source code, I change the color-change scale and make the value of thresholds much closer. For example, when the basic temperature is 89.5, I execute the follow rules:
Temperature >=90: Red
Temperature 89-90: Green
Temperature <89: style="font-weight: bold;">Advanced Performance:
I combined the project AirText to this task to display current temperature. When I shook the SPOT from left to right, I could see the Fahrenheit degree in a given color.


Difficulty and Challenge:
This task is comparatively easy so that I didn't encounter any big issues or challenges. But I ever got in some big trouble that cost a couple of hours to deal with when I ran this task on the SPOT.I simply describe two problems here and will also generalize all problems and relevant solutions in another individual post.

1)Applications do NOT run on the SPOT.
I used the command "Clean and Build Project" to compile my project by Netbeans 5.5.But I didn't see the expected result after I finish deploying my project to the SPOT.The SPOT didn't make any response even though I just used very simple code. The same situation happened when I ran the demo BounceDemo-OnSPOT.But if I planted the demo AirText to it, it worked. So I found the first reason causing this wrong situation. I used "ant enableota" to open OTA mode and forgot to turn it off. After I executed "ant disableota", the SPOT can run the demo BounceDemo-OnSPOT.

The second reason is difficult to find out because basically we often ignored it.When we use Netbeans IDE to create SPOT project, it will generate the default class "StartApplication". In general, we changed its name to different one but we don't know to modify the file MANIFEST.MF related to generating the jar file. The content of MANIFEST.MF is like below:

MIDlet-Name: TemperatureMonitor
MIDlet-Version: 1.0.0
MIDlet-Vendor: Sun Microsystems Inc
MIDlet-1: src/org/sunspotworld/StartApplication, , org.sunspotworld.src/org/sunspotworld/StartApplication
MicroEdition-Profile: IMP-1.0
MicroEdition-Configuration: CLDC-1.1

We need to change the fourth line to:
MIDlet-1: ,, org.sunspotworld.TemperatureMonitor
org.sunspotworld : Package Name
TemperatureMonitor : Main Class Name

In one word, you should check the OTA mode and the main class name in MANIFEST.MF first if you encounter the same problem as mine.

2)Applications die and can NOT reset the SPOT.
Due to the first problem, the SPOT cannot find main class to run. When I booted the SPOT, its indication Light just constantly flashed like being in the stalemate. Worse of all, the computer cannot find it when I tried to deploy the other correct project to it. I always receive the same warning messages such as the following ones:

SPOT Client starting...
Port COM6 unavailable...
Available ports: COM3
retrying...
Port COM6 unavailable...
Available ports: COM3
retrying...
Port COM6 unavailable...
Available ports: COM3
retrying...
Available ports: COM3

Error: Spot not found on port: COM6 not found

I also used the command "ant -Dport=COM6 slots" according to Sun Spot User's Guide, it didn't work. Even I tried all solutions that I got from the internet, my computer still didn't detect this SPOT. It was unexpectedly recovered after I carelessly rebooted my computer.

So please try the following two solutions to solve the same problem:

To execute the command "ant -Dport=COMn slots" in the local directory of your project;
COMn : the port connected to your SPOT

To reboot your computer;


Time Distribution:

Task

Description

Deadline

End Date

Total Time (hrs)

2

Temperature Monitor

06/13/2008

06/12/2008

10.9

Sub Task

Time

Create the framework of this project

0.5

Implement the two interfaces and main class

2.5

To create simple code to realize the requirement of this task

0.2

Solve two problems:

1) Applications do NOT run on the SPOT.

2) Applications die and can NOT reset the SPOT.

4.2

Combine AirText project to this task

0.5

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

3



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

[2]http://www.sunspotworld.com/docs/Orange/javadoc/com/sun/
spot/sensorboard/EDemoBoard.html#getADCTemperature()

SPOT Library

For this task, I mainly read some documents such as tutorials , guides and javadocs, and also studied some source code of demos.

The following two SPOT libraries are important for implementing Task 2:

com.sun.spot.peripheral : "Interfaces and classes dealing with the hardware on the SPOT processor board."[1]

com.sun.spot.sensorboard : "Contains highest level interfaces and concrete classes that make up the SunSPOT sensorboard libraries."[1]

Demos:

BounceDemo-OnSPOT
"In this demo, the row of LEDs on the top board of each Sun SPOT
represents a tube. Note the red LEDs at either end of the LED row.
Each represents a cork that keeps the ball in the tube. At first, the
ball on any Sun SPOT will be blue. However, if the Sun SPOTs are
able to communicate with each other, they will allocate different
colors for the ectoplasmic balls to avoid, as much as possible, duplication."[2]

AirText
"This application uses the linear array of tricolor LEDs on the eDemoboard
and "persistence of vision" to display text in thin air when the SPOT is
moved back and forth."[3]

BroadcastSample
"This simple demo shows you how to use the radio to broadcast some
data to any listening SPOT(s)."[4]

RadioStrength
"A simple application for 2 SPOTs. Each SPOT broadcasts 5 packets per
second and listens for radio broadcasts from the other SPOT. The radio
signal strength of the packets received is displayed in the SPOT's LEDs."[5]

Time Distribution

Task

Description

Deadline

End Date

Total Time (hrs)

1

Familiarizing with SPOTs' demos and APIs

06/13/2008

06/12/2008

15.1

Sub Task

Time

Install SPOT SDK(NetBeans IDE 5.5, JDK1.5,SDK)

0.5

Read Tutorials

1.5

Read Sun Spot User’s Guide

1.5

Read Sun Spot Library APIs (javadoc)

2

Study BourceDemo-OnSPOT

2.5

Study AirTextDemo

1.2

Study BroadcastSample

2.2

Study RaidoStrength

1.5

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

2.2


[1] Quoted from http://www.sunspotworld.com/docs/Green/javadoc/
[2] Quoted from http://www.sunspotworld.com/docs/Green/Tutorial/EctoplasmicBall.html
[3] Quoted from "ReadMe" document located [install directory]/SunSPOT/Demos/AirText
Author: Roger Meike
[4] Quoted from Code Description in [install directory]/SunSPOT/CodeSamples/RadioBroadcastSampleCode/src/org/sunspotworld/demo/BroadcastSample.java
Author: David Mercier
[5] Quoted from "ReadMe" document located [install directory]/SunSPOT/Demos/RadioStrength
Author: Ron Goldman