Java Solaris Communities Partners My Sun Sun Store United States Worldwide
»   Introduction
» Short Tour of a Sun SPOT
»   Ectoplasmic Bouncing Ball Demo
»   Loading and Running the Air Text Demo
»   Changing the Air Text Demo
 Basestation in Action (current page)
Sun SPOT Quick Start Tutorial

The Basestation in Action


Finally, we would like to show you the Sun SPOT basestation in communication with the free-range Sun SPOTs. Basestations can be used to deploy and debug code on free-range SPOTs.

To do over-the-air (OTA) communication between Sun SPOTs, you need to know the IEEE extended MAC address of the SPOTs. The IEEE extended MAC address is a 64-bit address, expressed as four sets of four-digit hexadecimal numbers: nnnn.nnnn.nnnn.nnnn. The first eight digits will always be 0014.4F01. The last eight digits should be printed on a sticker visible through the translucent plastic on the radio antenna fin. A typical sticker would say something like 0000.01AE and that would imply an IEEE address for that SPOT of 0014.4F01.0000.00AE. You can also get the IEEE address for a SPOT using an ant command explained below. We suggest you make a list with the IEEE address for each of your Sun SPOTs.

Let's begin by doing an over-the-air deployment of an application to a free-range SPOT. When we finished the Air Text demo, the basestation was not attached to anything. Please attach the basestation SPOT to the USB cable on your host workstation..

We need to make sure that the basestation is acting as a basestation, that is, it is running the program that forwards communication from the host workstation to the free-range SPOTs rather than running an application program. To test this,

    1. Open a command line window. Under Windows, this is usually available from Start > All Programs > Accessories > Command Prompt. Any Linux or Macintosh command line window will also do.
    2. In the command line window, navigate to the directory:
    3. Execute the command:
      ant slots

The system will display something which ends like this:
[java] [waiting for reset] ** VM stopped: exit code = 0 **
[java] [waiting for reset]

[java] Sun SPOT bootloader (1159-20060804)
[java] SPOT serial number = 0014.4F01.0000.00AE
[java] 0: C:\Program Files\Sun\SunSPOT\Demos\BounceDemo\BounceDemo-OnSPOT/s
uite/image (Mon Aug 21 10:56:56 PDT 2006) (28632 bytes) at 0x10140000
[java] 1: C:\Program Files\Sun\SunSPOT\Demos\BounceDemo\BounceDemo-OnSPOT/s
uite/image (Mon Aug 21 11:18:15 PDT 2006) (28632 bytes) at 0x101a0000 (current)
[java] OTA Command Server is disabled
[java] Ignoring application suite at startup
[java] Exiting
[delete] Deleting: C:\Program Files\Sun\SunSPOT\sdk\temp\spot-temp-143556030

The line that says "Ignoring application suite at startup" is your indication that the basestation SPOT is running in basestation mode. If the basestation SPOT was not in basestation mode, that section of the output would have said "Not ignoring application suite at startup". Notice also that, the output lists the IEEE address for the Sun SPOT in the line starting with "SPOT serial number".

The basestation SPOT was shipped in a state such that it will automatically go into basestation mode when it it plugged into an USB port. However, if your Sun SPOT basestation is not operating in basestation mode, execute the command:
ant selectbasestation run
in the command line window and it will go into basestation mode. When it starts in basestation mode, a series of lines to the command line window, ending with the words "Starting basestation..." You will need to control-C to terminate the ant script at that point and regain control of the command line window.

You still have a command line window open with your current directory set to
You are in the right project directory. To deploy the Bounce demo to the free-range SPOT over the air, execute the command:
ant -DremoteId=nnnn.nnnn.nnnn.nnnn deploy
where nnnn.nnnn.nnnn.nnnn is the IEEE address of the SPOT that has the AirText demo installed on it. Note carefully the case of the ant command options. Ant commands are case-sensitive. The command will not work if you have typed "-DremoteID" or "-DRemoteId" or "-dRemoteId". It must be "-DremoteId".

    The output from the command should end with something that looks like this:
    [java] My IEEE address is 0000.0000.0000.0001
    [java] Waiting for target to synchronise...
    [java] (please wait for remote SPOT 0014.4F01.0000.0106 to respond)
    [java] (if no response ensure SPOT is running OTACommandServer)

    [java] Remote Monitor (1159-20060804)
    [java] SPOT serial number = 0014.4F01.0000.0106
    [java] About to flash to slot 1
    [java] Writing imageapp58742.bintemp(27784 bytes) to remote Spot
    [java] ................................................................
    [java] ................................................................
    [java] ................................................................
    [java] ................................................................
    [java] ..................................

    [java] Writing Configuration(1080 bytes) to remote Spot
    [java] ............

    [java] Exiting
    [delete] Deleting: C:\Program Files\Sun\SunSPOT\sdk\temp\spot-temp-795716485




    Total time: 35 seconds

You have just reloaded the Bounce demo onto the target free-range SPOT.

Troubleshooting: If the deploy fails with a timeout error and/or a "BUILD FAILED" message, try resetting the free-range SPOT. If another attempt fails, then most likely the free-range SPOT does not have Over The Air (OTA) deployment enabled. To enable OTA deployment, unplug the basestation SPOT from the USB cable, connect the free-range SPOT to the USB cable and execute an "ant enableota" command. Then type "ant slots". The output says, among other things, "OTA Command Server is enabled". That indicates that you have enabled over the air deployment on that Sun SPOT. Disconnect the free-range SPOT from the USB cable and reconnect the basestation. Try the "ant -DremoteId=nnnn.nnnn.nnnn.nnnn deploy" command again. It should work now.

To run the Bounce demo, execute the command:
ant -DremoteId=nnnn.nnnn.nnnn.nnnn run
where nnnn.nnnn.nnnn.nnnn is the IEEE address of the target Sun SPOT.

    The output from that command will end with something that looks like this:

    [java] My IEEE address is 0000.0000.0000.0001
    [java] Waiting for target to synchronise...
    [java] (please wait for remote SPOT 0014.4F01.0000.0106 to respond)
    [java] (if no response ensure SPOT is running OTACommandServer)

    [java] Remote Monitor (1159-20060804)
    [java] SPOT serial number = 0014.4F01.0000.0106

    [java] Exiting
    [delete] Deleting: C:\Program Files\Sun\SunSPOT\sdk\temp\spot-temp-1133367407

    Total time: 19 second

You should now have two free-range Sun SPOTs with the Bounce demo loaded and running on them.

Now we can start the Ectoplasmic Bouncing Ball demo again, but this time we will a simulated Sun SPOT running on the host workstation and communicating with the free-range Sun SPOTs via the basestation's radio.

Select "File" from the NetBeans main menu bar and "Open Project" from the menu.

When the file selection box displays, navigate to the demo directory in the Sun SPOT SDK directory. Within that directory, select BounceDemo and then BounceDemo-OnDesktop.


After the project has been opened, select "Run" from the menu bar and then "Run Main Project" from that menu:

A window will open on the host workstation with the simulated Sun SPOT in it:

Grab the simulated SPOT with your workstation mouse and drag it to the left and right to tilt it. The simulation communicates with the other Sun SPOTs through the radio on the basestation Sun SPOT. Turn on or reset the free-range Sun SPOTs. See if you can get all three of the SPOTs - the two free-range SPOTs and the one simulated SPOT - all exchanging ectoplasmic balls. See if you can merge all three balls into one white ball.

When you have all three balls merged into one white ball, passing back and forth between the free-range Sun SPOTs and the simulated Sun SPOT, you have completed the welcome tutorial for Sun SPOT programming. Congratulations!

Undoubtedly, you now want to figure out how to implement your own application on a Sun SPOT.

A good place to start is with the code for the BuiltInSensorsDemo. It is in the <SunSPOTdirectory>/Demos directory. It contains all of the Java import statements which you will need and it illustrates how to instantiate and use all of the sensors on the demo sensor board. Many of the common usage patterns are illustrated there in a form that will make it easy fpr you to cut and paste the code to your application. If you want to learn more about using the radio, look at the RadioStrength demo.

You should also look in the <SunSPOTdirectory>/Demos/CodeSamples directory. This directory has a number of demonstration applications that each go into detail on a a single type of sensor or device. One of these demonstrates use of the GPIO pins - the pads available for external device I/O on the surface of the sensor board.

Use of the sensors is also described, briefly, in the Sun SPOT Owner's Manual. Finally, the software environment and structure for the Sun SPOT is described in the Sun SPOT Developer's Guide. It is a crucial resource for the Sun SPOT developer. Both are in the <SunSPOTdirectory>/sdk/doc directory.

Back to top