Example #1
0
  public void publish(SensorObservation observation, SensorMetaData sensorMetaData) {

    logger.warn("asked to publish");
    logger.warn(observation);
    logger.warn(sensorMetaData);

    if (true) return;

    // create an Observation object
    Observation obs = new Observation();

    logger.warn(sensorMetaData.getSensorID());
    // set SensorURL of observation
    Sensor sensor2 = lsmStore.getSensorById(sensorMetaData.getSensorID());
    obs.setSensor(sensor2.getId());
    // set time when the observation was observed. In this example, the time is current local time.
    obs.setTimes(observation.getTime());

    ObservedProperty obvTem = new ObservedProperty();
    obvTem.setObservationId(obs.getId());
    obvTem.setPropertyName(observation.getPropertyName());
    obvTem.setValue(observation.getValue());
    obvTem.setUnit(observation.getUnit());
    obs.addReading(obvTem);
    lsmStore.sensorDataUpdate(obs);
  }
Example #2
0
  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;
  }
Example #3
0
  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;
  }
Example #4
0
 public static SensorMetaData createSensorMetaData(VSensorConfig vs) {
   String metadataFile = generateMetaDataFileName(vs);
   SensorMetaData s = new SensorMetaData();
   s.initFromFile(metadataFile);
   return s;
 }