-2

I am trying to call an nest api to get room temperature using C code in Arduino.

When I call the api using postman, I get perfect response:

enter image description here

However when I write the code to get the temperature data, I get the following response:

request sent The request is HTTP/1.1 400 Bad Request.

Here is my code, can anyone help me what's wrong with my request:

const char* ssid = "linksys";
const char* password = "XXXXX";

const char* host = "firebase-apiserver07-tah01-iad01.dapi.production.nest.com"; // "developer-api.nest.com"; // "api.github.com";
const int httpsPort = 9553; //443 9553;
String url = "";


.......
.......
.......

 if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  } else {
        client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Authorization: Bearer c.SbsgvTBcsJREMOVED_CODE_FOR_SECURITY_REASON\r\n" +
               "Content-Type: application/json\r\n\r\n"
               );

        Serial.println("request sent");
  }

Thanks,

Shab

2
  • 1
    1) Don't post images of text. 2) Arduino is not C and not exactly C++. Commented Apr 7, 2017 at 2:03
  • Probably because you need a secure connection. Commented Apr 7, 2017 at 12:38

2 Answers 2

1

If you're getting a 400, you should check that the URL is actually set to /. Your code doesn't have the value of the url variable shown.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Femi for the promot response and sorry that I missed that part of the code. url is set to empty string because when I put "/" I get no response. Not even bad request.
@user1952378 well, empty string is very definitely wrong. It causes you to output something that isn't a syntactically valid HTTP request... which would explain the "bad request" :)
@hobbs, I see, but why putting '/' doesn't even get any response?
Not quite familiar with the Nest API, but you should check the path in Postman, and make sure you use that for URL: an empty response typically means you didn't ask for anything in particular, or possibly you got a redirect. Check if there are response headers that indicate you were redirected to a different url.
0

I figured in my case there was a delay in receiving the response. I just had to wait to get the response. And for sure url has to be "/"

String url = "/"

Thanks, Shab

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.