Hello,
I'm trying to read de sensors values of Arduino and sent this by wifi to android.
I make a httpget request to Arduino, and it sent me a page with this structure:
{ "temperature": "22"} for example...
I read this in webnavigator in notebook and it appears in browser.
But the Android give an error: W/System.err﹕ org.apache.http.client.ClientProtocolException
The Arduino sent this:
sensor.read11(dht_dpin);
server.println("HTTP 1.1/200 OK");
server.println("Content-Type: application/json");
server.println();
server.print("{ \"temperatura\": \"");
server.print(sensor.temperature, 1);
server.println(" \" }");
and try to read with this in Android:
public static void getJson(final String url) {
new Thread(new Runnable() {
@Override
public void run() {
Object retorno = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(url));
HttpResponse response = httpclient.execute(request);
InputStream content = response.getEntity().getContent();
Reader reader = new InputStreamReader(content);
Gson gson = new Gson();
retorno = gson.fromJson(reader, HashMap.class);
content.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
Can someone helpme?