Pacific Connection(英語)

Embedded Computing for the Rest of us: Project Sun SPOT

With just 850 students, Warren Wilson College in North Carolina is not awash in inter-departmental resources. So when Professor David Abernathy won a $100,000 grant to develop a geographic information system and wireless sensor network for the Cocobolo Nature Reserve in Panama, he needed some embedded programming expertise not likely to be found on campus.

Wireless sensors are ideal for studying changes in microclimates over time. As opposed to humans, sensors leave no footprints and break no branches, and can record conditions every 20 minutes around the clock. If you are a researcher interested in remote sensing, there are plenty of resources, including the University of California, Los Angeles’s Center for Embedded Network Sensing, which has more than $40 million in funding with graduate students coming from across the state. Abernathy admires the Center’s work, but given his limited grant, small department, and lack of graduate students, he needed something more off-the-shelf.

“When I got intrigued by the geographic possibilities of wireless sensor networks, I quickly got discouraged because I saw how difficult it would be to do what we want to do,⁠⁠ Abernathy says. The college had one computer science professor, who taught Java, which is not exactly known as an embedded language. But as it would turn out, Java was the precisely the language used for an open source sensor project developed by Sun Microsystems Laboratories known as Project Sun SPOT, or Sun Small Programmable Object Technology.

Project Sun SPOT was conceived as an experimental mobile platform for Java, a place where the language might prove useful beyond the mobile phone. Introduced by Sun Labs in 2006, Sun SPOTs have become (to borrow Apple’s phrase) the ⁠embedded system for the rest of us.⁠⁠ For $750 or \76,500 (with education discounts available), you can buy a Sun SPOT Java Development Kit, which includes two Sun SPOT devices, each of which includes a 180MHz 32-bit ARM920T core processor with 512K RAM and 4M Flash, 2.4GHz radio with an integrated antenna, a sensor board with a 3-axis accelerometer plus temperature and light sensors. You also get a base station?consisting of the processor board and radio?which connects to a PC. All of this hardware is off-the-shelf. Sun Labs⁠⁠ main contribution is an entirely new Java implementation built with embedded programming in mind. Sun Labs says the Java virtual machine was developed ⁠to the metal,⁠⁠ meaning that it has no operating system, per se, but includes some OS functions.

Sun SPOT applications have ranged all over the place, including a remote controlled ⁠spider-bot,⁠⁠ embedded Sun SPOTs in model rockets and race cars, and Mike’s Flying Bike?which is a mountain bike mounted for indoor exercise which controls Google Earth in flight simulator mode. Scientific applications include Abernathy’s rain forest monitoring project and a comparable one that Sun Labs has volunteered to develop for monitoring the conversion of commercial salt ponds into marsh in the San Francisco Bay. (Some of these apps can be seen on YouTube by searching under ⁠spaught.⁠)

On the Cocobolo project, Abernathy, who only ⁠dabbles⁠⁠ in Java, found help from two students who were already working for him as part of their work/study project. One of them, Chris Fusting, had programmed in C, C++, and Perl while in high school. Java is close enough to C that Fusting was able to understand the Sun SPOT code examples and alter them for the project. ⁠We began by interfacing to the onboard sensors in order to grab the data,⁠⁠ he says. ⁠We then stuff the data into a packet and send it to our host IP address, put in a sleep command for some short interval, and then loop back and do it again.⁠⁠ The device-to-device network hops that bring data in from the outer Sun SPOTS proved more problematic: after more than a couple of hops, the data wasn’t arriving. ⁠The Sun SPOT API has a couple of protocols for radio communications: radiogram and radiostream,⁠⁠ Fusting says. ⁠With radiogram, you pretty much send off the packet and hope it gets there, whereas radiostream is more ⁠TCP-ish⁠?you write to a stream and get confirmation that the data has gotten to the other end. We found that streams gave us a much more reliable transmission.⁠⁠ Fusting also wrote a small program that lights the LEDs when two Sun SPOTS are talking to each other, and spent a night placing the devices at various distances while watching for the blue glow. In a pasture adjacent to the rain forests, the team got the specified 100 meter transmission. In partial rain forests with clearings, the distance was about 20 meters. ⁠Here’s where the power of the Sun SPOT platform came in: with just four lines of Java code, you can to send all this data to the MySQL database, which we did via satellite.⁠

To get the data from the database to Google Earth, Fusting wrote some PHP code to generate KLM files, thereby creating a Google Earth mash-up. ⁠While we were set up in the rain forest, you could click on a link that would open up Google Earth, zooming in over Panama where we had hard coded the location of the reserve. You could then see the all the data in real time from the MySQL database.⁠

To protect against the weather, the sensor team mounted the Sun SPOTs in cases from OtterBox. To extend the battery life, the students soldered wires from the devices⁠⁠ external power terminal to solar panels, which were originally used to power garden lamps. The panels were themselves mounted on part of a refrigerator.

“The lesson for us was that anyone with a little motivation and technical background can make Sun SPOTs do amazing things,⁠⁠ Fusting says. Sun Labs was sufficiently impressed, and this summer brought Fusting in as an intern, where he has been polishing his Java skills and working on the project. By August when we spoke, he was preparing to return to Panama with Abernathy.

Also making the trip was Roger Meike, Sun Labs⁠⁠ Senior Research Director. I spoke by phone with him and his colleague, Senior Software Engineer Arshan Poursohi.

Sun SPOT isn't the first remote sensor device. Where did you see a need?
Poursohi: The big problem with existing platforms was the high ramp-up time. We wanted to introduce a platform easy enough for a novice embedded systems programmer that would still serve the needs of a professional. That's a challenge especially when you start to use multiple devices, which have sometimes required a team of people to maintain.
Meike: People who develop embedded systems have very specific skills. We are looking to bring in a larger community of people to embedded systems development. At the same time, we wanted to give Java programmers something to think about beyond the keyboard, mouse and screen?to let them program things out in the world.
So the difference between Sun SPOT and conventional remote sensing is largely in the programming language?
Poursohi: Correct. Historically, a lot of these nodes had been programmed in either assembly or low-level C. The de facto standard in the wireless center space is nesC, a C language subset. And there was also frustration with the hardware environment. Typically, the components don't come out of the box in a useable state. You have to spend a lot of time getting just to a basic "Hello World" output. We wanted to provide a good experience from the beginning.
Meike: Previous embedded technology was typically designed for specific applications, and to keep the production costs of those applications low. We designed the Sun SPOT hardware and software for general purpose flexibility, rather than optimizing for deployment. For example, the eDemo board that connects to the Sun SPOT is designed to make it easy to add external sensors, so that people who are not familiar with low-level hardware design can still experiment and follow their imagination.
Poursohi: Another difference was in using a 32-bit processor, an ARM-9, instead of the usual 8-bit microcontroller. That gives you a faster processor, a little bit more memory space, and far more power in connecting to things.
What did Sun Labs actually develop?
Meike: We built the entire system from scratch: the hardware platform, the functions of an operating system, an entirely new implementation of Java, plus libraries, drivers, and applications that sit on top.
What does it mean to implement Java "to the metal?"
Meike: It means we built some of the features you normally get in an operating system, such as the ability to start and stop processes, into the Java VM?so that the virtual machine also functions as the operating system. There is a small bit of C code that the system stands on?the rest of it is all Java. Even the Java virtual machine itself is mostly written in Java. That gives you a flexible environment that is very consistent all the way down to the hardware, so that you don't need different people with different skills to make a change to the environment. And because we've open sourced all of this, people can not only write applications but can dive deeper to customize the entire system, making the device do exactly what they want it to do.
Poursohi: On top of the VM, we have a multi-hop library, allowing messages to travel hop-to-hop up to around 100 meters per hop. Other libraries, which we've also open sourced, deal with the on-board sensors, as well as external sensors that you can add.
How much did you build upon Java ME for mobile applications?
Meike: That was definitely part of the inspiration. Java is already one of the most popular mobile platforms in the world, running on some 2 billion mobile phones. So given that expertise, we wanted to try to inspire what comes next.
It strikes me as unusual that a research lab would not just produce a technology like Sun SPOT, but invite developers to try it out.
Meike: The model was easier for us than it might first appear. This would have been just an open source development project, except that there's hardware involved?so we had to figure out how to get that into people's hands. Sun isn't known for selling small gadgets and research labs aren't usually authorized to sell products, but in this case, that's essentially what we did. We act like a tiny startup company?we even designed the box. I like to tell people that our entire inventory consists of a single part number, but really, this is about creating a community of developers. We'd like to see other companies take it from here.
But Sun does like to make money. What's the business model?
Meike: I think it's the same model as selling Java licenses on cell phones. We want to inspire people to use Sun technology. Our bet is that some of those people will create successful businesses, and when they do, they'll work closely with us to be even more successful.
How do people share code?
Meike: We have a site dedicated to collaboration: We also encourage colleges and universities to make their work available as open source on their own websites.
Sun SPOT has attracted artists, hobbyists, and researchers. Has anyone come up with anything you hadn't thought of?
I mean ideas that are commercially viable.
Meike: Most of those had already occurred to us: package monitoring, sensing ecological data, sensing HVAC [heading, ventilation, air conditioning] data. But it's hard to know what actually has promise in the market. People are using Sun SPOT to control model railroads. That application is a hobby, but it could also conceivably become a product.
What are you seeing from Japan?
Meike: We have not localized Sun SPOT technology for Japan, nor was it the first country where the technology was available: and yet, the fastest selling country for Sun SPOT is not the U.S. or some place in Europe?it's Japan.
Poursohi: Some of the projects from there are great?and we've had some commercial inquiries, as well.
Meike: In general, if you do a YouTube or Flickr search for the tag "spaughts", you'll see what people are up to.
What kind of industry interest has there been worldwide?
Meike: We're seeing interest especially from companies who are looking to prototype things quickly, or experiment with new types of devices. Sun SPOT is a great platform for that. But because it is not optimized for deployment, it's not necessarily what an established embedded company would switch to. We think that will be longer term and will depend in part on the economics of the hardware. The cost of all processors is going down, which means that the price difference between 8-bit and 32-bit processors will get smaller and smaller. And as the price gap narrows, there are more applications where the cost savings in development time justifies a greater expense for deployment. Eventually, we think the price difference will approach zero, and when that time comes, we want to have the best development platform out there.
Is higher power consumption also a limiting factor for 32-bit?
Poursohi: Yes, but a slightly larger battery will take care of it. So it again depends on how much you want to spend on optimizing, versus higher production costs.
You've said that you can get a lot done with a Sun SPOT with just a comparatively few lines of code. What's the process like?
Poursohi: The first thing to note is that you can get a lot of work done just with the libraries we've provided without being a hardware guru. For example, to connect to a remote control car, you instantiate an object that knows how to control a servo, then tell the servo where you'd like the car to go. If you want to connect a device not supported by our libraries, you can make your own Java class. Doing that will give you the ability to control the electrical value of the pins?that is, you represent a pin with an object whose methods include the ability to set it high or low. Of course, you must also read the device spec sheet to understand how the protocol works. We also provide some intermediate levels of control. For instance, we have a library for devices that are connected via serial. Of course, you must still write a protocol on top of that.
Meike: For example, a GPS connects both mechanically and electrically using a serial port. But the device also may also use an NMEA [National Marine Electronics Association] protocol for the actual data. So you would write Java code to parse that data and turn it into coordinates that tell where you are.
Poursohi: The big advantage here is that the protocol you've written is still in Java, which means you can run the same code on a laptop or a phone. In fact, if you look around, you'll find that this code is already available in an open source repository.
Meike: Another way to look at Sun SPOT’s Java implementation is standard Java, with the addition of PEEK and POKE functions. You get the advantages of a high level programming language and the familiarity of Java, but with the specificity of assembly?like setting pin and register values. If you do that, you still need to understand the underlying chip, but at least you don't have to change modes and switch to an entirely different language.
Does Java’s portability also come into play here compared with traditional embedded system development?
Poursohi: When you get down to the lower levels, you run into the same problems as traditional development?for example if a certain chip isn't connected in the usual way, you won't be able to change the pin values in the usual way. But you can just remap the pins; the rest of the code remains the same.
Are you still writing new libraries?
Poursohi: Continually. For example, we're currently writing a set of libraries called Yggdrasil [from Norse mythology?the tree at the center of the universe], a higher level framework that will sit atop our existing libraries and help tie multiple Sun SPOTS into a single system. See for more information.
What about new boards under development?
Poursohi: The basic idea is that the daughter board is changeable, so if you're not happy with the sensor set that's on there, you can design your own. At the lab, we've designed many of these daughter boards for our various internal applications. We've open sourced all of them, although we're currently only selling the eDemo board. We have one board that can accept SD cards for data logging, another, called eSerial, which allows high-speed connections to serial ports, two prototyping boards that let you easily attach other sensors?one with an 8-bit processor on it for easier control. Our latest board is the eDAC, which is a high-grade digital to analog conversion, which allows you to use the Sun SPOT much like an oscilloscope.

Project Sun SPOT resources
Project Sun SPOT home page
Applications, instruction, libraries and more
David Abernathy's Panama photos on Flickr
Sun SPOTs on Flickr site ,