Calling nest API from Arduino

半城伤御伤魂 提交于 2019-12-13 23:58:33

问题


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:

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


回答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.




回答2:


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



来源:https://stackoverflow.com/questions/43267690/calling-nest-api-from-arduino

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!