哇。天呐!我有回应了!你的提示使它工作@gre_gor。
我更改了主机名和端口,因为我的回复是这样的。
这是我的最终代码:
CODE:
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "xxxxx";
const char* password = "xxxxx";
const char* host = "firebase-apiserver10-tah01-iad01.dapi.production.nest.com";
const int httpsPort = 9553; //443;
const char* BearerKey = "xxxxx";
//declaring GPIO's
int gpio13Led = 13;
int gpio12Relay = 12;
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "87:CB:F2:E6:44:C0:AA:F2:4C:28:B2:97:85:70:18:92:45:1B:A4:57";
void setup() {
// preparing GPIOs
pinMode(gpio13Led, OUTPUT);
digitalWrite(gpio13Led, HIGH);
pinMode(gpio12Relay, OUTPUT);
digitalWrite(gpio12Relay, HIGH);
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
digitalWrite(gpio13Led, LOW);
} else {
Serial.println("certificate doesn't match");
}
String url = "/";
Serial.print("requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Content-Type: application/json\r\n" +
"Authorization: Bearer " + BearerKey + "\r\n\r\n"
);
Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
Serial.println(line);
if (line == "\r") {
Serial.println("headers received");
break;
}
}
while (client.available()) {
String line = client.readStringUntil('\n');
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
}
}
void loop() {
}
串行监视器:
connecting to xxxxx
...........
WiFi connected
IP address:
xxxxx
connecting to firebase-apiserver10-tah01-iad01.dapi.production.nest.com
certificate doesn't match
requesting URL: /
request sent
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, max-age=0
Pragma: no-cache
Connection: close
content-length: 8060
headers received
reply was:
==========
{"devices":{"thermostats":{"exxx":{"humidity":40,"locale":"nl-NL","temperature_scale":"C","is_using_emergency_heat":false,"has_fan":false,"software_version":"5.6.6-4","has_leaf":true,"where_id":"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA","device_id":"e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU","name":"Downstairs","can_heat":true,"can_cool":false,"target_temperature_c":15.0,"target_temperature_f":59,"target_temperature_high_c":24.0,"target_temperature_high_f":75,"target_temperature_low_c":20.0,"target_temperature_low_f":68,"ambient_temperature_c":15.5,"ambient_temperature_f":61,"away_temperature_high_c":24.0,"away_temperature_high_f":76,"away_temperature_low_c":8.5,"away_temperature_low_f":48,"eco_temperature_high_c":24.0,"eco_temperature_high_f":76,"eco_temperature_low_c":8.5,"eco_temperature_low_f":48,"is_locked":false,"locked_temp_min_c":20.0,"locked_temp_min_f":68,"locked_temp_max_c":22.0,"locked_temp_max_f":72,"sunlight_correction_active":false,"sunlight_correction_enabled":true,"structure_id":"vEJb634MNif-xxx{"access_token":"xxxx","client_version":2,"user_id":"xxxx"}}
==========
closing connection
奇怪的是,我的指纹不匹配,但它仍然继续向我提供信息。
下一步是阅读此响应并使用我想要的数据。 :-)