Hopping is a way for multiple Sun SPOTs to interact with each other over a wide range of area.
The main problem with the Sun SPOT is its range which according to theory is about 90 m on free ground. But it is found to decrease drastically due to intermediate obstacles. One of the ways to overcome this barrier is through hopping.
Hopping enables the data packet sent by a host Sun SPOT to reach its destination SPOT even though it is outside the range by using the intermediate SPOTs. This protocol support is built into SPOT SDK. The following code demonstrates the hopping of data packets using Sun SPOTs.
If the destination SPOT is not found in range, the NoRouteException is thrown and the SPOT sends the data to any other spot in range and tries to find the route through it. This mechanism can be used to create a mesh or network Sun SPOTs which can communicate to each other.
package org.sunspotworld.demo; import com.sun.spot.peripheral.Spot; import com.sun.spot.io.j2me.radiogram.*; import com.sun.spot.peripheral.NoRouteException; import com.sun.spot.peripheral.radio.mhrp.aodv.AODVManager; import com.sun.spot.util.IEEEAddress; import javax.microedition.io.*; /** * Sample Sun SPOT host application */ public class SunSpotHostApplication { /** * Print out our radio address. */ public void run() { //This method is authored by Amr Ergawy, the rest is SUN Microsystems template //The most important part here is using AODVManager to read routing tables //and to show the multi-hop routes IEEEAddress myAddr = new IEEEAddress(Spot.getInstance().getRadioPolicyManager().getIEEEAddress()); System.out.println("Hi! my address = " + myAddr.asDottedHex()); AODVManager theAODVManager = AODVManager.getInstance(); // It specifies the root and number of Sun SPOTS found int i=0; while(true) { try { RadiogramConnection conn = (RadiogramConnection) Connector.open("radiogram://:100"); Radiogram rdg = (Radiogram)conn.newDatagram(conn.getMaximumLength()); try { conn.receive(rdg); i++; System.out.println(i+" "+i+i); System.out.println("I recieved a msg from : " + rdg.getAddress().toString()); System.out.println("Its address as long is : " + rdg.getAddressAsLong()); System.out.println("The msg is : " + rdg.readUTF()); System.out.println("With a strenght of : " + rdg.getRssi()); System.out.println("At : " + System.currentTimeMillis()); System.out.println("And my route to it is : " + theAODVManager.getRouteInfo(rdg.getAddressAsLong())); System.out.println("\n\n\n"); } catch (NoRouteException e) { System.out.println("No route to any one ..."); } finally { conn.close(); } } catch(Exception e){ System.out.println("A problem opening the connection ..."); } } } /** * Start up the host application. * * @param args any command line arguments */ public static void main(String[] args) throws Exception { SunSpotHostApplication app = new SunSpotHostApplication(); app.run(); System.exit(0); } }





