Example #1
0
  @Override
  protected ArrayList<Sensor> doInBackground(String... params) {
    // TODO Auto-generated method stub
    Log.d("ask", "running");

    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("_id", userId));
    String result = null;
    // String url = "http://10.189.93.95:3000/auth/login";
    String url = "http://smartwaterwatch.mybluemix.net/sensor/availableSensors";
    BufferedReader in = null;
    StringBuffer sb = new StringBuffer("");
    try {
      Log.d("Email in Home", "" + userId);
      HttpClient client = new DefaultHttpClient();
      HttpPost request = new HttpPost(url);
      Log.d("2", "");
      UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
      Log.d("3", "");
      request.setEntity(formEntity);
      Log.d("4", "");
      HttpResponse response = client.execute(request);
      Log.d("5", "");
      in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
      Log.d("6", "");
      String line = "";
      String NL = System.getProperty("line.separator");
      while ((line = in.readLine()) != null) {
        sb.append(line + NL);
      }
      in.close();

    } catch (Exception e) {

    }
    result = sb.toString();
    Log.d("response of smartwatch", "" + result);

    ArrayList<Sensor> sensorArrayList = new ArrayList<>();

    try {
      JSONArray sensorArray = new JSONArray(result);
      Log.d("SensorArray", "" + sensorArray);
      for (int i = 0; i < sensorArray.length(); i++) {
        JSONObject sensorObject = sensorArray.getJSONObject(i);
        Sensor sensor = new Sensor();
        sensor.setSensorName(sensorObject.getString("sensorName"));
        sensor.setSensorType(sensorObject.getString("sensorType"));
        sensor.setSensorStatus(sensorObject.getString("activated"));
        sensorArrayList.add(sensor);
      }
    } catch (Exception e) {
      Log.d("Exception", "" + e);
    }

    return sensorArrayList;
  }
Example #2
0
  public static void genDummieData() {

    Session ses = HibernateUtil.getSessionFactory().openSession();
    ses.beginTransaction();
    // du data
    Location l1 = new Location();
    l1.setLocationName("Ubicacion principal");
    Location l2 = new Location();
    l2.setLocationName("Cochera");
    Location l3 = new Location();
    l3.setLocationName("Patio");
    ses.save(l1);
    ses.save(l2);
    ses.save(l3);

    User u1 = new User();
    u1.setUserName("_Leafhouse");
    u1.setUserLeafHouse(true);
    u1.setUserPassword("weaadasdad");
    u1.setUserEmail("*****@*****.**");
    u1.setUserAdmin(true);

    ses.save(u1);

    Sensor s1 = new Sensor();
    s1.setSensorLocation(l3);
    s1.setSensorName("Sensor puerta");
    s1.setSensorGpioPin(1);
    s1.setSensorType(SensorType.EVENT_FIRED);
    ses.save(s1);

    for (int i = 0; i < 20; i++) {
      SensorState ss = new SensorState();
      ss.setFireDate(Calendar.getInstance());
      ss.setSecurityBreach(false);
      ss.setSensor(s1);
      ss.setUser(u1);
      ses.save(ss);
    }

    SecurityState sss1 = new SecurityState();
    sss1.setSecurityEnabled(true);
    sss1.setUser(u1);
    sss1.setModifiedDate(Calendar.getInstance());
    ses.save(sss1);

    SecurityState sss2 = new SecurityState();
    sss2.setSecurityEnabled(false);
    sss2.setUser(u1);
    sss2.setModifiedDate(Calendar.getInstance());
    ses.save(sss2);

    // end
    ses.getTransaction().commit();
    ses.close();
  }