Summary of the content on the page No. 1 
                    
                         
 
 
 
 
 
Sun™ Small Programmable Object Technology (Sun SPOT) 
Developers’ Guide 
This version of the Guide refers to V2.0 
(updated 16-April-2007) 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.                                                                                                                                                                                                                                                           
                    
                    Summary of the content on the page No. 2 
                    
                        Copyright © 2007 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.    Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document.  In particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed at  http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S. an
                    
                    Summary of the content on the page No. 3 
                    
                        Contents  Introduction .................................................................................................................................... 5  Building and deploying Sun SPOT applications .............................................................................. 6  Deploying and running a sample application................................................................................................ 6  Deploying a pre-existing jar............................................
                    
                    Summary of the content on the page No. 4 
                    
                        Writing a device driver............................................................................................................................................ 40  http protocol support ................................................................................................................................... 41  Configuring the http protocol.................................................................................................................................. 41  Socket Pro
                    
                    Summary of the content on the page No. 5 
                    
                        Introduction  The purpose of this guide is to aid developers of applications for Sun SPOTs. The guide is divided  into two sections.    Building and deploying Sun SPOT applications provides information about how to build, deploy  and execute Sun SPOT applications. The topics covered include:    • Building and deploying simple applications  • Deploying applications you’ve received as jars from other developers  • Including properties and external resources through the manifest  • Setting up a bas
                    
                    Summary of the content on the page No. 6 
                    
                        Building and deploying Sun SPOT applications  Deploying and running a sample application  The normal process for creating and running an application (assuming you are working from the  command line rather than an IDE) is:    • Create a directory to hold your application.  • Write your Java code.  • Use the supplied ant script to compile the Java and bind the resulting class files into a  deployable unit.  • Use the ant script to deploy and run your application.    In this section we will describ
                    
                    Summary of the content on the page No. 7 
                    
                           [delete] Deleting directory C:\MyApplication\build     [delete] Deleting directory C:\MyApplication\suite     [delete] Deleting directory C:\MyApplication\j2meclasses    -post-clean:    clean:    -pre-compile:    -do-compile:      [mkdir] Created dir: C:\MyApplication\build      [javac] Compiling 1 source file to C:\MyApplication\build    -post-compile:    compile:    -pre-preverify:    -make-preverify-directory:      [mkdir] Created dir: C:\MyApplication\j2meclasses    -unjar-utility-jars:  
                    
                    Summary of the content on the page No. 8 
                    
                          -post-init:    init:    -override-warning-find-spots:    -main-find-spots:       [echo] Using Sun SPOT device on port COM45    -do-find-spots:    slots:    -run-spotclient-with-optional-remoteId:    -run-spotclient-with-script-contents:    -run-spotclient:       [java] Waiting for target to synchronise...       [java] (please reset SPOT if you don't get a prompt)       [java] [waiting for reset]         [java] Sun SPOT bootloader (1514-20060824)       [java] SPOT serial number = 0014.4F01.0000
                    
                    Summary of the content on the page No. 9 
                    
                        or    ant –Dport=COM2 info    The difference between these two commands is that the “spotport” version will check that there  is a Sun SPOT connected to the specified port, whereas the “port” version will attempt to  connect to a Sun SPOT on the specified port regardless. You should normally use the  “spotport” version. If you prefer, you may specify the port in the build.properties file of the  application:    spotport=COM2    or    port=COM2    On Unix-based systems, including Mac OS X, if you
                    
                    Summary of the content on the page No. 10 
                    
                             [exec] [Adding property key: MIDlet-Vendor value: Sun Microsystems Inc]       [exec] [Adding property key: MIDlet-1 value: Spottests,,  squawk.application.Startup]       [exec] [Adding property key: MIDlet-2 value: TestMIDlet label,,  com.sun.spot.TestIMlet]       [exec] [Adding property key: MicroEdition-Profile value: IMP-1.0]       [exec] [Adding property key: MicroEdition-Configuration value: CLDC-1.1]       [exec] [Including resource: res1.txt]       [exec] Created suite and wrote it i
                    
                    Summary of the content on the page No. 11 
                    
                          -do-init:    -post-init:    init:    environment:         [java] To configure the environment for Squawk, try the following command:         [java]     set JVMDLL=C:\jdk1.5.0_06\jre\bin\client\jvm.dll      BUILD SUCCESSFUL  Total time: 0 seconds  C:\MyApplication>    6. Run the application.  To run the application, use the “ant run” command.    C:\MyApplication>ant run  Buildfile: build.xml    -pre-init:    -init-user:    -init-system:    -do-init:    -post-init:    init:    -override-warning-
                    
                    Summary of the content on the page No. 12 
                    
                                 [java] --------------------------------------------------------------------       [java] Hits   -   Class:95.74%  Monitor:92.38%  Exit:100.00%  New:98.43%       [java] GCs: 2 full, 0 partial       [java] ** VM stopped: exit code = 0 **           [java] Exiting     [delete] Deleting: C:\SunSPOT\dev\temp\spot-temp-674916937    -post-run:    run:    BUILD SUCCESSFUL  Total time: 10 seconds  C:\MyApplication>    As you can see, this application just prints “Hello world!” However, it gives y
                    
                    Summary of the content on the page No. 13 
                    
                        Excluding files from the compilation  To exclude files or folders matching a specific pattern from the java compilation, set the ant  property spot.javac.exclude.src, either on the command line with –D or in the build.properties  file of the project. The value of the property should be specified using standard ant wildcarding.    For example, to exclude all source files in all “unittests” folders, use:    spot.javac.exclude.src=**/unittests/*  Manifest and resources  The file MANIFEST.MF in the 
                    
                    Summary of the content on the page No. 14 
                    
                          resources/META-INF/MANIFEST.MF    extension a within its root folder. The adderlib has such  file, whose content is     FavouriteSnake: Viper    This defines a property whose value will be available to all applications in a similar fashion to  application-specific manifest properties. The addertest application demonstrates this by displaying  the value of this property. The library suite is built to contain all the properties defined by the  manifests of all its input jars. For more details on
                    
                    Summary of the content on the page No. 15 
                    
                        Sun SPOT Sun SPOT Host (“base station”) (“Target”) USB 802.15.4 radio   The Host can be any of the supported platforms (e.g. Windows PC, Mac). The Host application is a  J2SE program. The Target application is a Squawk Java program.    In the SPOT SDK and documentation the 64-bit addresses that identify SPOTs are expressed as  sixteen hexadecimal digits subdivided into four groups that are separated by dots for readability.    The Basestation may run in either dedicated or shared mode. In dedica
                    
                    Summary of the content on the page No. 16 
                    
                        Base Station configuration  It is possible to select a channel and pan id for the base station using command line properties in  conjunction with ant host-run. The properties are:    -Dremote.channel=nn  -Dremote.pan.id=nn    Alternatively, if you are operating in dedicated mode, the IRadioPolicyManager interface provides  operations to adjust the output power of the radio, the PAN Id and the channel number. To access  the policy manager from your host program do:    Spot.getInstance().getRadioP
                    
                    Summary of the content on the page No. 17 
                    
                          To configure the SPOT so that this thread is started each time the SPOT starts issue this command  via a USB connection:    ant enableota    The SPOT remembers this setting in its configuration area in flash memory.    To configure the SPOT so that the OTA Command Server is not started each time the SPOT starts  issue this command:    ant disableota    Although the OTA Command Server thread runs at maximum Thread priority, parts of the radio  stack run at normal priority. This means that if an
                    
                    Summary of the content on the page No. 18 
                    
                        remote.pan.id either on the command line or in the .sunspot.properties file in your user root  folder.  Using short names for SPOTs  As a shortcut, it is possible to use short names for SPOTs instead of  the full 16-digit IEEE address.  To do this create a file called “spot.names” in your user home directory. The file should contain  entries of the form:    =    for example    my-spot-1=0014.4F01.0000.0006    Note that these short names are used for all connections open
                    
                    Summary of the content on the page No. 19 
                    
                        Even if you aren’t concerned about security, you need to be aware of this if you want to be able to  use Sun SPOTs interchangeably amongst two or more SDK installations. See the section Sharing  Sun SPOTs.   Changing the owner of a Sun SPOT  Once set, only the owner can change the public key remotely, although anyone who has physical  access to the Sun SPOT can also change the public key. If user B wishes to use a Sun SPOT device  previously owned by user A, they can become the new owner in one 
                    
                    Summary of the content on the page No. 20 
                    
                        ant deploy    for each Sun SPOT.  What is protected?  Applications and customized libraries are always verified and unless the digital signature can be  successfully verified using the trusted public key, the application will not be executed. Extra  security is provided for over-the-air deployment. In this case, all updates to the configuration page  are verified before the page is updated. This prevents a number of possible attacks, for example a  change to the trusted public key, or a denial o