Lab 2: Application
Deployment and the SPOT Basestation
Now that we’ve played around with the application that comes on the SPOTs, let’s see how to put something else on there. Sun's “Quick Start Tutorial” makes use of the AirText demo to demonstrate deployment. We have chosen, however, to use a different demo, called Telemetry, for this purpose. You will learn not only how to build and deploy applications with Netbeans, but you will get to see an example where the basestation relays data from the free-range SPOTs to an application running on a PC. The Telemetry program receives data from a SPOT's accelerometer and reports it in a graph with some adjustable parameters.
1. Open, build, and deploy. Changing the current application on your Sun SPOTs couldn’t be much easier. First we will install the application for the free-range SPOT. Next, we will also build and run a normal Java program on the PC that reports sensor data returned from the SPOT. All you have to do is open a project, clean and build it, and deploy it on the SPOT.
a. Open. The project we are going to open and then put on the SPOTs next is called Telemetry-OnSPOT. To open this project, you can either click the link on the “Sun SPOTs info” tab (if you closed this already, it can be reopened by clicking the icon that looks like a SPOT on the toolbar just beneath the menus and about five icons from the left), or go to File->Open Project and at the open file dialog select the Telemetry-OnSPOT project folder from inside the TelemetryDemo folder which is in the Demos directory. If you get lost, the absolute directory (on Windows) should be C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-OnSPOT. Make sure you have the “open as main project” box checked.
b. Build. You’ll notice that Telemetry-OnSPOT now appears in the Project Explorer on the left-side of Netbeans. You can expand the project and view the source files that the application consists of in the Project Explorer if you’d like. Right click on the Telemetry-OnSPOT project (the root of the tree if you did any expanding) and select “Clean and Build Project.” This command can also be run from the “Build” menu or with shift+F11. You will notice that output from the build goes in the box that takes up approximately the lower fourth of the Netbeans window. The last line of output from the build should be “BUILD SUCCESSFUL” followed by how long the operation took.
c.
Deploy. Now that the application is built, it’s time
to put it on a SPOT! First make sure you
have a SPOT plugged into the USB cable and that the cable is connected to the
computer. Then, right click on the Telemetry-OnSPOT
project and select “Deploy to Sun SPOT.” After a few seconds and several lines of
output, the output should once again conclude with “BUILD
SUCCESSFUL.” If Netbeans appears to pause
in the middle of the deployment, tap the reset button on the SPOT you are
deploying to, and the operation should immediately continue. Your SPOT is now running the free-range
portion of the Telemetry demo. Note: When you first connect a SPOT to the
PC, Windows may bring up the “Found New Hardware” dialog. This is for the installation of the SunSPOT USB drivers.
You should be okay just clicking “next” several times until it finishes
(it doesn't matter what you select for the first choice) and then telling it to
“continue anyway” when it complains that the driver is not
windows-certified. You may have to do this
again later when Windows encounters a new SPOT it has not seen before.
2.
Set up the basestation. By now you
should have one SPOT successfully running the Telemetry-OnSPOT
application. You will see the left-most
LED lit up red, and the one next to it will flash yellow occasionally. Next, you need to get the basestation
set up so that when you run the OnDesktop Telemetry
application, it will be able to receive sensor data from the free-range SPOT
you just deployed onto. A very
convenient tool SPOT introduced with the latest stable release of the SPOT SDK,
Orange, is called the SPOT Manager and allows you to easily manage your SDK
installation and the state that your SPOTs are in without having to use the
command line. The file to open the SPOT
Manager should be on your desktop. Go to
your desktop and double-click on “SPOTManager.jnlp.” You should see a
Java program launch. If you haven't
already, plug the basestation
into the USB cable to connect it to the
PC. At the top of the “Sun SPOTs” tab of the SPOT Manager you will
see “Select a SPOT” and then a pull-down list that should display the IEEE
address of the your basestation. If you
don’t see anything in that box, hit “refresh.” Now we need to get your basestation running as a shared basestation,
which is the mode necessary to interface a PC Java Application with free-range
SPOTs. To do this, click on the basestation button
towards the bottom of the “Sun SPOTs” tab and select “start shared basestation.” You should see a second window pop-up with basestation output.
If everything went right, the last line of output you will see in this
new window is “[TraceRouteServer]starting.” This will stay open until you stop running a
shared basestation.
3.
Build and run the
OnDesktop project. It is time to build and run the desktop Java
application. By now, you should be able
to figure out how to do this. Open the Telemetry-OnDesktop
project, make sure it is set as your main project, right click on the project
and select “Clean and Build Project,” and, assuming that your build was
successful, right click on the project again and choose “Run Project.” A window should
appear that looks like a graph with some buttons and check-boxes at the
bottom. You will also notice that the
red light on your free-range SPOT is now green, indicating that it is talking
to the desktop application and will be the source of accelerometer data once
you tell it to “collect data.”
Congratulations! You have successfully deployed both parts of your first
SPOT/Desktop application.
4. Test the Telemetry demo. Now that you have the Telemetry demo on a SPOT and running on your PC, let’s see what it does. Hit the “collect data” button at the bottom of the desktop program and watch as the data from the SPOT's accelerometer is reported on the graph. Play with the Telemetry demo for a while if you like, trying different things and exploring the functionality provided. Pretty cool, huh?
Conclusion: After completing this section, you should know how to build and deploy projects to the SPOTs, as well as how to run standard PC Java applications in Netbeans, and how to start and stop a shared basestation. Hopefully by now are you excited about working with the Sun SPOTs and can't wait to start writing your own applications.
Questions:
1. At the end of the last lab, you considered SPOT applications that you think would be useful if developed. What new functionality for your preexisting ideas or entirely new applications can you think of that make use of a basestation and possibly include a PC program as well?