Cheetohzzz
Cheetohzzz

Reputation: 1

Issue with HTTPS connection in ESP32 Google Photo Clock project

I'm working on a Google Photo Clock project using an ESP32 board and encountering an issue with establishing an HTTPS connection. Here's the relevant code and the error I'm getting:

Code:

`




// WiFi and HTTPS setup
#if defined(ESP32)
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>

const char* rootCACertificate = \
"-----BEGIN CERTIFICATE-----\n" \
/* ... */ \
"-----END CERTIFICATE-----\n";

WiFiMulti WiFiMulti;
WiFiClientSecure *client = new WiFiClientSecure;

// ... 

void setup() {
    // ...
    
    // init WiFi
    WiFi.mode(WIFI_STA);
    WiFiMulti.addAP(SSID_NAME, SSID_PASSWORD);
    while (WiFiMulti.run() != WL_CONNECTED) {
        delay(500);
    }

    // init HTTPClient
    client->setCACert(rootCACertificate);
}

void loop() {
    // ...

    HTTPClient https;
    https.begin(*client, GOOGLE_PHOTO_SHARE_LINK);
    https.setTimeout(HTTP_TIMEOUT);
    int httpCode = https.GET();

    // ...
}

This is what i got as the error on serial monitor:

https://photos.app.goo.gl/_____________
[HTTPS] begin...
[HTTPS] GET...
[HTTPS] return code: -1
[HTTPS] GET... failed, error: connection refused

I'm able to connect to the Wi-Fi network successfully, but the HTTPS connection to the Google Photos share link fails with the error "connection refused". I've double-checked the share link, and it seems to be correct. What could be causing this issue, and how can I resolve it?

Upvotes: 0

Views: 100

Answers (1)

rrrandolphhh
rrrandolphhh

Reputation: 15

#define HTTPC_ERROR_CONNECTION_REFUSED (-1)

^ this is the error you're getting using the HTTPClient library.

Without your link it's hard to know if the request will even work outside of your embedded project.

I 100% recommend downloading and using Postman to confirm you're formatting your request correctly. It's real easy to learn and great for testing GET vs POST requests and what they return. I use it for all of my HTTP arduino/esp32 projects

Otherwise --

This could be from a number of things, such as your server not being setup correctly to receive the request, or your request not being formatted correctly -- however I just dealt with this issue after it was already working for a while.

It has something to do with the new version holding onto the connection between repeated requests. If you don't have one in here, you absolutely need a delay after a successful connection or new connection attempt. You want it to be at least a few seconds.

Check the version of your ESP32 board in board manager. A few things broke in 3.0+ I reverted to v2 and it miraculously started working again for me.

Upvotes: 0

Related Questions