Java Solaris Communities Partners My Sun Sun Store United States Worldwide
»   Welcome and 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
»   Send-Data and HTTP Demos
 

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 Sun SPOTs.

To do over-the-air (OTA) communication between Sun SPOTs, you need to know the IEEE extended MAC address of the Sun 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 Sun SPOT of 0014.4F01.0000.01AE. You can also get the IEEE address for a Sun 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 Sun 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 Sun SPOTs rather than running an application program.

There are at least two ways you can do this. One is to watch the activity LED on the basestation. If it gives two green flashes every 10 seconds, it is in basestation mode.

You may also use an ant command to see if the Sun SPOT is configured as a basestation. To do 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:
      [SunSPOTdirectory]/Demos/BounceDemo/BounceDemo-OnSPOT
    3. Execute the command:
      ant info

The system will display something like this:

-run-spotclient-once:

[java] SPOT Client starting...
[java] (please reset SPOT 0014.4F01.0000.2359 on port /dev/cu.usbmodem1d11)
[java] [waiting for reset]
[java] [waiting for reset]
[java] [waiting for reset] ** VM stopped: exit code = 0 **
[java] [waiting for reset]
[java]
[java] Sun SPOT bootloader (yellow-100901)
[java] SPOT serial number = 0014.4F01.0000.2359
[java]
[java] Startup configuration:
[java] OTA Command Server is disabled
[java] Configured as a Basestation
[java]
[java] Squawk command line:
[java] -spotsuite://library
[java] -Xboot:268763136
[java] -Xmxnvm:0
[java] -isolateinit:com.sun.spot.peripheral.Spot
[java] -dma:1024
[java] -Dspot.start.manifest.daemons=false
[java] com.sun.spot.peripheral.basestation.BaseStation
[java]
[java] Library suite:
[java] hash=0xfb1718
[java] Installed library matches current SDK library
[java] Installed library matches shipped SDK library
[java] Current SDK library matches shipped SDK library
[java]
[java] Security:
[java] Owner key on device matches key on host
[java]
[java] Configuration properties:
[java] spot.hardware.rev: 8
[java] spot.powercontroller.firmware.version: PCTRL-2.06
[java] spot.sdk.version: yellow-100901
[java]
[java] Exiting

-run-spotclient-multiple-times-locally:

-run-spotclient:

BUILD SUCCESSFUL

In the section titled "Startup configuration" there is a line that says "Configured as a basestation." that 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 "Configured to run the built-in IsolateManager".

Also notice that the line above "Configured as a basestation" says "OTA Command server disabled." This is equally important. The OTA command server should be running only on the free-range Sun SPOTs. If it is running on the basestation, the over-the-air deployments will not work. To disable the OTA command server on the basestation, use the command "ant disableota".

Finally, notice that the output lists the IEEE address for the Sun SPOT in the line starting with "SPOT serial number". Ironically, running ant info stops the basestation program from running. Press the control button to reset the basestation and restart the basestation program.

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, you can execute the command:

ant startbasestation

in the command line window and your basestation will go into basestation mode. It will print a series of lines to the command line window, ending with the words "Starting basestation..."

You should still have a command line window open with your current directory set to

[SunSPOTdirectory]/Demos/BounceDemo/BounceDemo-OnSPOT

You are in the right project directory. To deploy the Bounce demo to the free-range Sun 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 Sun 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:

-run-spotclient-once:

[java] Sun SPOT Client starting...
[java] Waiting for target to synchronise...
[java] (please wait for remote Sun SPOT 0014.4F01.0000.0106 to respond)
[java] (if no response ensure Sun SPOT is running OTACommandServer)
[java]
[java] Remote Monitor (yellow-100901)
[java] Sun SPOT serial number = 0014.4F01.0000.0106
[java] About to flash to C:\Program Files\Sun\SunSPOT\Demos\BounceDemo\BounceDemo-OnSPOT/suite/image
[java] Writing imageapp3539.bintemp(25323 bytes) to remote Sun SPOT 0014.4F01.0000.0106
[java] |========= | 19%
[java] |===================== | 39%
[java] |================================= | 59%
[java] |============================================= | 79%
[java] |========================================================= | 98%
[java] |============================================================| 100%
[java]
[java] Exiting

-run-spotclient-multiple-times-with-remote-id:

-run-spotclient-once-locally:

-run-spotclient-multiple-times-locally:

-run-spotclient:

-post-deploy:

jar-deploy:

deploy:

BUILD SUCCESSFUL
Total time: 25 seconds

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

Troubleshooting: If the deploy fails with a timeout error and/or a "BUILD FAILED" message, try resetting the free-range Sun SPOT. If another attempt fails, then most likely the free-range Sun 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 Sun SPOT to the USB cable and execute an "ant enableota" command. Then type "ant info". 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 Sun SPOT from the USB cable and reconnect the basestation. Try the "ant -DremoteId=nnnn.nnnn.nnnn.nnnn deploy" command again. It should work now.

The Bounce demo is now loaded on that Sun SPOT again. You can start the application one of two ways. If you don't need to see the console output from the application, you can start the application by pressing on the control button and resetting the Sun SPOT. If you want to see the console output from the application, you can use the command window and 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:

-run-spotclient-once:
[java] Sun SPOT Client starting...
[java] Waiting for target to synchronise...
[java] (please wait for remote Sun SPOT 0014.4F01.0000.0106 to respond)
[java] (if no response ensure Sun SPOT is running OTACommandServer)
[java]
[java] Remote Monitor (yellow-100901)
[java] Sun SPOT serial number = 0014.4F01.0000.0106

And the application will start and the output will be directed to the command window. If you start the application this way and are not interested in the output, you can Control-C to terminate the ant command. The application will continue to run on the Sun SPOT.

Please start up the Bounce demo on the Sun SPOT in one of these ways. 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 add 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.

A NetBeans screenshot. The File item has been chosen from the menu bar.  From the drop-down menu, the item 'Open Project' is being selected.

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.

The Netbeans Open Project dialog box is shown.  The directory displayed is the 'BounceDemo' directory.  Two projects are displayes within that directory: 'BounceDemo-OnDesktop' and 'BounceDemo-OnSPOT'.  The BounceDemo-OnDesktop is selected.

 

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

A NetBeans screenshot.  The active project is BounceDemo-onDesktop.  The mouse cursor has selected the Run item from the menu bar and is positioned over the drop-down menu item 'Run main project.'

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

A windows application window is show.  The title is 'An Extra Sun SPOT (Simulated).'  The main body of the window is gray with an image of a Sun SPOT shown slightly off center and slightly tilted to the right.  The rightmost LED has a pastel star over it to indicate that that the simulated LED is lit.

Grab the simulated Sun 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 Sun SPOTs - the two free-range Sun SPOTs and the one simulated Sun 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.


Next: Send-Data and HTTP Demos