Using Real World Data in Oracle Fusion

Sun Spots hooked upto Fusion

Time needed to try it ourself :
2 days setting up Sun Spots and getting it going in your Env

Purpose :
Wanted to get real world data to use in Oracle Fusion

What it covers :
    (1) BaseStation Code, Just pools for data from remote spots

    (2) Spot code, Remote spots give back temp, light, acc cord's

Implementation Details .....

BaseStation Code (hooked up to USB Radiogram Host pooling for Data)

package org.sunspotworld.demo;
/*
 * netsolvers.net Aug 23 2012
 *
 * @author Ravi Manthena
 * 
 * @ Netbeans with Sun Spot SDK 
 */
import com.sun.spot.io.j2me.radiogram.RadiogramConnection;
import java.io.BufferedWriter;
import java.io.FileWriter;
import javax.microedition.io.Connector;
import javax.microedition.io.Datagram;

public class SunSpotHostApplication {

    public void run() {

        int run10times = 10; // for testing only
        while (true) {
            RadiogramConnection conn = null;
            try {
                // Spot one xml spot name 086C
                conn = (RadiogramConnection) 
                        Connector.open("radiogram://0014.4F01.0000.086C:100");
                Datagram dg = conn.newDatagram(conn.getMaximumLength());
                dg.writeUTF("getstatus");
                conn.send(dg);
                conn.receive(dg);
                String spotinfo = dg.readUTF();
                System.out.println("Received: " + spotinfo);
                // write to a file system to be used by Fusion
                writetoxmlfile(spotinfo);
                conn.close();
                conn = null;
                Thread.sleep(100);

                // Spot two plan old name=value spot name 0ACF
                conn = (RadiogramConnection) 
                        Connector.open("radiogram://0014.4F01.0000.0ACF:101");
                dg = conn.newDatagram(conn.getMaximumLength());
                dg.writeUTF("getstatus");
                conn.send(dg);
                conn.receive(dg);
                spotinfo = dg.readUTF();
                System.out.println("Received: " + spotinfo);
                // write to a file system to be used by Fusion
                writetonamevaluefile(spotinfo);
                conn.close();
                conn = null;
                Thread.sleep(10000); // wait 10 sec to what is the staus
           } catch (Exception x) {
                System.out.println("One one the spot is hosted ");
                x.printStackTrace();
            } finally {

                if (conn != null) {
                    try {
                        conn.close();
                    } catch (Exception xx) {
                        xx.printStackTrace();
                    }
                }

            }
        }
    }
    
    
    public void writetonamevaluefile(String status){
            StringBuffer buf = new StringBuffer(status);
            try{
                StringBuffer newbuf = new StringBuffer();
                FileWriter fstream = 
      new FileWriter("/Users/manthena/linuxoraclesharefolder/spotgetstaus.txt");
                BufferedWriter out = new BufferedWriter(fstream);
                out.write(status);
                out.close();
                fstream.close();
            }catch (Exception x){
                x.printStackTrace();
            }
    }
    
    public void writetoxmlfile(String status){
            try{
                FileWriter fstream = 
      new FileWriter("/Users/manthena/linuxoraclesharefolder/spotgetstaus.xml");
                BufferedWriter out = new BufferedWriter(fstream);
                out.write(status);
                out.close();
                fstream.close();
            }catch (Exception x){
                x.printStackTrace();
            }
    }

    public static void main(String[] args) throws Exception {
        SunSpotHostApplication app = new SunSpotHostApplication();
        app.run();
        System.exit(0);
    }
}
Remote Spots Code

package org.sunspotworld.demo;
/*
 * netsolvers.net Aug 23 2012
 *
 * @author Ravi Manthena
 * 
 * @ Netbeans with Sun Spot SDK 
 */
import com.sun.spot.io.j2me.radiogram.RadiogramConnection;
import com.sun.spot.peripheral.radio.RadioFactory;
import com.sun.spot.resources.Resources;
import com.sun.spot.resources.transducers.IAccelerometer3D;
import com.sun.spot.resources.transducers.ILightSensor;
import com.sun.spot.resources.transducers.ITemperatureInput;
import com.sun.spot.resources.transducers.ITriColorLEDArray;
import com.sun.spot.resources.transducers.LEDColor;
import com.sun.spot.util.Utils;
import javax.microedition.io.Connector;
import javax.microedition.io.Datagram;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class SunSpotApplication extends MIDlet {

    // we need use all these default classes provided by Sun Spot
    private ITriColorLEDArray leds = 
            (ITriColorLEDArray) Resources.lookup(ITriColorLEDArray.class);
    private ITemperatureInput tempSensor = 
            (ITemperatureInput) Resources.lookup(ITemperatureInput.class);
    private IAccelerometer3D accel = 
            (IAccelerometer3D) Resources.lookup(IAccelerometer3D.class);
    // get access to lights on the board for bling bling factor and debugging
    ILightSensor lightSensor = 
            (ILightSensor) Resources.lookup(ILightSensor.class);

    protected void startApp() throws MIDletStateChangeException {
        long ourAddr = RadioFactory.getRadioPolicyManager().getIEEEAddress();
        ledsBlinkInRow(); //may be helpful in debugging 
        run();
    }

    public void run() {
        ledsBlinkInRowWhite();
        try {
            while (true) {
                RadiogramConnection conn = 
                       (RadiogramConnection) Connector.open("radiogram://:101");
                Datagram dg = conn.newDatagram(conn.getMaximumLength());
                Datagram dgreply = conn.newDatagram(conn.getMaximumLength());
                conn.receive(dg);
                String question = dg.readUTF();
                dgreply.reset(); // reset stream pointer
                dgreply.setAddress(dg); // copy reply address from input
                if (question.equals("getstatus")) {
                    dgreply.writeUTF(getspotinfo());
                    conn.send(dgreply);
                    conn.close();
                    ledsBlinkInRow(); 
                } else {
                    dgreply.writeUTF("Don't understand what you want");
                    conn.send(dgreply);
                    conn.close();
                    ledsBlinkInRowRed();
                }
            }
        } catch (Exception x) {
            ledsBlinkInRowRed();
            ledsBlinkInRowRed();
            x.printStackTrace();
        }

    }

    // format return spot status into name=value
    public String getspotinfo() {
     StringBuffer buf = new StringBuffer();
     try{
      buf.append("Temp="+Double.toString(tempSensor.getFahrenheit())+"\n");
      buf.append("Light="+Integer.toString(lightSensor.getAverageValue())+"\n");
      buf.append("AccesX="+accel.getAccelX()+"\n");
      buf.append("AccesY="+accel.getAccelY()+"\n");
      buf.append("AccesZ="+accel.getAccelZ()+"\n");
     }catch(Exception x){
        x.printStackTrace();
        buf.append("Something is wrong");
     }
     return buf.toString();
    }
    
    // format return spot status into xml
    public String getspotinfoxml() {

        StringBuffer buf = new StringBuffer();
        buf.append("");
        buf.append(getLightLevel());
        buf.append(getAcc());
        buf.append(getTempFahrenheit());
        buf.append("\n");
        return buf.toString();
    }

    // get temp in Fahahren
    public String getTempFahrenheit() {
        try {
            return "\n\t" + 
                   Double.toString(tempSensor.getFahrenheit()) + "";
        } catch (Exception x) {
            x.printStackTrace();
        }
        return "null";
    }

    // get temp in Celsisus
    public String getTempCelsius() {
        try {
            return "\n\t" + 
                   Double.toString(tempSensor.getCelsius()) + "";
        } catch (Exception x) {
            x.printStackTrace();
        }
        return "null";
    }

    // get the current light level 
    public String getLightLevel() {
        try {
            return "\n\t" + 
               Integer.toString(lightSensor.getAverageValue()) + "";

        } catch (Exception x) {
            x.printStackTrace();
        }
        return "null";
    }

    // get the Accelerometer X Y Z
    public String getAcc() {

        StringBuffer returnval = new StringBuffer();

        try {

            returnval.append("\n\t");
            returnval.append(accel.getAccelX());
            returnval.append("");

            returnval.append("\n\t");
            returnval.append(accel.getAccelY());
            returnval.append("");

            returnval.append("\n\t");
            returnval.append(accel.getAccelZ());
            returnval.append("");

            return returnval.toString();

        } catch (Exception x) {
            x.printStackTrace();
        }
        return "null";
    }

    // below are helper methods for bling bling and to know spot is working

    // add in the ; since code pretty stylesheet does not like that
public void ledsBlinkInRow() {
        leds.setOff();

        for (int i = 0 i  


Issues I ran info on Mac
Need to give sudo 755 permission on \var\ lock files for USB.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.