Exemplo n.º 1
0
    @Override
    protected String doInBackground(String... params) {
      // TODO Auto-generated method stub
      JSONParser jParser = new JSONParser();
      ArrayList<NameValuePair> parames = new ArrayList<NameValuePair>();
      parames.add(new BasicNameValuePair("id_lampe", data.get(lightindex).getId_equip()));
      parames.add(new BasicNameValuePair("etat", lightState + ""));
      parames.add(new BasicNameValuePair("auto", autostate + ""));

      JSONObject json =
          jParser.makeHttpRequest(
              new Settings(Lights.this).getHost() + "/Domotique/Light.php", "GET", parames);

      try {
        int success = json.getInt("success");

        if (success == 1) {

          message = json.getString("message");
          return "success";

        } else {
          message = json.getString("message");
          return "fail";
        }
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return null;
    }
Exemplo n.º 2
0
    @Override
    protected String doInBackground(String... params) {
      // TODO Auto-generated method stub
      jParser = new JSONParser();

      ArrayList<NameValuePair> parames = new ArrayList<NameValuePair>();
      parames.add(new BasicNameValuePair("id_user", new Settings(Lights.this).getID()));
      parames.add(
          new BasicNameValuePair("id_maison", new Settings(Lights.this).getselectedhouse()));

      JSONObject json =
          jParser.makeHttpRequest(
              new Settings(Lights.this).getHost() + "/Domotique/LightState.php", "GET", parames);
      Log.d("shutter", json.toString());
      try {
        int success = json.getInt("success");

        if (success == 1) {

          JSONArray lampes = json.getJSONArray("lampe");
          Log.i("allobjectlampe", lampes.toString());
          for (int i = 0; i < lampes.length(); i++) {
            JSONObject lamp = lampes.getJSONObject(i);

            String id_lampe = lamp.getString("id_lampe");
            Log.i("id_shutter", id_lampe);
            String id_rm = lamp.getString("id_rm");
            String des_rm = lamp.getString("des_rm");
            int temp_rm = lamp.getInt("temp_rm");
            int himu_rm = lamp.getInt("himu_rm");
            int etat_lampe = lamp.getInt("etat_lampe");
            Lampe lp =
                new Lampe(id_lampe, "LAMPE", etat_lampe, new Room(id_rm, des_rm, temp_rm, himu_rm));

            // if (Integer.parseInt(sh_s)==1)
            data.add(lp);
          }

          message = json.getString("message");
          return "success";

        } else {
          message = json.getString("message");
          return "fail";
        }
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return null;
    }