コード例 #1
1
  /*
   * Returns list of sensors currently loaded in the system
   * */
  public static String getListOfSensors() {
    StringBuilder s = new StringBuilder();
    Iterator iter = Mappings.getAllVSensorConfigs();

    sensors.clear();
    coordinates.clear();

    while (iter.hasNext()) {
      VSensorConfig sensorConfig = (VSensorConfig) iter.next();
      Double longitude = sensorConfig.getLongitude();
      Double latitude = sensorConfig.getLatitude();
      Double altitude = sensorConfig.getAltitude();
      String sensor = sensorConfig.getName();

      if ((latitude != null) && (longitude != null) && (altitude != null)) {
        Point point = new Point(latitude, longitude, altitude);
        coordinates.add(point);
        sensors.add(sensor);
        s.append(sensor)
            .append(" => ")
            .append(longitude)
            .append(" : ")
            .append(latitude)
            .append("\n");
      }
    }
    return s.toString();
  }
コード例 #2
0
ファイル: LoginToMSRSense.java プロジェクト: joheben/OpenIoT
  public static void main(String[] args) throws RemoteException, FileNotFoundException {

    PropertyConfigurator.configure(DEFAULT_GSN_LOG4J_PROPERTIES);
    String host = "http://micssrv22.epfl.ch/";
    VSensorConfig conf = new VSensorConfig();
    conf.setName("GSNTest");
    conf.setDescription("Desc1");
    conf.setAddressing(
        new KeyValue[] {
          new KeyValueImp("latitude", "46.4823313875"),
          new KeyValueImp("Longitude", "6.9873408131"),
          new KeyValueImp("Altitude", "2043.1780")
        });
    conf.setOutputStructure(
        new DataField[] {
          new DataField("rh", "integer"),
          new DataField("ths", "double"),
          new DataField("rh", "double")
        });
    String username = "******";
    String password = "******";

    register_sensor(username, password, conf, host);
    // delete_sensor(username, password, conf);
  }
コード例 #3
0
ファイル: LoginToMSRSense.java プロジェクト: joheben/OpenIoT
  /**
   * Tries to delete a virtual sensor. Returns an integer for status.
   *
   * @param username username for sensorweb user account
   * @param password password for sensorweb user account
   * @param conf configuration of the virtual sensor
   * @return status of operation is integer. 0 for not deleted (already exists), 1 for deleted.
   * @throws java.rmi.RemoteException java.rmi.RemoteException
   */
  public static int delete_sensor(String username, String password, VSensorConfig conf)
      throws RemoteException {

    logger.warn("Deleting sensor " + conf.getName() + " from Sensormap...");
    gsn.msr.sensormap.sensorman.ServiceStub stub = new gsn.msr.sensormap.sensorman.ServiceStub();
    gsn.msr.sensormap.sensorman.ServiceStub.Guid passGUID = login_to_sensor_map(username, password);

    // create DeleteVectorSensor object
    gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensor deleteVectorSensorParams =
        new gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensor();
    deleteVectorSensorParams.setPassCode(passGUID);
    deleteVectorSensorParams.setPublisherName(username);
    deleteVectorSensorParams.setOriginalPublisherName(username);
    deleteVectorSensorParams.setSensorName(conf.getName());

    logger.warn("Calling DeleteVectorSensor with parameters:");
    logger.warn("...passCode: " + deleteVectorSensorParams.getPassCode());
    logger.warn("...PublisherName: " + deleteVectorSensorParams.getPublisherName());
    logger.warn("...OriginalPublisherName: " + deleteVectorSensorParams.getOriginalPublisherName());
    logger.warn("...SensorName: " + deleteVectorSensorParams.getSensorName());

    gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensorResponse output =
        stub.DeleteVectorSensor(deleteVectorSensorParams);
    String call_output = output.getDeleteVectorSensorResult();

    if (call_output.indexOf("OK") >= 0) {
      logger.warn(
          "Sensor " + conf.getName() + " deleted correctly. SensorMap says: " + call_output);
      return DELETE_SENSOR_OK;
    } else {
      logger.warn("Sensor " + conf.getName() + " not deleted. SensorMap says: " + call_output);
      return DELETE_SENSOR_ERROR_DOESNT_EXIST;
    }
  }
コード例 #4
0
ファイル: Repository.java プロジェクト: rathoddt/OpenIoT
  public static Sensor createLSMSensor2(VSensorConfig vs) {
    SensorMetaData s = createSensorMetaData(vs);

    System.out.println("*************  NOW publishing *****" + "\n" + vs);
    System.out.println(s);

    Sensor sensor = new Sensor();
    sensor.setName(s.getSensorName());
    sensor.setAuthor(s.getAuthor());
    sensor.setSensorType(s.getSensorType());
    sensor.setSourceType(s.getSourceType());
    sensor.setInfor(s.getInformation());
    sensor.setSource(s.getSource());
    sensor.setTimes(new Date());

    Place place = new Place();
    place.setLat(vs.getLatitude());
    place.setLng(vs.getLongitude());
    sensor.setPlace(place);

    logger.warn("sensor created from file (metadata)");

    return sensor;
  }
コード例 #5
0
ファイル: Main.java プロジェクト: jakobvukalovic/gsn-client
  public static StorageManager getStorage(VSensorConfig config) {
    // StringBuilder sb = new StringBuilder("get storage for: ").append(config == null ? null :
    // config.getName()).append(" -> use ");
    StorageManager sm = storagesConfigs.get(config == null ? null : config);
    if (sm != null) return sm;

    DBConnectionInfo dci = null;
    if (config == null || config.getStorage() == null || !config.getStorage().isDefined()) {
      // Use the default storage
      //    sb.append("(default) config: ").append(config);
      sm = mainStorage;
    } else {
      //    sb.append("(specific) ");
      // Use the virtual sensor specific storage
      if (config.getStorage().isIdentifierDefined()) {
        // TODO get the connection info with the identifier.
        throw new IllegalArgumentException("Identifiers for storage is not supported yet.");
      } else {
        dci =
            new DBConnectionInfo(
                config.getStorage().getJdbcDriver(),
                config.getStorage().getJdbcURL(),
                config.getStorage().getJdbcUsername(),
                config.getStorage().getJdbcPassword());
      }
      sm = storages.get(dci.hashCode());
      if (sm == null) {
        sm =
            StorageManagerFactory.getInstance(
                config.getStorage().getJdbcDriver(),
                config.getStorage().getJdbcUsername(),
                config.getStorage().getJdbcPassword(),
                config.getStorage().getJdbcURL(),
                DEFAULT_MAX_DB_CONNECTIONS);
        storages.put(dci.hashCode(), sm);
        storagesConfigs.put(config, sm);
      }
    }
    // sb.append("storage: ").append(sm.toString()).append(" dci: ").append(dci).append(" code:
    // ").append(dci == null ? null : dci.hashCode());
    // if (logger.isDebugEnabled())
    // logger.warn(sb.toString());
    return sm;
  }
コード例 #6
0
ファイル: LoginToMSRSense.java プロジェクト: joheben/OpenIoT
  public static int register_sensor(
      String username, String password, VSensorConfig conf, String gsnURI)
      throws RemoteException, FileNotFoundException {

    gsn.msr.sensormap.sensorman.ServiceStub.Guid passGUID = login_to_sensor_map(username, password);
    HashMap<String, MetaData> output =
        MetaData.createMetaData(Main.getContainerConfig().getMsrMap().get("metadata"));

    logger.warn("Registering sensor " + conf.getName() + " on Sensormap...");

    gsn.msr.sensormap.sensorman.ServiceStub stub =
        new gsn.msr.sensormap.sensorman.ServiceStub(); // the
    // default
    // implementation
    // should
    // point
    // to
    // the
    // right
    // endpoint

    StringBuilder pComments = new StringBuilder();
    StringBuilder pNames = new StringBuilder();
    StringBuilder pMetadata = new StringBuilder();
    StringBuilder pTypes = new StringBuilder();
    String groupName = Main.getContainerConfig().getMsrMap().get("group-name");

    for (DataField df : conf.getOutputStructure()) {
      MetaData metaData = output.get(df.getName().toLowerCase().trim());
      String pType = null;
      String pUnit = "";

      if (metaData != null) {
        pTypes.append(metaData.getSensorType()).append("|");
        pType = metaData.getSensorType();
        pMetadata.append(metaData.getMetadata()).append("|");
        pComments.append(metaData.getComments()).append("|");
        pNames.append(metaData.getSensorName()).append("|");
        pUnit = metaData.getUnit();
      } else {
        pTypes.append(df.getName()).append("|");
        pNames.append(df.getName()).append("|");
        pType = df.getName();
      }
      if (!dataTypeCache.contains(pType)) {
        gsn.msr.sensormap.sensorman.ServiceStub.CreateSingularSensorType createType =
            new gsn.msr.sensormap.sensorman.ServiceStub.CreateSingularSensorType();
        createType.setPublisherName(username);
        createType.setPassCode(passGUID);
        createType.setName(pType);
        createType.setUnit(pUnit);
        createType.setDataType("scalar");
        createType.setIconUrl("");
        String result =
            stub.CreateSingularSensorType(createType).getCreateSingularSensorTypeResult();
        logger.info("Registering data type: " + pType + " , MSR's output: " + result);
        dataTypeCache.add(pType);
      }
    }

    gsn.msr.sensormap.userman.ServiceStub.AddGroup createGroup =
        new gsn.msr.sensormap.userman.ServiceStub.AddGroup();
    gsn.msr.sensormap.userman.ServiceStub login = new gsn.msr.sensormap.userman.ServiceStub();
    createGroup.setGrpName(conf.getName());
    if (groupName != null && groupName.trim().length() > 0) createGroup.setParentGroup(groupName);
    createGroup.setAdmin(username);
    String call_output = login.AddGroup(createGroup).getAddGroupResult();
    logger.info(
        "Creating a group called : "
            + conf.getName()
            + " With Parent: "
            + groupName
            + " MSR: "
            + call_output);

    gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensor deleteVSensorParam =
        new gsn.msr.sensormap.sensorman.ServiceStub.DeleteVectorSensor();
    deleteVSensorParam.setOriginalPublisherName(username);
    deleteVSensorParam.setPublisherName(username);
    deleteVSensorParam.setPassCode(passGUID);
    deleteVSensorParam.setSensorName(conf.getName());
    deleteVSensorParam.setSensorType("GSN-" + conf.getName());

    call_output = stub.DeleteVectorSensor(deleteVSensorParam).getDeleteVectorSensorResult();
    logger.info("Unregister: " + conf.getName() + " - MSR: " + call_output);

    gsn.msr.sensormap.sensorman.ServiceStub.RegisterCompositeSensor registerVectorSensorParams =
        new gsn.msr.sensormap.sensorman.ServiceStub.RegisterCompositeSensor();

    registerVectorSensorParams.setPublisherName(username);
    registerVectorSensorParams.setPassCode(passGUID);
    registerVectorSensorParams.setVectorSensorName(conf.getName());
    registerVectorSensorParams.setWsURL(gsnURI + "services/Service?wsdl");
    registerVectorSensorParams.setAlt(conf.getAltitude().toString());
    registerVectorSensorParams.setLat(conf.getLatitude().toString());
    registerVectorSensorParams.setLon(conf.getLongitude().toString());
    registerVectorSensorParams.setDesc(conf.getDescription());
    registerVectorSensorParams.setVectorSensorType("GSN-" + conf.getName());
    registerVectorSensorParams.setParamTypes(pTypes.toString());
    registerVectorSensorParams.setParamComments(pComments.toString());
    registerVectorSensorParams.setParamMetaData(pMetadata.toString());
    registerVectorSensorParams.setParamNames(pNames.toString());
    registerVectorSensorParams.setAccessControl("protected");
    registerVectorSensorParams.setDataType("vector");
    registerVectorSensorParams.setIcon("image/CImg/weather_tower.gif");
    registerVectorSensorParams.setGroupName(conf.getName());

    call_output =
        stub.RegisterCompositeSensor(registerVectorSensorParams).getRegisterCompositeSensorResult();

    if (call_output.indexOf("OK") >= 0) {
      logger.warn(
          "Sensor " + conf.getName() + " registered correctly. SensorMap says: " + call_output);
      return REGISTER_SENSOR_OK_CREATED_NEW;
    }

    if (call_output.indexOf(
            "Error: Sensor with the same publisher name and sensor name already exists")
        >= 0) {
      logger.warn(
          "Sensor "
              + conf.getName()
              + " not registered (already exists). SensorMap says: "
              + call_output);
      return REGISTER_SENSOR_ERROR_ALREADY_EXISTS;
    }

    logger.warn("Sensor " + conf.getName() + " not registered. SensorMap says: " + call_output);
    return REGISTER_SENSOR_ERROR_NOT_CREATED;
  }
コード例 #7
0
ファイル: Repository.java プロジェクト: rathoddt/OpenIoT
  public Sensor createLSMSensor(VSensorConfig vs) {
    SensorMetaData s = createSensorMetaData(vs);

    String id =
        TestLSM.addSensorToLSM(
            "swissex",
            "swissex1234",
            s.getSensorName(),
            s.getAuthor(),
            s.getSourceType(),
            s.getSensorType(),
            s.getInformation(),
            s.getSource(),
            0,
            0);

    System.out.println("SENSOR ID published to LSM => " + id);

    if (true) return null;

    Sensor sensor = null;
    LSMTripleStore lsmStore = null;

    try {

      System.out.println("Testing LSM...");

      // 1. Create an instanse of Sensor class and set the sensor metadata
      sensor = new Sensor();
      sensor.setName(s.getSensorName());
      sensor.setAuthor(s.getAuthor());
      sensor.setSensorType(s.getSensorType());
      sensor.setSourceType(s.getSourceType());
      sensor.setInfor(s.getInformation());
      sensor.setSource(s.getSource());
      sensor.setMetaGraph("http://lsm.deri.ie/OpenIoT/test/sensormeta#");
      sensor.setDataGraph("http://lsm.deri.ie/OpenIoT/test/sensordata#");
      sensor.setTimes(new Date());

      System.out.println(sensor.getId());

      // set sensor location information (latitude, longitude, city, country, continent...)
      Place place = new Place();
      place.setLat(vs.getLatitude());
      place.setLng(vs.getLongitude());
      sensor.setPlace(place);

      sensor.setUser(user);

      // create LSMTripleStore instance
      lsmStore = new LSMTripleStore();

      // set user information for authentication
      lsmStore.setUser(user);

      System.out.printf(sensor.getId());
      // call sensorAdd method
      lsmStore.sensorAdd(sensor);

      System.out.printf(sensor.getId());

    } catch (Exception e) {
      logger.warn("cannot send the data to server");
      logger.warn(e);
    }

    return sensor;
  }
コード例 #8
0
ファイル: Repository.java プロジェクト: rathoddt/OpenIoT
 public static String generateMetaDataFileName(VSensorConfig vs) {
   return vs.getFileName() + METADATA_FILE_SUFFIX;
 }