Calling nest API from Arduino

2019-09-21 09:42发布

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

标签: arduino
2条回答
干净又极端
2楼-- · 2019-09-21 10:05

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

查看更多
男人必须洒脱
3楼-- · 2019-09-21 10:16

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.

查看更多
登录 后发表回答