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);
}
}
Activity
Field | Original Value | New Value |
---|---|---|
Component/s | FIWARE-TECH-HELP [ 10278 ] |
Status | Open [ 1 ] | In Progress [ 3 ] |
Status | In Progress [ 3 ] | Answered [ 10104 ] |
Assignee | Jason Fox [ jason.fox ] |
HD-Enabler | IDAS [ 10884 ] | |
Description |
Created question in FIWARE Q/A platform on 01-02-2019 at 18:02 {color: red}Please, ANSWER this question AT{color} 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); } } |
Created question in FIWARE Q/A platform on 01-02-2019 at 18:02
{color: red}Please, ANSWER this question AT{color} 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); } } |
Resolution | Done [ 10000 ] | |
Status | Answered [ 10104 ] | Closed [ 6 ] |
Fix Version/s | 2021 [ 12600 ] |