从 Arduino 调用 Nest API [英] Calling nest API from Arduino

查看:19
本文介绍了从 Arduino 调用 Nest API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Arduino 中的 C 代码调用 nest api 以获取室温.

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

当我使用 postman 调用 api 时,我得到了完美的响应:

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:

请求已发送请求是 HTTP/1.1 400 错误请求.

这是我的代码,任何人都可以帮助我我的请求有什么问题:

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");
  }

谢谢,

沙巴

推荐答案

如果您得到 400,您应该检查 URL 是否实际设置为 /.您的代码没有显示 url 变量的值.

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.

这篇关于从 Arduino 调用 Nest API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆