Moe
Moe

Reputation: 185

Nest thermostat API: Connection time out after establishing a request using the retrieved access_token

I am making an Android app to talk to NEST a thermostat using the newly released API. I am following the instruction provided in this page: https://developer.nest.com/documentation/how-to-auth.

I have got it working up to the point that I receive the access_token successfully. However using that access_token and establishing an HTTP GET request to https://developer-api.nest.com/devices.json?auth={access_token} I get a connection timeout exception!

@mccv Here is my code:

private void make_REST_call(String access_token) {

    String access_token_uri = "https://developer-api.nest.com/devices.json?auth="+access_token;

    try {
        URI uri = new URI(access_token_uri);

        // Set the connection timeout value to X seconds (30000 milliseconds)
        final HttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, 100000);  // In miliseconds
        httpclient = new DefaultHttpClient(httpParams);
        HttpGet httpget = new HttpGet();
        httpget.setURI(new URI(access_token_uri));

        // Execute HTTPs GET request
        Long reqTime = System.currentTimeMillis();
        Log.d(tag + " make_REST_call", " reqTime time= " + reqTime);

        HttpResponse response = null;

        try {
            response = httpclient.execute(httpget);
            Log.d(tag + " make_REST_call", " response is= " + response.getEntity());
        }
        catch (Exception e) {
            e.printStackTrace();
            Log.e(tag + " make_REST_call", e.toString());
        }

        Long resTime = System.currentTimeMillis();
        Log.d(tag + " make_REST_call", " response time= " + (resTime - reqTime));

    }
    catch (Exception e) {
        Log.e(access_token_uri, e.toString());
        e.printStackTrace();
    }
}

Upvotes: 1

Views: 627

Answers (2)

Moe
Moe

Reputation: 185

I figured out what was wrong.

There were actually a firewall on my way to get to the server with a blocked port. By redirecting my httpclient to a proxy, I bypassed it, so the problem was solved.

Upvotes: 1

Lev
Lev

Reputation: 11

You may generate more debugging with:

final Config defaultConfig = Firebase.getDefaultConfig
defaultConfig.setLogLevel(Logger.Level.DEBUG)

Upvotes: 0

Related Questions