Details
-
Type:
Monitor
-
Status: Closed
-
Priority:
Major
-
Resolution: Done
-
Affects Version/s: None
-
Fix Version/s: 2021
-
Component/s: FIWARE-TECH-HELP
-
Labels:
-
HD-Enabler:IDAS
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)
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error)
}
) {
@Override
protected Map<String, String> getParams() throws AuthFailureError
@Override
public Map<String, String> getHeaders() throws AuthFailureError
};
// Add the request to the RequestQueue.
queue.add(stringRequest);
}
}
2019-02-01 21:05|CREATED monitor | # answers= 1, accepted answer= False