Issues with NetworkClientSecure and HTTPClient on ESP32-C6 (301 Error and Missing Files for HTTPS GET Requests)

Hello everyone,

I’m currently trying to perform a GET request to an HTTPS server to download files using an ESP32-C6 on PlatformIO, but I’ve hit a few obstacles. Here’s a summary:

  1. WiFiClientSecure Compatibility
    The WiFiClientSecure library works fine in the Arduino IDE for HTTPS requests, but in PlatformIO, it seems unsupported and possibly deprecated. Following Espressif’s documentation, I tried using NetworkClientSecure, which is suggested as a replacement. However, it throws this error:

    src/main4.cpp:4:10: fatal error: NetworkClientSecure.h: No such file or directory

  2. HTTPClient and HTTPS GET Request (301 Error):
    After the issue with NetworkClientSecure, I attempted the HTTPClient library. When performing a GET request to the HTTPS server, I receive a 301 Moved Permanently error. The URL is valid and works with WiFiClientSecure in Arduino IDE, so I know it’s correct.

  3. Trying to Use Network Library:
    Since NetworkClientSecure worked with the Arduino IDE, I downloaded it and its required dependency, the Network library, from (arduino-esp32/libraries at 07c510e3adc0dfe4a284d0f47d6ecd07286c712f · espressif/arduino-esp32 · GitHub). However, when compiling, I get an error indicating that it can’t find the following include:

    #include “network_provisioning/network_config.h”

    I haven’t been able to locate network_config.h or find where it should come from.

  4. Using mbedtls:
    As a last attempt, I tried calling mbedtls/ssl.h directly, but I encountered an undefined reference error:

    undefined reference to `mbedtls_ssl_init’

Currently, I don’t have any dependencies in lib_deps in my platformio.ini file. I’d appreciate any help or guidance on how to make HTTPS GET requests work on the ESP32-C6 with PlatformIO.

Thank you for your time and assistance!

1 Like

Unfortunately you do not show the content of your platformio.ini

The ESP32-C6 is only supported from Espressif32 Arduino 3.x onwards.
There is no official support for the Arduino 3.x framework for PlatformIO.
You will therefore most likely still be using the old Arduino 2.x core in PlatformIO - just a guess.

Please show the content of your platformio.ini and name the version of the installed Espressif32 platform

A simple solution is to use pioarduino.

Hi, thank you so much for replying

Here is my platformio.ini

; PlatformIO Project Configuration File

;

; Build options: build flags, source filter

; Upload options: custom upload port, speed and extra flags

; Library options: dependencies, extra library storages

; Advanced options: extra scripting

;

; Please visit documentation for the other options and examples

; Redirecting...

[env:esp32-c6]

platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.12.10/platform-espressif32.zip

framework = arduino

board = esp32-c6-devkitm-1

monitor_speed = 115200

I’m not sure if there’s another way to make HTTPS requests with this framework using an ESP32-C6. Thank you very much for your time, and have an excellent day!

I’m also encountering an issue when trying to use the library from the Git repository you mentioned and during the build process in PlatformIO, I’m getting the error:

undefined reference to 'lwip_hook_ip6_input'

:frowning_face:

No, that’s not the platform i mentioned. Try:

platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.07/platform-espressif32.zip

The BasicHttpsClient example works without issues using pioarduino (Arduino 3.0.7) on an esp32-c6-devkitm-1 board.

Hi!

Here’s the current setup I have in my platform.ini file:

; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed, and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Documentation for additional options and examples:
; https://docs.platformio.org/page/projectconf.html

[env:esp32-c6]
; platform = https://github.com/pioarduino/platform-espressif32.git
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.07/platform-espressif32.zip
framework = arduino
board = esp32-c6-devkitm-1
monitor_speed = 115200

For my code, I’m using the following libraries:

#include "LittleFS.h"
#include "Update.h"
#include <WiFi.h>
#include "HTTPClient.h"
#include <ArduinoOTA.h> // Only for InternalStorage

String server_url = "https://www.diainternacionalde.com";
WiFiClient wifiClientSSL;  // HTTPS
HTTPClient http;

char* ssid = "my_ssid";
char* password = "my_password";

void getFileFromServer() {
    http.begin(wifiClientSSL, server_url);
    http.setTimeout(5000);
    int httpCode = http.GET();  // Make GET request
    if (httpCode > 0) {
        Serial.printf("[HTTP] GET... code: %d\n", httpCode);
    } else {
        Serial.printf("HTTP GET request failed, error: %s\n", http.errorToString(httpCode).c_str());
    }

    String payload = http.getString();
    Serial.println(payload);

    http.end();
}

void connectWiFi() {
    Serial.println("Connecting to WiFi");
    WiFi.begin(ssid, password); 
    while (WiFi.status() != WL_CONNECTED) {
        Serial.println("Connection Failed!");
        delay(5000);
    }
    Serial.println("Connected to the WiFi");
}

void setup() {
    Serial.begin(115200);
    connectWiFi();

    if (!LittleFS.begin(true)) {
        Serial.println("SPIFFS Mount Failed");
        return;
    }
}

void loop() {
    getFileFromServer();
    // Additional code for updates or normal loop tasks
}

I’m currently encountering an error:

400 Bad Request: The plain HTTP request was sent to HTTPS port

This is a valid URL, so I’m not sure if this issue stems from a library configuration or an error in my code. Any ideas on what could be causing this issue or how to address it?

You have configure and pass in a WiFiClientSecure instance to the HTTPClient’s constructor. Using just an instance of a WiFiClient ends up in a unsecure http connection instead https!

Check the example I have posted above.

Thank you very much, the example you gave me and the platform.ini work perfectly.

Thank you so much and have a nice day!! :grin: