Exemplo n.º 1
0
  public static void newSensorData(String deviceName, String data) {
    Device found = null;
    for (Device device : Kernel.getInstance().getDevices()) {
      if (device.getName().equals(deviceName)) {
        found = device;
      }
    }
    if (found == null) {
      return;
    }
    JSONObject jsonObject = (JSONObject) JSONValue.parse(data);
    if (jsonObject == null
        || jsonObject.keySet() == null
        || jsonObject.keySet().iterator() == null) {
      // System.out.println("Erro json " + data);
      return;
    }

    JSONArray components = (JSONArray) jsonObject.get("components");

    Iterator i = components.iterator();
    while (i.hasNext()) {
      Object oo = i.next();
      JSONObject joo = (JSONObject) oo;
      String thing = joo.get("name").toString();
      String value = joo.get("value").toString();
      found.getThings().get(thing).setLastValue(value);
    }
  }
Exemplo n.º 2
0
 @GET
 @Produces("text/html")
 @Path("/data/{device}/{sensor}")
 public String execute(
     @PathParam("device") String deviceName, @PathParam("sensor") String sensor) {
   for (Device device : Kernel.getInstance().getDevices()) {
     if (device.getName().equals(deviceName)) {
       Thing thing = device.getThings().get(sensor);
       return thing.getLastValue();
     } else {
       return "Sensor not found";
     }
   }
   return "Device not found";
 }
Exemplo n.º 3
0
  @GET
  @Produces("text/html")
  @Path("/{device}/{sensor}")
  public String read(@PathParam("device") String deviceName, @PathParam("sensor") String sensor) {
    if (deviceName != null && sensor != null) {
      for (Device d : Kernel.getInstance().devices) {
        if (d.getName().equals(deviceName)) {
          try {
            return d.getThings().get(sensor).execute(sensor);

          } catch (Exception ex) {
            Logger.getLogger(Manager.class.getName())
                .log(
                    Level.SEVERE,
                    "Error sending Serial Message to {0}. {1}",
                    new Object[] {d.getName(), ex.getMessage()});
          }
        }
      }
    }
    return "not found";
  }