I cannot get my code to set the target temperature (in Android). The code I show below receives an OK status (200) along with the current temperature as the payload. I would expect to have received the new temperature I wrote (65degF). I am using the url:
https://developer-api.nest.com/devices/thermostats/THERMOSTAT-ID/target_temperature_f?auth=AUTH CODE
with my thermostat id and authentication code in place. I also have read and write permissions for my client. When I execute a similar request in a Chrome extension I have, the temperature gets set correctly on the thermostat. Can anyone pinpoint what I'm missing here? Commented out code shows a couple of the things I've tried.
Thanks.
InputStream is = null;
String result = "";
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPut httpPut = new HttpPut(url);
httpPut.addHeader("Content-Type", "application/json");
httpPut.addHeader("Accept", "application/json");
//httpPut.addHeader("Connection", "keep-alive");
httpclient.getParams().setBooleanParameter("http.protocol.expect-continue",false);
//value.setContentType("application/json");
httpPut.setEntity(new StringEntity("65");
HttpResponse response = httpclient.execute(httpPut);
HttpEntity entity = response.getEntity();
is = entity.getContent();
int statusCode = response.getStatusLine().getStatusCode();
Log.d("StatusCode",Integer.toString(statusCode));
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
// Convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
Log.d("Result",result);
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}