Package com.openhouseautomation.model

Examples of com.openhouseautomation.model.Sensor


    // String type = (String) parent.getProperty("type");
    Reading reading = ofy().load().fromEntity(entreading);
    if (reading == null) {
      log.log(Level.SEVERE, "null reading");
    }
    Sensor sensor = ofy().load().now(reading.getSensor());
    if (sensor == null) {
      log.log(Level.SEVERE, "null sensor");
    }
    String sentitydate = getDateString(reading.getTimestamp());
    String value = reading.getValue(); // value of reading
    emit(sensor.getType() + ":" + sensor.getId() + ":" + sentitydate, value);
    // emits the form: TEMPERATURE:38382834:20140417, 72
    // where TYPE:SENSORID:DATE,READING
    // } catch (EntityNotFoundException e) {
    // }
  }
View Full Code Here


    DataTable data = new DataTable();
    ArrayList cd = new ArrayList();
    try {
      // Fill the data table.
      cd.add(new ColumnDescription("date", ValueType.DATETIME, "Date"));
      Sensor sensor =
          ofy().load().type(Sensor.class).id(Long.parseLong(request.getParameter("id"))).now();
      log.log(Level.WARNING, "sensor={0}", sensor);
      if (sensor.getType() == Sensor.Type.TEMPERATURE || sensor.getType() == Sensor.Type.HUMIDITY) {
        cd.add(new ColumnDescription("high", ValueType.NUMBER, "High"));
        cd.add(new ColumnDescription("low", ValueType.NUMBER, "Low"));
      } else if (sensor.getType() == Sensor.Type.LIGHT) {
        cd.add(new ColumnDescription("nonzeroavg", ValueType.NUMBER, "Total"));
      } else if (sensor.getType() == Sensor.Type.WINDSPEED) {
        cd.add(new ColumnDescription("high", ValueType.NUMBER, "High"));
      }
      data.addColumns(cd);

      List<ReadingHistory> readings =
          ofy().load().type(ReadingHistory.class).ancestor(sensor).list();
      GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
      // without a timezone of GMT, you will get:
      // can't create DateTimeValue from GregorianCalendar that is not GMT.
      // and if you want your graph in a TZ other than GMT? Nope.
      for (ReadingHistory reading : readings) {
        cal.setTime(new Date(reading.getTimestamp().getTime()));
        if (sensor.getType() == Sensor.Type.TEMPERATURE || sensor.getType() == Sensor.Type.HUMIDITY) {
          data.addRowFromValues(cal, new Double(reading.getHigh()), new Double(reading.getLow()));
        } else if (sensor.getType() == Sensor.Type.LIGHT) {
          data.addRowFromValues(cal, new Double(reading.getAverage()));
        } else if (sensor.getType() == Sensor.Type.WINDSPEED) {
          data.addRowFromValues(cal, new Double(reading.getHigh()));
        }
      }
    } catch (final TypeMismatchException e) {
      log.log(Level.SEVERE, e.toString(), e);
View Full Code Here

      }
      log.info("1. authorization checked");
      String sensorid = request.getParameter("k");
      log.log(Level.INFO, "k={0}", sensorid);
      // load the sensor entity
      Sensor sensor = ofy().load().type(Sensor.class).id(Long.parseLong(sensorid)).now();
      if (sensor != null) {
        out.println(sensor.getId() + "=" + sensor.getLastReading() + ";" + sensor.getLastReadingDate().getTime() / 1000);
        log.log(Level.INFO, "sent:{0}={1};{2}", new Object[]{sensor.getId(), sensor.getLastReading(), sensor.getLastReadingDate().getTime() / 1000});
      } else {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Sensor not found");
      }
    }
  }
View Full Code Here

      log.log(Level.INFO, "k={0},v={1}", new Object[]{sensorid, sensorval});
      ofy().transact(new Work<Sensor>() {
        @Override
        public Sensor run() {
          Key<Sensor> sk = Key.create(Sensor.class, Long.parseLong(sensorid));
          Sensor sensor = ofy().load().now(sk);
          // set the value
          sensor.setLastReadingDate(new Date());
          sensor.setLastReading(sensorval);
          ofy().save().entity(sensor);
          log.log(Level.INFO, "saved sensor:{0}", sensor);
          Reading reading = new Reading();
          reading.setSensor(sk);
          reading.setTimestamp(new Date());
View Full Code Here

        if (cursor != null) {
          query = query.startAt(cursor);
        }
        QueryResultIterator<Sensor> iterator = query.iterator();
        while (iterator.hasNext()) {
          Sensor sens = iterator.next();
          out.println(sens.toString());
          tickler++;
        }
        cursor = iterator.getCursor();
        if (tickler == 0) {
          done = true;
View Full Code Here

    data.addColumns(cd);

    // Fill the data table.
    try {
      // TODO pass sensor id in as a parameter, then pass back values for that id
      Sensor sensor =
          ofy().load().type(Sensor.class).id(Long.parseLong(request.getParameter("id"))).now();
      Date cutoffdate = new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24 * 7));
      List<Reading> readings =
          ofy().load().type(Reading.class).ancestor(sensor).filter("timestamp >", cutoffdate)
              .list();
View Full Code Here

TOP

Related Classes of com.openhouseautomation.model.Sensor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.