[ https://jira.fiware.org/browse/HELP-15411?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Fernando Lopez resolved HELP-15411. ----------------------------------- Resolution: Done > [fiware-stackoverflow] How to send commands to iot-sensors using android application > ------------------------------------------------------------------------------------ > > Key: HELP-15411 > URL: https://jira.fiware.org/browse/HELP-15411 > Project: Help-Desk > Issue Type: Monitor > Components: FIWARE-TECH-HELP > Reporter: Backlog Manager > Assignee: Jason Fox > Labels: fiware, fiware-orion > > 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); > } > } -- This message was sent by Atlassian JIRA (v6.4.1#64016)
You can get more information about our cookies and privacy policies clicking on the following links: Privacy policy Cookies policy