Ultra-low Bandwidth Communication with Java ME

By Bruce Hopkins (updated)

In the U.S. Department of Defense as well as in commercial industries, there are several applications that need wireless communication at low data rates (and consequently with low power consumption). For instance, most modern vehicles now contain tire pressure monitoring systems.

Have you ever wondered how the tire pressure sensor data is sent from each of the tires to the vehicle’s internal embedded computing system, and ultimately to the dashboard? Obviously, there are no wires to connect the sensors in the tires to the data bus in the dashboard. So, as you can imagine, there must be some mechanism available in order to retrieve the sensor data from the tire pressure sensors. Additionally, such a mechanism must be wireless and be able to operate for a very long time without interruption.

In this tech tip, we’re going to explore how to use Java ME and Sun SPOT technology to create a low-bandwidth wireless system to read sensor data. The following image shows one of the SPOTs relative to a US quarter.

Here’s some Sun SPOT specs -- you can see why I’m excited about creating and deploying applications on this new computing platform:

    Java ME CLDC 1.1 JVM (Squawk VM)
    180 MHz 32 bit processor
    512K RAM
    4M Flash memory
    IEEE 802.15.4 radio with integrated antenna
    3-axis accelerometer
    Temperature sensor
    Light sensor
    6 analog inputs with ADC
    2 user-programmable switches
    rechargeable battery

Note that although the Sun SPOTs are compliant with the 802.15.4 specification, they are not fully compliant with true ZigBee devices since they do not implement the upper layers of the ZigBee protocol. Since many folks are fairly new to ZigBee, let’s compare it with some of the more common wireless communication protocols. The table below compares WiFi, Bluetooth, and ZigBee.

WiFi Bluetooth ZigBee
IEEE Specification 802.11b,g 802.15.1 802.15.4
Maximum Bandwidth 54 Mb/s 3 Mb/s 250 kb/s
Maximum Communication Range 300 ft. 300 ft. 30 ft.
Power Consumption Rate hours days months/years

As you can see, ZigBee (or any other IEEE 802.15.4 derivative) is an ideal protocol for wireless sensor applications. These applications are typified by scenarios where it is either impractical or inconvenient to have a physical connection to the desired sensor or sensor array (for instance, a tire pressure sensor). The Sun SPOT SDK includes (3) SPOT devices. One of them attaches to your computer via a USB cable and acts as a base station while the other two can freely roam.

This tech tip presents two fully functioning applications; the first one will be the base station application, which will receive data from the second application, the free roaming wireless Sun SPOT. In this scenario, I’m not going to perform any discovery mechanism in order for the two devices to find each other. I already know the ZigBee address of the both the base station and the free roaming SPOT, so I’m going to have them address each other directly. Since the SPOTs have a CLDC JVM, I’ll use the Generic Connection Framework (GCF) in order to open a connection from the base station to the free roaming SPOT:

Connector.open("radiostream://0014.4F01.0000.1447:55");

As you can see, the wireless address of the free roaming SPOT is 0014.4F01.0000.1447. In this application, I chose an arbitrary port number of 55, but you’re free to use any numerical value between 31 and 127 as a port number for your applications.

Following is the full source for the base station application, named HostReceiver.java. It opens a wireless connection to the free roaming SPOT devices and receives 10 temperature readings from the remote device.
package receiver;

import com.sun.spot.peripheral.\*;
import com.sun.spot.peripheral.radio.\*;
import com.sun.spot.io.j2me.radio.\*;
import com.sun.spot.io.j2me.radiogram.\*;
import com.sun.spot.util.IEEEAddress;
import java.io.DataInputStream;
import javax.microedition.io.InputConnection;   
import com.sun.spot.util.\*;

import java.io.\*;
import javax.microedition.io.\*;

public class HostReceiver {
    /\*\*
     \* Print out our radio address.
     \*/
    public void run() throws IOException{
        IEEEAddress zigbeeAddress = new IEEEAddress(Spot.getInstance().getRadioPolicyManager().getIEEEAddress());
        System.out.println("The Host station Zigbee radio address = " + zigbeeAddress.asDottedHex());
        
        StreamConnection streamConnection = (StreamConnection) Connector.open("radiostream://0014.4F01.0000.1447:55");
         
        for(int i=0; i<10; i++){

            DataInputStream data_input_stream = streamConnection.openDataInputStream();

            double value = data_input_stream.readDouble();
            System.out.println("The temperature is: " + value + "F");

            data_input_stream.close();
            Utils.sleep(3000);        
        }
       
        streamConnection.close();
        System.exit(0);     
        
    }

    /\*\*
     \* Start up the host application.
     \*
     \* @param args any command line arguments
     \*/
    public static void main(String[] args) throws Exception {
        HostReceiver app = new HostReceiver();
        app.run();
    }
}

Now, here’s the code for the free roaming SPOT that samples the ambient temperature using its onboard temperature sensor. It will sample the temperature 10 times and send that data to the base station. This application also does some extra work by turning on the external LEDs to different colors in order to let the operator know if the SPOT is operating properly or encountering an exception. All this code is contained in the file named SpotSender.java.

package sender;

import com.sun.spot.peripheral.Spot;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.peripheral.ITriColorLED;
import com.sun.spot.peripheral.radio.IRadioPolicyManager;
import com.sun.spot.io.j2me.radiostream.\*;
import com.sun.spot.io.j2me.radiogram.\*;
import com.sun.spot.util.\*;
import com.sun.spot.sensorboard.io.ITemperatureInput;

import java.io.\*;
import javax.microedition.io.\*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import java.io.\*;
import javax.microedition.io.\*;

public class SpotSender extends MIDlet {    
    public StreamConnection streamConnection = null;
    public ITemperatureInput temperatureSensor = null;
    public IEEEAddress zigbeeAddress = null;
    
    public SpotSender(){
        try {
            streamConnection = (StreamConnection) Connector.open("radiostream://0014.4F01.0000.1709:55");
            temperatureSensor = EDemoBoard.getInstance().getADCTemperature();
            zigbeeAddress = new IEEEAddress(Spot.getInstance().getRadioPolicyManager().getIEEEAddress());
            
            System.out.println("Our radio address = " + zigbeeAddress.asDottedHex());
        } catch (IOException e){
            System.out.println("exception in constructor");
        }       
    }
    
    protected void startApp() throws MIDletStateChangeException {
     
        // get a reference to the LED array
        ITriColorLED [] leds = EDemoBoard.getInstance().getLEDs();
        
        // set LED2 to green
        leds[2].setRGB(0,100,0);               
        
        for(int i=0; i<10; i++){
            
            // turn all LEDs off
            leds[2].setOff();
            leds[3].setOff();
            leds[4].setOff();
            
            // turn LED2 on
            leds[2].setOn();                 
            Utils.sleep(250);                  

            try{              
                DataOutputStream data_output_stream = streamConnection.openDataOutputStream();
                data_output_stream.writeDouble(temperatureSensor.getFahrenheit());

                data_output_stream.close();
               
                // set the color to blue
                leds[3].setRGB(0,0,100);                   
                leds[3].setOn();                    
            } catch (Exception e){
                // set the color to red
                leds[4].setRGB(100,0,0);             
                leds[4].setOn();                                 
            }           

            leds[2].setOff();
            Utils.sleep(3000);                                      
        }
        
        try{
            streamConnection.close();
        } catch (IOException e){   
        }       
    }
    
    protected void pauseApp() {
        // This will never be called by the Squawk VM
    }
    
    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // Only called if startApp throws any exception other than MIDletStateChangeException
    }
}

So what happens when you deploy and run this code yourself? Well, you should get an output like this from your base station application:

The Host station radio address = 0014.4F01.0000.1709
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.5F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.95F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.05000000000001F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.5F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.95F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.05000000000001F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.5F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.05000000000001F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.5F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
[radiostream] Adding: Input from 0014.4F01.0000.1447 on port 55
The temperature is: 90.5F
[radiostream]Removing: Input from 0014.4F01.0000.1447 on port 55
Success! It looks like it’s a little warm in my office, so I probably need to cool it down...
Comments:

Please note that Sun SPOTs do not implement the ZigBEE protocol. It uses the same PHY layer and implements the LowPan layer (I think), but not the ZigBEE protocol itself.

I think this means that it uses the same frequency and low level packet exchange, but does not support the higher level protocol which is embedded in these packets.

Long way of saying, no ZigBee, but the app is still cool :)

Posted by EricArseneau on December 06, 2007 at 03:04 PM PST #

You're absolutely right, about both points.

1. Yes, the Sun SPOTs implement the IEEE 802.15.4 spec, which is the same spec used by the ZigBee protocol (however, the SPOTs do not implement the upper layers of the spec).

2. Yes, the app is still cool. :-)

Thanks for the clarification.

Bruce

Posted by Bruce Hopkins on December 06, 2007 at 09:00 PM PST #

Nice writeup on a nifty application. One minor clarification, and this is to the physical range performance of 802.15.4. Under typical operating conditions, a 15.4 2.4GHz link at 0dBm output (1mW) will work reliably over distances between 70 and 250 ft indoors (in standard residential and commercial hollow-wall construction). Outdoors the line-of-sight distance has been regularly shown to be on the order of 1000 - 1300 ft using only a board trace for the antenna. If the job is to maintain low data rate, low-duty-cycle communications between two devices, 15.4 will always outperform 802.11b/g in the ability to maintain a link at a given distance.
There are those out there that have amped up 15.4 with both extra output power (upto about 20dBm/100mW, well below regulatory limit) and added a low-noise amp to the receiver. These hacks increase range significantly, and have been done mostly for operation in industrial environments. Outdoors, the range of so-equipped 15.4 radios is measurable in miles. This added range does come at an impact on battery life, but if the low duty-cycle suggestions are followed, then it's not necessarily a huge impact.
On the subject of Bluetooth, only BT Class 1 transmitters have a chance of making the 300' range, and that's only if the wind is blowing in the right direction %\^) and you're alone in the Mojave Desert. 99.99% of all BT products are Class 2, and the typical (not the advertised) range for class 2 products is 5 to 15'. Bluetooth was never intended for good range performance.

Posted by jon adams on December 07, 2007 at 12:39 AM PST #

Also note that IEEE 802.15.4 communications are more like 30m than 30ft.

Posted by Roger Meike on December 13, 2007 at 02:48 AM PST #

26

Posted by guest on January 15, 2008 at 10:52 PM PST #

Is there any target date or quarter for moving the Sqawk VM and support libraries into open source?

Posted by Steve on January 16, 2008 at 12:26 AM PST #

please i need latest infomation on the new Java tecnology and codes that can enhance my java ability.

Posted by Donald Felix on January 16, 2008 at 12:29 AM PST #

i need java Newsletters

Posted by Donald Felix on January 16, 2008 at 12:34 AM PST #

Regarding open-sourcing Squawk VM and support libraries, please keep tuned to the Java Mobile & Embedded Developer Days (January 23-24, 2008, Sun Santa Clara campus) as there will be an update about this there. <https://developerdays.dev.java.net/>

Posted by Christine Dorffi on January 16, 2008 at 06:44 AM PST #

You can read about various Java technology newsletters and tech tips at the Sun Developer Network (SDN) Program News site <http://blogs.sun.com/SDNProgramNews/> or at <http://developers.sun.com/newsletters/>. A couple of useful ones are Java Fundamentals <http://blogs.sun.com/JavaFundamentals/> and Core Java <http://blogs.sun.com/CoreJavaTechTips/>. The New to Java Programming Center may also be helpful: <http://java.sun.com/new2java/>.

Posted by Christine Dorffi on January 16, 2008 at 06:52 AM PST #

Hmmm..

How I can use those devices on our web-site?!

Posted by WiFi SQL Connector on January 16, 2008 at 11:24 PM PST #

Hi,

I'm not sure what you mean. The Sun SPOT device is a portable embedded system that includes a JVM, sensors, a radio, etc. I don't see how these devices could be utilized on a website. Can you provide a use case?

Thanks

Posted by Bruce Hopkins on January 17, 2008 at 02:39 AM PST #

Possible web scenario:

I'm currently working on a monitor/control Xaml website for wide area HVAC that uses Zigbee enabled relay+analog channel boards for controlling HVAC equipment. In my case the Zigbee network is connected to an onsite linux pc that communicates to the internet. The onsite computer polls local zigbee boards and pushes state back to an online server for storage in a SQL database. The return pull is the last command in a command table for changing state on a designated Zigbee board’s relay.

The online server persists board state and commands in a DB and allows clients to see visualizations of state as push button relay boards or A/D channels as simple strip charts.
HVAC is generally not mobile but I imagine full connectivity via cell/wifi would allow the same scenario using Sun Spot devices.

Posted by randy on January 21, 2008 at 01:17 AM PST #

Randy,

Thanks for the scenario. Yes, the host application can be modified so that it feeds the SPOTs sensor data to a JDBC database. If the database is accessed by a Servlet or JSP, then you can display such information on the web.

Posted by Bruce Hopkins on January 22, 2008 at 05:33 AM PST #

so whats the point, specify the Real World Industry Solution, & Offering for the Industry, rather than a Campus JAVA+ Device Sucess Experiment, How can I be able to Utilize the Device/Java with the E-Commerce Business,.......? any Idea, any Compatibility & the Range, & I Need a Range of 200feet, how you Respond with that as the Store is huge,

thanks,

Posted by hawk on January 24, 2008 at 07:48 AM PST #

is there any free downloads for windows me edition pc?

Posted by jerry harper on January 24, 2008 at 11:57 AM PST #

Best technology can be Improved by your ideas

Posted by Anna on February 08, 2008 at 06:52 PM PST #

still waiting to see them on the shelf at Frys

Posted by jon adams on February 08, 2008 at 11:20 PM PST #

So, is there any java implementation of ZIgBee out there? or do I have to implement the whole upper layer myself?

Posted by Ron Bartor on February 26, 2008 at 09:27 PM PST #

Ron,

I personally don't know of any implementations that have fully implemented the entire upper layer of the ZigBee protocol stack, but the links below point to some Java implementations that may provide what you're looking for:

http://seclab.uiuc.edu/web/uncategorized/jxbee-java-xbee-802.15.4-zigbee-modem-driver.html
http://www.ajile.com/index.php?Itemid=44&id=16&option=com_content&task=view
http://www.arcom.com/pr/released/ember_pr.htm

Thanks,

Bruce

Posted by Bruce Hopkins on February 27, 2008 at 11:15 PM PST #

Squawk was open sourced a couple of weeks ago and can now be found at http://squawk.dev.java.net.

Sun SPOT has also been open sourced, but under different projects, see https://spots.dev.java.net/ and http://www.sunspotworld.com.

We would love to see them on the shelves at Frys !!!

For more detailed information, I would recommend you pose questions on the forurms at http://sunspotworld.com/forums.

Posted by Eric Arseneau on February 28, 2008 at 08:26 AM PST #

Good nice!
Your very good!
But I can't use those devices on our web-site! Can you help me?
Thanks

Posted by xiong on March 04, 2008 at 03:53 PM PST #

Awesome. And thanks for posting some code. Always helps those of us out there walking blind.

Posted by 82drops on May 17, 2008 at 07:29 PM PDT #

The best of Java is yet to be done experience the world of Java2me

Posted by Donald Felix on May 19, 2008 at 02:27 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Tips for developers who use Java technologies (Java SE, Java ME, JavaFX) for mobile and embedded devices.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today