private void publicaSensor(Gateway gateway, Sensor sensor) throws Exception {

    // make sure cookies is turn on
    CookieHandler.setDefault(new CookieManager());

    HTTPClient http = new HTTPClient();

    List<NameValuePair> postp = new ArrayList<>();
    postp.add(new BasicNameValuePair("login", "huberto"));
    postp.add(new BasicNameValuePair("password", "99766330"));

    http.sendPost(this.urlLogin, postp);

    List<NameValuePair> SensorParams = new ArrayList<>();
    SensorParams.add(new BasicNameValuePair("sensor_nome", sensor.getNome()));
    SensorParams.add(new BasicNameValuePair("sensor_desc", sensor.getDescricao()));
    SensorParams.add(new BasicNameValuePair("sensor_modelo", sensor.getModelo()));
    SensorParams.add(new BasicNameValuePair("sensor_precisao", sensor.getPrecisao()));
    SensorParams.add(new BasicNameValuePair("sensor_tipo", sensor.getTipo()));
    SensorParams.add(
        new BasicNameValuePair("sensor_servidorborda", Integer.toString(this.ServidorBordaID)));
    SensorParams.add(new BasicNameValuePair("sensor_gateway", Integer.toString(gateway.getId())));

    String result = http.GetPageContent(this.insertSensorURI, SensorParams);
    // System.out.println(result);
    String publicType = result.split(":")[0];
    String sensorID = result.split(":")[1];

    sensor.setId(Integer.parseInt(sensorID));

    if (null != publicType)
      switch (publicType) {
        case "insert":
          System.out.println(
              "-> Sensor "
                  + sensor.getNome()
                  + "("
                  + sensor.getId()
                  + ") cadastrado no Servidor de Contexto com sucesso.");
          break;
        case "update":
          System.out.println(
              "-> Sensor "
                  + sensor.getNome()
                  + "("
                  + sensor.getId()
                  + ") atualizado no Servidor de Contexto com sucesso.");
          break;
      }
  }
示例#2
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);
  }
示例#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;
  }