Hieromon / AutoConnect

An Arduino library for ESP8266/ESP32 WLAN configuration at runtime with the Web interface
https://hieromon.github.io/AutoConnect/
MIT License
911 stars 190 forks source link

WiFiClientSecure is not working with AutoConnect #611

Closed linaspasv closed 1 year ago

linaspasv commented 1 year ago

Hello, so I have this odd issue where WiFiClientSecure can't connect to anything when AutoConnect Portal(webServer); is added into the code. Here is a small test snippet to reproduce the issue:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <AutoConnect.h>

ESP8266WebServer webServer;
AutoConnect Portal(webServer);

void setup() {
    Serial.begin(115200);
    while (! Serial);

    WiFi.begin("....", ".....");

    Serial.println("");
    Serial.println("");

    while (WiFi.status() != WL_CONNECTED) {
        Serial.print(".");
        // wait 1 second for re-trying
        delay(1000);
    }
}

void loop() {
    IPAddress remote_addr;
    WiFi.hostByName("example.com", remote_addr);
    Serial.println(remote_addr.toString());

    WiFiClient wifiClient;
    wifiClient.connect(remote_addr, 80);
    Serial.println("[HTTP] " + String(wifiClient.connected() ? "connected" : "not connected"));

    WiFiClientSecure wifiClientSecure;
    wifiClientSecure.setInsecure();
    wifiClientSecure.connect(remote_addr, 443);
    Serial.println("[HTTPS] " + String(wifiClientSecure.connected() ? "connected" : "not connected"));

    delay(5000);
}
linaspasv commented 1 year ago

It looks like the issue was lack of heap memory for ESP8266 but the following flag for platformio solved the problem.

-D PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED