Exercise 7: Connecting via the Radio

Expected duration: 45 minutes

Introduction:

In this exercise, youwill complete your Wireless Sensor Application by enabling the Wireless Networking capabilities of the Sun SPOT and connecting your two applications wirelessly. At the end of this exercise, bending the Bend Sensor should result in a corresponding movement of the servo on the other end.

To enable the Radio Connection you will be using the BendySender and ServoReceiver classes in their respective projects. All of the network code for these two classes has already been implemented, and you will be enabling them in order to allow the network connections.

Steps to follow:

  1. Edit the Manifest files in each project to define the IEEE Network Addresses of each Sun SPOT
  2. Enable the Network Code in each Project
  3. Compile and deploy each project to your Sun SPOTs

Editiing the Manifest Files

  1. Go to the 'Files' Tab in NetBeans
  2. Select the 'resources/META-INF/Manifest.inf' file and open it for editing

  3. Enter the Sun SPOT IEEE Addresses for each Sun SPOT in the appropriate field
  4. Save the files
  5. Next you will need to edit the Bendy class file to enable the Network code.

    
     63    //  private BendySender nw;
     64 
     72        //  nw = new BendySender();
    
     97 //                try {
     98 //                    nw.send(msg);
     99 //                } catch (IOException ex) {
    100 //                    ex.printStackTrace();
    101 //                }
    
    158        // nw.connect();
    159 
    

    Just uncomment the indicated lines in the source file and the networking code will be activated.
  6. Open the ServoMover class and enable the Networking code in that class:

    
     81 //        snw = new ServoReceiver(this);
     82 //        System.out.println("Waiting for calibration data...");
     83 //        snw.connect();
     84 //        Thread t = new Thread(snw);
     85 //        t.start();
    

    Again, just uncomment the indicated lines to enable the networking code.
  7. Now build and deploy each application to your Sun SPOTs, and you're done!
  8. You will, of course, have to re-calibrate the Bend Sensor as you did in Software Exercise 1, after which bending the sensor should cause the Servo to move.

Your complete hardware setup should look like this:

Summary:

You should now have a fully functioning, networked Sun SPOT Wireless sensor application which reads data from a non-linear, analog Bend Sensor and transmits those readings over a wireless connection to a remote Sun SPOT which translates those values into linear values for a Servo and moves the servo.

Go to solution

Go on to summary