Skip to content

Https and fasled #5365

Closed
Closed

Description

@patrice916

Board / MCU

ESP32

LED Chipset

WS2812B / NeoPixel

FastLED Version

3.10.10

Arduino / PlatformIO version

Arduino 2.3.11

Operating System

Windows

Description

I'm sorry, but there's a problem between FastLED and HTTPS with the latest
version of Fastled 3.10.10 and Expressive version 3.3.12 The connection returns a 200
code on the first loop iteration, but then returns -1.
However, it works with Expressive version 2.0.17 and FastLED version 6.9.0.

Steps to reproduce

yes

Minimal sketch

#include "FastLED.h"
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>

WiFiMulti wifiMulti;

const char*    ssid = "XXXXXXXXXXX";                 // your network SSID (name)
const char*    password = "xxxxxxxxxxxxxxxxx";       // your network password
const String  host = "https://aviationweather.gov/api/data/metar?format=json&ids=";


// Define Leds
#define No_Stations          35      // Number of Stations also Number of LEDs
#define DATA_PIN              5      // Connect to pin D5/P5 with 330 to 500 Ohm Resistor
#define LED_TYPE         WS2812      // WD2811 or WS2812 or NEOPIXEL
#define COLOR_ORDER         GRB      // WD2811 are RGB or WS2812 are GRB
#define BRIGHTNESS           10      // Master LED Brightness (<12=Dim 20=ok >20=Too Bright/Much Power)



// Define STATIONS & Global Variables   
const std::vector<String> Stations {    //   << Set Up   - Do NOT change this line
  "NULL, STATION NAME         ",        // 0 << Reserved - Do NOT change this line
  "LPPT, LISBONE, GA          ",        // 1
  "LEMD, MADRID, GA           ",        // 2
  "LEVC, VALENCE, GA          ",        // 3
  "LEBL, BARCELONE, GA        ",        // 4
  "LFBO, TOULOUSE, GA         ",        // 5
  "LFMT, MONTPELLIER, GA      ",        // 6
  "LFTW, UZES NIMES, GA       ",        // 7
  "LFML, MARSEILLE, GA        ",        // 8
  "LFMN, NICE, GA             ",        // 9
  "LFKJ, AJACCIO, GA          ",        // 10
  "LIEE, CAGLIARI, GA         ",        // 11
  "LIRN, NAPLES, GA           ",        // 12
  "LIRP, PISE, GA             ",        // 13
  "LIPZ, VENISE, GA           ",        // 14
  "LIMC, MILAN, GA            ",        // 15
  "LSGG, GENEVE, GA           ",        // 16
  "LFLL, LYON, GA             ",        // 17
  "LFLC, CLERMONT FERRAND, GA ",        // 18
  "LFPO, ORLY, GA             ",        // 19
  "LFPG, CDG, GA              ",        // 20
  "LFST, STRASBOURG, GA       ",        // 21
  "LSZH, ZURICH, GA           ",        // 22
  "EDDM, MUNICH, GA           ",        // 23
  "EDDF, FRANKFURT, GA        ",        // 24
  "ESGG, GOTEBORG, GA         ",        // 25
  "EHAM, AMSTERDAM, GA        ",        // 26
  "EGLL, LONDRE, GA           ",        // 27
  "EIDW, DUBLIN, GA           ",        // 28
  "LFRC, CHERBOURG, GA        ",        // 29
  "LFRB, BREST, GA            ",        // 30
  "LFRZ, STNAZAIRE, GA        ",        // 31
  "LFBH, LAROCHELLE, GA       ",        // 32
  "LFBD, BORDEAUX, GA         ",        // 33
  "LFBA, AGEN, GA             ",        // 34
  "LFBZ, BIARRITZ, GA         ",        // 35
}; 

String metar;          // Raw METAR data                                     // << Do NOT change this line

String         rem[No_Stations + 1];  // Remarks
String        wind[No_Stations + 1];  // wind speed
String    category[No_Stations + 1];  // NULL   VFR    MVFR   IFR    LIFR
//..............................................Black  Green   Blue   Red    Magenta



void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED){
    delay(300);                          // Wait a little bit
  }
  WiFi.mode(WIFI_STA);
  wifiMulti.addAP(ssid, password);

}

void loop() {
String urls = "";
  for (int j = 1; j <= No_Stations; j++) {
      String station = Stations[j].substring(0, 5);
      urls = urls + String (station);
  }
  int len = urls.length();
  urls = urls.substring(0, len - 1);
  if (wifiMulti.run() == WL_CONNECTED) {
  	WiFiClientSecure client;
  	client.setInsecure();
  	HTTPClient https;
  	if (https.begin(client, host + urls)) {
      https.addHeader("Connection", "close"); 
  		metar = "";
  		int httpCode = https.GET();
      Serial.println(httpCode);
  		if (httpCode == HTTP_CODE_OK) {
      		metar = https.getString();
  		}
  	https.end();
    } else {
      delay(5000);
      return;
    }
  } 
delay(10000);

}

Serial / debug output

200
200
-1
-1
-1

Checklist

  • I have searched existing issues for duplicates
  • I have tested with the latest FastLED release or git master
  • I can reproduce this with a minimal sketch

Activity

  1. added
    status: triage
    type: bug
    on Nov 21, 2026
  2. added
    sanitized
    on Nov 21, 2026
  3. zackees commented on Nov 21, 2026

    @zackees
    Member

    Thanks for the report. Your sketch includes FastLED.h but never calls FastLED.addLeds or FastLED.show. In that case FastLED creates no driver, DMA buffer or lock at runtime, so it is unlikely to interfere with HTTPS directly. The upgrade also moved from ESP32 Arduino core 2.0.17 to 3.3.12 at the same time, which is the larger change. To narrow it down, could you:

    1. With core 3.3.12, remove #include "FastLED.h" (and the FastLED library) and check whether the second request still returns -1.
    2. On each loop, print ESP.getFreeHeap(), ESP.getMaxAllocHeap() and https.errorToString(httpCode). A -1 after the first successful request is often mbedTLS failing to allocate a new session.
    3. Confirm the earlier FastLED version that worked ("6.9.0" is not a FastLED release; was it 3.9.x?).

    If the failure only happens with the include present, please attach the full sketch (without credentials), and we will compare the linked hooks and RAM use.

  4. patrice916 commented on Nov 21, 2026

    @patrice916
    Author

    I’ve found the problem: on the first iteration, the program uses the router’s IPv6 address and it works, but for some reason, it gets stuck afterward.
    However, if I use WiFi.setDNS(1,1,1,1), the issue is resolved—though it’s not a very clean solution.

  5. added
    sanitized
    and removed
    sanitized
    on Nov 21, 2026
  6. zackees commented on Nov 21, 2026

    @zackees
    Member

    Reproduction attempt and root-cause analysis

    Summary: I could not get FastLED to cause this. With Arduino-ESP32 3.3.12, the same HTTPS loop returns 200 every time, whether or not FastLED.h is included, on both FastLED 3.10.10 and current master.

    What #include "FastLED.h" changes in your sketch

    Your sketch never calls addLeds/show. I built it for esp32dev on core 3.3.12 with and without the include and diffed the two linked images:

    • Static RAM (.data + .bss): +20 bytes. FastLED takes no heap away from mbedTLS.
    • Static constructors: CFastLED::CFastLED() and two pointer initialisers. They store constants only. They start no task, no allocation and no hardware.
    • One real runtime difference: on cores 3.3.2–3.3.12, FastLED replaces the core's app_main()/loopTask() with a copy of cores/esp32/main.cpp. The copy skips the Serial0.setPins() call so that sketches which don't use Serial save flash (perf(esp32p4): remove unnecessary Serial0 retention from Arduino framework startup #4892). It creates the loop task with the same stack size (getArduinoLoopTaskStackSize()/8192), priority and core as stock. This only applies on 3.3.x, which is why it lines up with your core upgrade, so I tested it directly.

    Hardware A/B test

    ESP32-C6, Arduino-ESP32 3.3.12 (pioarduino 55.03.312). An on-device esp_https_server on 127.0.0.1 returns a 16 KB body. Your client code runs unchanged against it: WiFiClientSecure + setInsecure(), HTTPClient, Connection: close, and the body kept in a global String. 10 requests per build:

    Build Startup in use Results Free heap at boot Free heap after req 10 Loop-stack HWM
    no FastLED stock app_main/loopTask 10/10 × 200 371168 201752 4876
    FastLED master FastLED flLoopTask 10/10 × 200 371860 202340 4848
    FastLED 3.10.10 FastLED flLoopTask 10/10 × 200 371860 202452 4832

    I confirmed with nm that the FastLED images really ran FastLED's startup (fl_esp32_arduino_app_main, flLoopTask). Free heap drops by about 250 B per request in all three builds, including the one without FastLED. That leak is in the core/TLS stack, not in FastLED.

    Root cause

    This is not a FastLED defect. The failure comes from the ESP32 Arduino core upgrade from 2.0.17 to 3.3.12 (ESP-IDF 4.4 to 5.5, including a new mbedTLS version), which your report changed at the same time. 200, 200, -1 is HTTPC_ERROR_CONNECTION_REFUSED: WiFiClientSecure::connect() failed. Over the internet on a classic ESP32 this usually means the TLS handshake could not allocate its buffers. aviationweather.gov sends an RSA certificate chain and a large JSON reply, and the classic ESP32 has much less free heap with WiFi STA running than the C6 above. This part is a hypothesis. I have no classic ESP32 with internet access to confirm it, so the numbers below would settle it.

    Next steps

    1. Rule FastLED out completely by putting this before the include. It restores the core's stock app_main/loopTask, and it works from the Arduino IDE (no build flags needed):
      #define FL_ESP32_STOCK_ARDUINO_MAIN 1
      #include "FastLED.h"
      If the -1 still happens, FastLED's startup code is not involved.
    2. Before each request, print ESP.getFreeHeap() and ESP.getMaxAllocHeap(), and print https.errorToString(httpCode) after it. Also call client.lastError(buf, sizeof buf) on the WiFiClientSecure to get the mbedTLS error. -0x7F00 (MBEDTLS_ERR_SSL_ALLOC_FAILED) or a max-alloc below ~40 KB confirms heap exhaustion.
    3. If it is heap: build metar with metar.reserve(...) once, or parse the stream directly with https.getStream() instead of getString(). You can also try client.setTimeout()/https.setReuse(false).

    FastLED is adding a note to the docs so the opt-out in step 1 is easier to find.

  7. zackees commented on Nov 22, 2026

    @zackees
    Member

    Correction to my previous comment, step 1. On a closer check, #define FL_ESP32_STOCK_ARDUINO_MAIN 1 in the sketch is not enough in the Arduino IDE. FastLED's own library objects also define the weak app_main, and the Arduino IDE links library .o files directly. FastLED's startup therefore stays in the image whatever the sketch defines. (Under PlatformIO/fbuild the library is linked as an archive, so the define works there. That is where I verified it.) This is a FastLED bug and I'm fixing it now. I'll post here when the fix lands. The A/B test results in the previous comment still stand: FastLED's startup made no difference to the HTTPS loop on core 3.3.12. Steps 2 and 3 (heap numbers and lastError) are still the quickest way to pin down your -1.

  8. zackees commented on Nov 22, 2026

    @zackees
    Member

    The fix for the opt-out landed in #5385 (master 9ae863e34). FastLED's own library objects no longer contain the weak app_main. In the Arduino IDE (using FastLED master until the next release), this line now restores the core's stock startup:

    #define FL_ESP32_STOCK_ARDUINO_MAIN 1
    #include "FastLED.h"

    Put it before #include "FastLED.h" in every sketch file that includes FastLED. I checked it on an ESP32-C6 with core 3.3.12: with the define, the image links the core's own app_main/loopTask. Without it, the image uses FastLED's startup as before.

    On your -1: the A/B test above found no FastLED effect, so the cause is most likely the core 2.0.17 → 3.3.12 change on a classic ESP32 (TLS heap). The define lets you confirm that on your board. Please post the ESP.getMaxAllocHeap() and client.lastError() output from the earlier comment if it still fails.

  9. zackees commented on Nov 22, 2026

    @zackees
    Member

    Tracking note: this is the same report as #5010 (closed; its follow-up replies from 2026-11-21 are answered there now), #5091 and #5092. This issue is the single open thread for it.

    Background from #5010: an ESP32 C++ guard defect (#4994) was fixed by #5007, and a later test passed 160 HTTPS requests on an ESP32dev with core 3.3.11. Neither reproduced the 200-then--1 failure. The reporter's replies show it still happens with #5007 included (master and 3.10.10, core 3.3.12), so that defect was not the cause. Next step is the reporter's heap and lastError() numbers, with FL_ESP32_STOCK_ARDUINO_MAIN set to rule out FastLED's startup code.

  10. patrice916 commented on Nov 22, 2026

    @patrice916
    Author
  11. added
    sanitized
    and removed
    sanitized
    on Nov 22, 2026
  12. zackees commented on Nov 22, 2026

    @zackees
    Member

    Thanks for tracking it down. Your result fits what we measured: the first request works, then DNS lookups through the router (Livebox) IPv6 resolver stop, and connect() fails with -1. That comes from DNS on the network/core side, not from FastLED. Our A/B test gave 10/10 200 with and without FastLED on core 3.3.12.

    WiFi.setDNS(...) is a valid fix. Calling it once after WiFi.begin()/connect should be enough, so it doesn't need to run every loop.

    Separately, #5385 fixed the FL_ESP32_STOCK_ARDUINO_MAIN opt-out for Arduino IDE builds, and #5392 adds a regression test for it.

    Closing; please reopen if it comes back with a fixed DNS server. Merci / thanks!

  13. moved this from Triage to Done in FastLED Trackeron Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    sanitizedstatus: triagetype: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions