Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-15411

[fiware-stackoverflow] How to send commands to iot-sensors using android application

    Details

      Description

      Created question in FIWARE Q/A platform on 01-02-2019 at 18:02
      Please, ANSWER this question AT https://stackoverflow.com/questions/54484127/how-to-send-commands-to-iot-sensors-using-android-application

      Question:
      How to send commands to iot-sensors using android application

      Description:
      I setup an the fiware201:iot-sensor inside an Ubuntu 16.04 instance on FIWARE-lab , and am currently building an android application to be able to send commands to access the dummy devices provided by the context provider , i setup a class that formats the data and sends it to the endpoint provided by the tutorial , but i cant seem to get it to work , i get a 422 error whenever i try to send any command.

      additional details:
      i am using volley -> a package to send post,get requests in android
      fiware-lab region : crete

      here is the code:

      import android.content.Context;
      import android.util.Log;

      import com.android.volley.AuthFailureError;
      import com.android.volley.Request;
      import com.android.volley.RequestQueue;
      import com.android.volley.Response;
      import com.android.volley.VolleyError;
      import com.android.volley.toolbox.StringRequest;
      import com.android.volley.toolbox.Volley;

      import java.util.HashMap;
      import java.util.Locale;
      import java.util.Map;

      public class ApiController {
      private String urlString
      public String serverResponse;
      private RequestQueue queue ;

      public ApiController(Context context)

      { //set context variables if required serverResponse = ""; queue = Volley.newRequestQueue(context); }

      public void setDevice(String device)

      { this.device = device; urlString = "http://myFloatingIp:3001/iot/" +"Lamp001"; // URL to call }

      public void send() {
      String uri = String.format(Locale.US, urlString);

      // Request a string response from the provided URL.
      StringRequest stringRequest = new StringRequest(Request.Method.POST,uri,
      new Response.Listener<String>() {
      @Override
      public void onResponse(String response)

      { serverResponse = response; }

      }, new Response.ErrorListener() {
      @Override
      public void onErrorResponse(VolleyError error)

      { serverResponse = "Error"; }

      }
      ) {
      @Override
      protected Map<String, String> getParams() throws AuthFailureError

      { Map<String,String> params=new HashMap<String,String>(); params.put("data","urn:ngsi-ld:Lamp:001"@On"); return params; }

      @Override
      public Map<String, String> getHeaders() throws AuthFailureError

      { Map<String,String> headers=new HashMap<String,String>(); headers.put("Content-Type","text/plain"); return headers; }

      };

      // Add the request to the RequestQueue.
      queue.add(stringRequest);
      }

      }

        Activity

        Hide
        backlogmanager Backlog Manager added a comment -

        2019-02-01 21:05|CREATED monitor | # answers= 1, accepted answer= False

        Show
        backlogmanager Backlog Manager added a comment - 2019-02-01 21:05|CREATED monitor | # answers= 1, accepted answer= False
        Hide
        backlogmanager Backlog Manager added a comment -

        2019-02-02 00:06|UPDATED status: transition Answer| # answers= 1, accepted answer= False

        Show
        backlogmanager Backlog Manager added a comment - 2019-02-02 00:06|UPDATED status: transition Answer| # answers= 1, accepted answer= False
        Hide
        backlogmanager Backlog Manager added a comment -

        2019-02-02 03:05|UPDATED status: transition Answered| # answers= 1, accepted answer= False

        Show
        backlogmanager Backlog Manager added a comment - 2019-02-02 03:05|UPDATED status: transition Answered| # answers= 1, accepted answer= False

          People

          • Assignee:
            jason.fox Jason Fox
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: