Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By pingwing
#73780 Hi everybody!

I've posted my question already on github https://github.com/esp8266/Arduino/issues/4300, but maybe this is a better forum for this.
I'm trying to get data from my thermostat with an http.get() but I always get an error 307 (redirection). I'm starting to think that it is related to the https url I'm trying to connect to.

Is there somebody who had a similar issue, or knows how to solve the problem underneath?

Thanks in advance

Here is my code, in the last part you can see the connection with the server I'm trying to make:

Code: Select all#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266mDNS.h>

#define USE_SERIAL Serial

String accessurl = "https://api.home.nest.com/oauth2/access_token";
MDNSResponder mdns;

// My Network cred.
const char* ssid = "Blanked out";
const char* password = "Blanked out";

int gpio13Led = 13;
int gpio12Relay = 12;

void setup(void){
// preparing GPIOs
pinMode(gpio13Led, OUTPUT);
digitalWrite(gpio13Led, HIGH);

pinMode(gpio12Relay, OUTPUT);
digitalWrite(gpio12Relay, HIGH);

Serial.begin(115200);
delay(5000);
WiFi.begin(ssid, password);
Serial.println("");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
}
void loop(void){
Serial.println("Wifi Up - Test Start!");
delay(10000);
if((WiFi.status() != WL_CONNECTED)) {
Serial.println("wifi down");
return;
}

HTTPClient http;
//Here I gave the footprint along with the url. But I'm not sure if it works.
http.begin("https://developer-api.nest.com/", "87:CB:F2:E6:44:C0:AA:F2:4C:28:B2:97:85:70:18:92:45:1B:A4:57");

//http.addHeader("Cache-Control", "no-cache", true, true);
//http.addHeader("Postman-Token", "419da1fa-6070-3338-c215-8be740891136", true, true);
http.addHeader("Authorization", "Bearer c.blanked out", true, true);
http.addHeader("Host", "developer-api.nest.com", true, true);
http.addHeader("Content-Type", "application/json", false, true);



int httpCode = http.GET();   
Serial.println("request sent: \n");
Serial.println(httpCode); //Doesn't seem to work? I never see any outprint.
if (httpCode == HTTP_CODE_OK) {
   String payload = http.getString();
   Serial.printf("[HTTP] GET response: %s", payload.c_str());
 } else {
   String payload = http.getString();
   String loc = http.header("Location");
   Serial.printf("[HTTP] GE returned %d. kapot, error: %s; response: %s, new location: %s\n", httpCode, http.errorToString(httpCode).c_str(), payload.c_str(), loc.c_str());
   
 }
 http.end();

}