Beispiel #1
0
  public void startApp() throws MIDletStateChangeException {
    System.out.println("Starting sensor gathering");
    BootloaderListenerService.getInstance()
        .start(); // monitor the USB (if connected) and recognize commands from host
    long ourAddr = RadioFactory.getRadioPolicyManager().getIEEEAddress();
    System.out.println("Our radio address = " + IEEEAddress.toDottedHex(ourAddr));
    IAnalogInput sensor = EDemoBoard.getInstance().getAnalogInputs()[EDemoBoard.A4];

    DatagramConnection dgConnection = null;
    Datagram dg = null;
    try {
      // specify broadcast_port
      dgConnection = (DatagramConnection) Connector.open("radiogram://broadcast:" + BROADCAST_PORT);

      dg = dgConnection.newDatagram(50);
      System.out.println("Maxlength for Packet is : " + dgConnection.getMaximumLength());
    } catch (IOException ex) {
      System.out.println("Could not open radiogram broadcast connection");
      ex.printStackTrace();
      return;
    }
    int counter = 0;
    while (true) {
      try {

        // 9.8mV per inch
        double val = sensor.getVoltage();
        voltages[counter] = val;
        double sum = 0;
        for (int i = 0; i < voltages.length; i++) {
          sum += voltages[i];
        }
        System.out.println("Voltage average: " + sum / voltages.length);
        counter++;
        if (counter > 9) {
          counter = 0;
        }
        // System.out.println("Value in volts: "+ val);
        // double inches = val/0.0098;
        // System.out.println("Value in inches: "+ inches);
        // Write the string into the dataGram.
        // dg.reset();
        // dg.writeLong(ourAddr);
        // dg.writeDouble(val);

        // Send DataGram
        // dgConnection.send(dg);

        // Sleep for 200 milliseconds.
        Utils.sleep(50);
      } catch (IOException ex) {
        System.err.println("Caught " + ex + " while collecting/sending sensor sample.");
        ex.printStackTrace();
      }
    }
  }
Beispiel #2
0
 private void processAttentionCmd(IOTACommandHelper helper) {
   if (helper.isRemote()) {
     Utils.log("Redirecting output to " + hostAddress.asDottedHex());
     remotePrintManager.redirectOutputStreams(hostAddress.asDottedHex());
   }
 }