If you do not have a Sun SPOT (Figure 1), do not be bored, you can still have a lot of fun! In this entry, I gonna explain how to start programming the world using NetBeans 6.1!
sun_spot2.jpg
Figure 1: Sun SPOT rulez!!!

Downloading NetBeans IDE 6.1

1. Download NetBeans IDE 6.1 (RC1 launched today). A lot of new nice features, take a look in the New and Noteworthy and in the release pagefor a detailed list. 

Installing Sun SPOT plugin

2. Install Sun SPOT plugin into NetBeans. Downloadcom-sun-sunspot-updatecenter.nbm. Now, in NetBeans, go to: 2.1 Tools menu -> Plugin. 2.2 Click onDownloaded tab. 2.3 Click on Add Plugins button and select the file. Then, confirm the installation clicking on Install button and accept the license agreement. 2.4 Finally, go to theAvailable Plugins tab, mark SunSPOTApplicationTemplate, SunSPOTHostApplicationTemplate and Sun SPOT Info, click onInstall button and accept the license agreement.2.5 You can check that everything is installed going to Installed tab (Figure 2).
PS: David Simmons has blogged about these steps before.
netbeans_spot1.png Figure 2: Installed tab. 

Getting Sun SPOT SDK 3.0 Beta

3. Get the Sun SPOT SDK 3.0 Beta emailing David Simmons, more details here. You will receive a link to download SPOTManager tool, that is a jar that installs the SDK and can run the emulator. Be sure you have at least JDK 1.5 and at least Ant1.6.5 installed and configured in your system. 

Creating the Demo Application

4. Let's make the default demo application work. Go to: 4.1 File menu -> New Project 4.2 Select Java category, select Sun SPOT project and then click Next.4.3 Leave the default project name and package and click Finish. 4.4 Open org.sunspotworld.StartApplication.java. You can see it extends MIDlet and already has some code. If you are familiar with Java ME, you will not have big problems. But, basically, Sun SPOT arquitecture is CLDC (Connected Limited Device Profile) 1.1 and has IMP (Information Module Profile) in the top - which can be defined as a MIDP (Mobile Information Device Profile) without UI stuff. Also, it has some additional libraries and all this runs in a VM called Squawk, that is characterized by being most written in Java. So, StartApplication implements the abstract methods inherited from the MIDlet (startApp,pauseApp that Squawk never calls and destroyApp). It works in a sand box enviromnent.
The startApp code, in List 1, basically gets an object reference to the singleton eDemo Board and then make its LED blink red for a quarter of second each second. As you, can see, the code is pretty high level and easy to understand.
    protected void startApp() throws MIDletStateChangeException {
        System.out.println("Hello, world");
        new BootloaderListener().start();   // monitor the USB (if connected) and recognize commands from host

        long ourAddr = Spot.getInstance().getRadioPolicyManager().getIEEEAddress();
        System.out.println("Our radio address = " + IEEEAddress.toDottedHex(ourAddr));

        ISwitch sw1 = EDemoBoard.getInstance().getSwitches()[EDemoBoard.SW1];
        leds[0].setRGB(100,0,0);                // set color to moderate red
        while (sw1.isOpen()) {                  // done when switch is pressed
            leds[0].setOn();                    // Blink LED
            Utils.sleep(250);                   // wait 1/4 seconds
            leds[0].setOff();
            Utils.sleep(1000);                  // wait 1 second
        }
        notifyDestroyed();                      // cause the MIDlet to exit
    }
List 1: startApp code. 

Running the Demo Application in the emulator

5. Put this application to run in the emulator.5.1 Right click the project and selectBuild. It will generate the jar in the /$PROJECT_HOME/suite/. If you have a spot device, you could send it directly by right clicking the project and selecting Build Project + Deploy to Sun SPOT , forgetting the next steps.5.2 Open the emulator (in the ToolManager, go toSolarium tab and then click in the Solariumbutton). Then, in the emulator, click on the Emulator menu -> New virtual SPOT, you will notice that a Sun SPOT will appear in the squared right area. 5.3 Right click on the Sun SPOT picture, then click Specify application jar file... and select the application jar in /$PROJECT_HOME/suite/, which is the place that the application was built in step 5.1. 5.4 After that, click again on it, then Run MIDlet and StartApplication. Finally, you will see a red LED blinking!!! Wow!
netbeans_spot2.png
Figure 3: NetBeans 6.1, ToolManager, Emulator and the red LED blinking! 

Where I go next?

In NetBeans, check the Sun SPOT Info, that you have installed with the plugin, by clicking in the Window menu. David Simmons' Blog - http://blogs.sun.com/davidgsRoger Meike's Blog - http://blogs.sun.com/roger Sun SPOT Feeds (really nice aggregator with more cool blogs) - http://planets.sun.com/SunSPOT/group/SunSPOTProject Sun SPOT - https://www.sunspotworld.comOpen source Sun SPOT - https://spots.dev.java.net (take a look in its subprojects as well). Search for spaughts in youtube.com or subscribe the tag feed directly. Recently, Aaron Houston has organized a conference call about Sun SPOT with Roger Meike and published the nice links we get during it in an email he sent. The links are available here too. Slideshere.

PS: I am using this entry for the NetBeans IDE 6.1 Beta Blogging Contest, take a look at http://www.netbeans.org/competition/blog-contest.htmlfor more information about it. Go ahead, make an entry and have a chance to win $500! Good luck for us!
61blog-contest-logo.gif

Thanks! Have a nice weekend!
Program the world!
Bruno Ghisi