Lab session 1: Introduction to the Java-programmable Sun SPOT technology. The point of the lab today is to get you familiar with the basics and layout of the Sun SPOTs and hopefully get you excited about working with them. This will give you a glimpse at some of the fun, cool things that can be done with them. Introduction The goal of this lab is to introduce you to Sun’s new Sun SPOT (which stands for Small Programmable Object Technology) wireless sensor network technology. Unlike most motes that run TinyOS and require applications to be written in NesC, Sun’s new motes are programmed in Java. For people with experience in Java, learning to program applications for the Sun SPOTs should be relatively easy. Sun makes use of familiar techniques in the design of the SPOT API ; communication between motes, for example, should be reasonably intuitive for anyone that has used sockets before. The Sun SPOT software comes with a number of fun example applications that show off some of what the motes are capable of. We will explore a couple of these, learning how to deploy applications on the SPOTs as we go, and ultimately start looking at the code to see how the programs work. Let’s get started. We will install all the software that we need for dealing with Sun SPOTs in the future. 1 Install everything that is needed . You need to install Java (jdk), Netbeans and Apache Ant. All these applications are publicly available for downloading, both under Linux and Windows. Apache Ant is a software tool for automating software build processes. It is similar to the Unix application 'make' but it is implemented using the Java language, requires the Java platform, and is best suited to building Java projects. The most noticeable difference between Ant and make is that Ant uses XML to describe the build process and its dependencies, whereas make has its Makefile format. By default the XML file is named build.xml. The easiest way to install everything that you need is through the Sun SPOT Manager, to be found at http://www.sunspotworld.com/SPOTManager . Moreover, the Sun SPOT Manager will allow you to update your spots in the future with the newest firmware versions, and also to access documentation and a Sun SPOT emulator. NOTE: do not forget to add the path of the new installed applications to your system's environment variables. 2 Check your equipment. You should have been provided with a Sun SPOT development kit. This includes two motes and a basestation. You can tell the basestation apart from the free-range SPOTs by the fact that it does not have a detachable semi-transparent plastic cover on top and is not as tall off the table. You will also need at least one USB cable to hook your SPOTs up to the computer. 3 Open Netbeans. Sun has made programming and deploying applications to the SPOTs extremely simple by incorporating the functionality into Netbeans, the Integrated Development Environment (IDE) that Sun offers with their free version of the Java Development Kit (jdk). The Netbeans modules that allow for this come with the SunSPOT sdk. In this lab, we will be learning how to work with the SPOTs through Netbeans. You may already have another favorite IDE of your own, or even already dislike Netbeans for whatever reason, however we will make use of it in these labs to take advantage of the ease of developing and deploying SunSPOT applications that it provides. 4 “Short tour of a Sun SPOT”. When you first open Netbeans, you should see a tab open called “SunSPOTs info”, with a heading that reads: “Welcome to the World of Sun Small Programmable Object Technology - Sun SPOTs.” A little farther down the page, you will see a link to the 'Sun SPOT Quick Start Tutorial'. Click this. From there click on either the link at the end of the introduction or on the sidebar to the “short tour of a Sun SPOT.” Quickly read over this page. This will get your familiar with the basics of the SPOTs. Try taking the lids off and locating the switches next to the LED’s (under the lid) and the control (power) button. The tour will teach you about turning a SPOT on, how to reset a SPOT, and how to interpret the power/activity LED. The same documentation can be found within the Sun SPOT Manager, in which case you do not need to do the 3rd and 4th steep above. Instead, open the manager application and go to the 'Tutorial' tab. Additionally, the manager offers more information (like the installation instructions, the developers' guide or the emulator manual) under the tab 'Docs'. Deploying applications: The Telemetry Demo. As the Sun's “Quick Start Tutorial”, at the end of the previous lab session we used 'AirText' demo to show how to deploy programs into the Sun SPOTs. To confirm how deployments are done, let us use today a different demo, called 'Telemetry'. We will recall how to build and deploy applications with Netbeans, and we 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. Let’s get started. 5 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 freerange 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 TelemetryOnSPOT project folder from inside the TelemetryDemo folder which is in the Demos directory (now under the sdk directory of installation). 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 under Windows, it 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. 6 Setup 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. The basestation needs to run as a shared basestation, which is the mode necessary to interface a PC Java Application with free-range SPOTs. The basestation of the kits we delivered to you are already configured to run as such. If you need to configure them again, use the SPOT Manager application. 7 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. 8 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. Deploying another application: The Ectoplasmic Bouncing Ball Demo The SPOTs come preloaded with a demo that utilizes the on-board three-axis accelerometer, one of a number of sensors that the free-range SPOTs are equipped with, and the eight tri-color LED’s under the lid. This demo is also covered in the next section of the Quick Start Tutorial. You are welcome to refer the tutorial in addition to —or instead of—the steps below (if anything is unclear, the tutorial has pictures). Since the Sun SPOTs we use in our lab are updated with the newest firmware version, this demo is not preloaded in them anymore. To play with it, we need to deploy it into the spots: 1 Plug the SPOT into your computer with the USB cable. Turn it on if it does not switch on automatically after being plugged. 2 Open Netbeans and open the project named 'BounceDemo-OnSPOT', to be chosen from the demos included at the SDK (Java) installation. 3 Once loaded, click on the right mouse button when having the name of the project selected. Several options to manage the project are then shown. Build the project and deploy it to the Sun SPOT. If you have more than one spot connected, the program will ask you to which spot to deploy. Once the demo project is built and deployed, you can already run it. This can be done by selecting the 'Run' option from the project, or by switching off and on again the spot. If your SPOT doesn’t respond and refuses to power-up, it may not be charged. In this case use the USB cable to plug it into the computer and charge it, but it may take a minute or two before it will have enough power for the demo to run. 1 When the SPOT is on, the two lights on the ends will be red, and there will be a blue (or green) light somewhere that acts like a bouncing ball if you tilt or shake the mote back and forth. 2 Play with the bouncing ball. Take a moment to get a feel for the bouncing ball application. Shake the SPOT furiously to get the ball bouncing between the two ends at lightning speed and then hold it still and watch the ball gradually lose speed and settle back down to a final resting place. When the ball is on one end, try tilting the mote gradually just until the ball falls and watch it bounce back a few times (most likely ending up on the other end; though sometimes if you just barely tilt it, the ball will go back to where it started). Try to get the ball to stop in the very middle (without spending too much time trying). Once you’ve had enough fun, go on to the next step. 3 Introduce the second SPOT. If you haven’t already, start up the second freerange SPOT, which should also have the bouncing ball application running. This time you will see a ball that is green. Now turn both motes off (hold the control button for a couple seconds; if you just press it without holding, it will reset and not shut down) and then turn the one that previously had the green ball back on again. Notice that it will now have a blue ball. This means that the SPOTs, true to the spirit of wireless sensor networks, are aware of each others’ presence. We will investigate this further when we look at the code later. NOTE: if you are doing this lab in close proximity to other groups, the colors may not match what is described here since all the motes will be communicating and trying to assign themselves a unique color at startup. There is a maximum of three motes (and thus three unique colors) per self-assigning group, though. 4 Break down the walls. Make sure both your motes are on. Now go ahead and take both the lids off. If you were wondering earlier what the control switches do, the answer is: it depends on what the application developer wants them to. It just so happens that the developers at Sun were nice enough to make bouncing ball demo even cooler by letting us use the control switches to share multiple balls in one arena that spans more than one SPOT. If that wording is confusing to you, try it yourself and see what happens. a Press one of the control switches. The red light on that end of the mote will start to blink. While that light is still blinking, press a switch on another mote. The two “walls” should disappear. Now you can have both balls going back and forth between SPOTs! Unless you’re really good, the balls will probably quickly combine into one. You can even put the walls back up and isolate both balls on one mote, or take all the walls out altogether. b Play with this for a while, taking walls down and passing balls back and forth between multiple motes. Important related documents Documentation concerning Sun SPOTs can be accessed at the website and forums suppoprted by Sun, being the main one at http://www.sunspotworld.com/docs/ (currently, we have the Red Release). Specially useful are the following manuals: • The owners manual (www.sunspotworld.com/docs/Red/SunSPOTOwnersManual.pdf), that describes the Sun SPOT devices in detail. It documents, more or less, the same contents that we have explained in the classroom. • The manual www.sunspotworld.com/docs/Red/SunSPOT-TheoryOfOperation.pdf , that describes the electro-technical details of the Sun SPOT devices. This manual is only useful for us in case of need to consult some very low-level detail like, for example, when programming the eDemo board for connecting with other devices. • The guide (www.sunspotworld.com/docs/Red/spot-developers-guide.pdf), that focuses on how to programming them. This will be useful for the forthcoming lab lessons. Exercises 1 Can you already imagine some fun, useful, or interesting applications that you would like to see made to run on the SunSPOTs? Describe them shortly. 2 Using Netbeans, have a look at the source code of the bouncing ball demo. Try to get the flavour of how a program running on Sun SPOTs look like and which Java packages seem to be useful. 3 Using Netbeans, open another demo called 'AirText' which is also provided within the Java distribution you installed. Build it, deploy it and run it in the Sun SPOTs. Have a look at the source code and study the components of this project. 4 Make a copy of this project. Edit its source code and manipulate it in order to modify the message that is displayed on the air when shaking the spots. You must achieve to run your modification on the Sun SPOTs.
© Copyright 2026 Paperzz