Repository navigation
Description
What happened?
After so many seconds, the lights will turn off for a split second, then turn back on to the default Orange color, no matter what color/brightness/effect it was prior. After it does this, it acts normally until the next random reset.
Setup: I have a Dig-Uno running WLED 0.13.0-b6 for under cabinet kitchen lighting with 76 WS2812B 30 led/m. It is synced to a Hue light, every 2500 ms. Running on Wi-Fi. Previously, I was running a ESP8266 and this was occurring on older WLED versions as well.
I've tried the following troubleshooting steps:
- Replace the power supply. Originally an Alitove 5V3A wall wart. Then a MeanWell 5V/5A wall wart. And for troubleshooting, an MeanWell 5V/60A box. The troubleshooting PSU is known working, I was previously using it for my house exterior before moving to 24v.
- Change LED strip. Unplugged the cabinet lighting and plugged in a different, known working
- Re-flash WLED. During my previous attempt at troubleshooting, I re-flashed from scratch. (I think I still have the problem
- Changing to a 5A fuse (not that I thought this would help)
- Removed the barrel connector and used ferrules to connect power
- Saw that the MeanWell wall-wart was providing 5.12v. The MW box is outputting exactly 5v.
- Noticed that during the reset, I'll lose a single network ping.
At this point, I've changed everything yet still have this problems.
To Reproduce Bug
- Configure Hue Light to sync to poll a light.
Was able to verify this by wiping the configuration by re-flashing the DigUno, letting it sit for >24hrs with no issues, then integrating with Philips Hue and immediately start having the issue.
Expected Behavior
The WLED firmware doesn't reset and go back to default Orange color but stays synced to Hue Light
Install Method
Binary from WLED.me
What version of WLED?
0.13.0-b6
Which microcontroller/board are you seeing the problem on?
ESP8266, ESP32
Relevant log/trace output
No response
Anything else?
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
Aircoookie commentedon Jan 21, 2022
Have been seeing this as well since a long time ago.
The available heap memory slowly decreases until the device resets randomly or upon trying to access the UI due to the low memory condition.
The polling must be causing a memory leak either in the TCP stack, AsyncClient library, or handling code.
nikita240 commentedon Jan 23, 2022
+1 I'm also affected by this
bobness09 commentedon Mar 4, 2022
I also can reproduce this easily, when I switch on Hue Sync. With sync off it runs stable. Most of the times it crashes between 10sec and 2-5mins. Also, there's always ~200KB free heap on my ESP32, even right before it crashes.
Had no problem on 0.12.0, the bug startet to occur when I updated to 0.13.0-b5 and is still on b7.
bobness09 commentedon Mar 15, 2022
Still a problem in 0.13.1 for me. It crashes more often the lower the sync time is.
franciscoangelini commentedon Oct 2, 2022
i try sync my esp wled with hue and said Hue status: Invalid light ID i try stable 0.3.13 and 0.13b7
wusapa commentedon Jan 30, 2024
I also have the problem that my WLED keeps restarting when I sync it with my Hue lights. Are there any fixes in sight for this?
Version: v0.14.1
GroveGuard commentedon Jul 13, 2024
Hello fellas,
i struggled a LOT with these restart problems till i finaly get it is the hue connect setting. I have that problem in all of my 8 controllers (many different brands) and also in a seperate vlan. i tried nearly everything to get this working cause i have a full hue setup in my house and would love to controll all lights with the hue app, so i need that sync badly.
Is there any chance some off the genius programming minds in the wled community could figure out a fix for that memory leak problem?
if i could assist in any way pls dont hesitate to let me know.
Greetings
softhack007 commentedon Jul 13, 2024
Actually it might be improved already in the latest releases of 0.14.4 or 0.15.beta. there were memory leaks in both ithe UDP and the asyncWS library. However you'll need a build with the new esp32 framework version 2.0.9, so you'd need the "WROVER" bin or use an esp32-S3.
The WROVER firmware requires a reduced filesystem partition, so you cannot update by OTA.
If you still see the same problem, please inform us. Personally I don't have a HUE system, so the only help I can offer is hunting for mem leaks by visual inspection of the source code. And I'm not particularly good with JSON.
GroveGuard commentedon Jul 17, 2024
Thanks for the reply. I tested all versions till 0.15.0-b3 but, when i activate the HUE sync it begins to run unstable.
I cannot connect my controller directly to the PC cause i use this ATHOM-Controller.
Is there a way to Flash a Wrover-Binary OTA?
I just saw there is a b4-release. I will test it within the next days and let you know if it works.
Have a good one
Zugdar commentedon Apr 5, 2025
Just put together my first WLED setup with a Dig-Quad. Not a programmer but dabble in many smart systems. This still seems to be an issue 0n V0.15.0 I had resets between 4-8 minutes and have a much more stable system after disabling and removing all Hue communication. More testing/waiting to be done to verify the fix fully. Was noticing the colors shifting to the booted orange and going back to the hue bulb it was assigned to shortly after pairing the system.
Other thing I did which may or may not be a factor.
1 remaining item
softhack007 commentedon Jan 28, 2026
@coderabbitai please inspect the hue sync code (
wled00/hue.cpp) for possible memory leaks or use-after-free problems, and summarize your results.coderabbitai commentedon Jan 28, 2026
🧩 Analysis chain
@softhack007, I'll inspect the Hue sync code for potential memory leaks and use-after-free issues.🏁 Script executed:
Length of output: 5021
@softhack007, I've analyzed the Hue sync code and found several memory management issues:Primary Memory Leak (Critical)
AsyncClient is never freed:
hueClient = new AsyncClient()allocates a new clienthueClient->close()closes the connection but doesn't delete the objectdelete hueClientanywhere in the codeThis is likely the main cause of the gradual heap depletion users are reporting.
Additional Issues
1. Missing cleanup when polling is disabled (Lines 26-28)
The client is closed but never deleted, leaving the allocated memory unreleased.
2. No disconnect callback registered (Lines 40-42)
Only
onConnect,onData, andonErrorcallbacks are registered. Without anonDisconnectcallback, there's no handling for connection drops, which could leave the client in an inconsistent state.3. Repeated String allocations in sendHuePoll() (Lines 59-73)
Multiple String concatenations occur on every poll cycle:
While String objects are automatically cleaned up, this pattern can cause heap fragmentation over time, especially with frequent polling.
4. Large stack allocation (Line 87)
StaticJsonDocument<1024> root;1024 bytes on the stack isn't a leak, but could contribute to stack pressure on ESP devices with limited RAM.
Recommendations
reserve(), or use stack-allocated char buffersThe AsyncClient leak would explain why users see slow heap depletion over hours/days, with crashes occurring when heap is exhausted. The issue would be worse with shorter poll intervals (as users reported).
🧠 Learnings used
softhack007 commentedon Jan 28, 2026
@coderabbitai two questions:
the function reconnectHue() is also called from asyc_tcp context within set.cpp. Can this call lead to heap corruption, assuming that free heap in async_tcp is between 2kb and 1kb?
please analyze the use of
StaticJsonDocument<1024> root;and suggest a sufficient buffer size. Also inspect HUE protocol documentation on the internet to justify your proposal for a meaningful ArduinoJSON buffer size.coderabbitai commentedon Jan 28, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 865
🏁 Script executed:
Length of output: 5021
🏁 Script executed:
Length of output: 803
🏁 Script executed:
Length of output: 631
🏁 Script executed:
Length of output: 1902
🌐 Web query:
💡 Result:
Example Hue Bridge API v1 response (read a single light):
GET http://<bridge-ip>/api/<username>/lights/1{ "state": { "on": true, "bri": 202, "hue": 13122, "sat": 211, "xy": [0.5119, 0.4147], "ct": 467, "alert": "none", "effect": "none", "colormode": "ct", "reachable": true }, "type": "Extended color light", "name": "TV Left", "modelid": "LCT001", "swversion": "65003148", "pointsymbol": { "1": "none", "2": "none", "3": "none", "4": "none", "5": "none", "6": "none", "7": "none", "8": "none" } }[1]
If you instead fetch all lights, the response is keyed by light id:
GET http://<bridge-ip>/api/<username>/lights{ "1": { "state": { "on": false, "bri": 198, "hue": 5360, "sat": 192, "effect": "none", "xy": [0.533, 0.387], "ct": 500, "alert": "select", "colormode": "xy", "mode": "homeautomation", "reachable": true }, "type": "Extended color light", "name": "Standard Lamp", "modelid": "LCA001", "manufacturername": "Signify Netherlands B.V.", "productname": "Hue color lamp" } }[2]
Sources: [1] [2]
🌐 Web query:
💡 Result:
For local Hue Bridge (CLIP v1) authentication (creating a username), you
POST /apiwith a JSON body like{"devicetype":"my_app#device"}. The Bridge responds with a JSON array containing one object, in one of these formats:Success response (username created)
[{"success":{"username":"<username>"}}]Example shown in practice/docs: the
success.usernamefield is the token you use in subsequent URLs. [1][2]Minified size (bytes):
29 + len(<username>)(e.g., if the username is 40 chars → 69 bytes)
Error response (link button not pressed)
[{"error":{"type":101,"address":"/","description":"link button not pressed"}}]This happens if you didn’t press the Bridge’s physical link button in time. [3]
Minified size (bytes): 78 bytes (ASCII)
Notes on “size”: Actual HTTP payload size can be larger if your client/server adds whitespace/newlines (“pretty printed”) or uses different header/transfer settings; the byte counts above are for the raw minified JSON text only.
Sources:
[1] https://devmin.io/2019/11/philips-hue-api-and-postman/
[2] https://developers.meethue.com/develop/get-started-2/
[3] https://www.issackelly.com/blog/2012/11/10/philips-hue-api-hacking
🏁 Script executed:
Length of output: 23
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 5711
🏁 Script executed:
Length of output: 37
🏁 Script executed:
Length of output: 27
🏁 Script executed:
Length of output: 1513
🏁 Script executed:
Length of output: 0
@softhack007, excellent questions! Here's my analysis:Question 1: Heap Corruption Risk from async_tcp Context
Yes, this is a serious problem. When
reconnectHue()is called fromset.cppduring settings page submission, it executes in the AsyncWebServer's task context with only 8KB stack (CONFIG_ASYNC_TCP_STACK_SIZE=8192).The critical issue is heap allocation, not stack:
Problems with 1-2KB free heap:
AsyncClient allocation size: An AsyncClient object likely requires 500-1000 bytes (includes TCP buffers, callback pointers, connection state, send/receive queues)
No heap check: The code doesn't verify available heap before allocation. With only 1-2KB free heap, this allocation could:
Cascading allocations: After AsyncClient creation, the code immediately calls
connect()which may allocate additional TCP buffersRecommendation: Add heap validation before allocation:
Question 2: StaticJsonDocument Buffer Size
Based on Philips Hue Bridge API v1 responses, I analyzed the actual sizes:
Actual Hue API Response Sizes:
Light state response (what WLED queries):
Authentication response: 69-78 bytes for success/error responses
ArduinoJSON Memory Requirements:
ArduinoJSON needs approximately 1.5-2x the JSON text size for its internal document representation (object/array nodes, string storage, etc.).
Stack Consumption Analysis:
StaticJsonDocument<1024>uses 1024 bytes of stack (1/8 of the 8KB async_tcp stack)onHueData()which is called from async_tcp callback contextsendHuePoll()and call chain depth, this is concerning but not immediately criticalRecommendation: Reduce to 512 bytes
Justification:
Alternative: Use
DynamicJsonDocumentwith heap allocation and error checking, but given WLED's heap constraints, stick with StaticJsonDocument at a reduced size.The combination of both issues (heap allocation in low-heap conditions + large stack allocation) likely contributes to the crashes users report with frequent polling intervals.
🧠 Learnings used
softhack007 commentedon Jan 28, 2026
@coderabbitai would the Philips Hue Bridge API v2 (successor of v1) require a larger JSON buffer?
coderabbitai commentedon Jan 28, 2026
🧩 Analysis chain
🌐 Web query:
💡 Result:
Hue Bridge CLIP API v2
GET /clip/v2/resource/light(and.../light/{id}) responses are wrapped like:errors(array) anddata(array) (postman.com)A light entry in
datais a resource object that includes identifiers liketype,id, optionalid_v1, and anownerreference, plus state blocks such ason,dimming,color_temperature,color, etc. (openhue.io)Example (single light)
GET /clip/v2/resource/light/{lightId}typically returns one-elementdata:{ "errors": [], "data": [ { "type": "light", "id": "3f2a8e2c-6e12-4f6a-9d52-0d5c5e2c9c10", "id_v1": "/lights/8", "owner": { "rid": "42edd1f5-9538-4180-9ced-2d9e07f26d0f", "rtype": "device" }, "metadata": { "name": "Desk lamp", "archetype": "desk_lamp" }, "on": { "on": true }, "dimming": { "brightness": 42.1 }, "color_temperature": { "mirek": 250, "mirek_valid": true }, "color": { "xy": { "x": 0.3127, "y": 0.3290 } } } ] }“Size” (bytes) of the JSON
There isn’t a fixed size: it depends on which optional blocks are present (e.g.,
gradient,effects,dynamics,powerup, etc.). (openhue.io)To get the actual response size, read the HTTP
Content-Lengthheader (when provided) or measure the received body length in bytes in your client.Citations:
🌐 Web query:
💡 Result:
Example CLIP v2
GET /clip/v2/resource/light/{lightId}“complete” light response (includes common + optional capability blocks; some blocks appear only if the light supports them) [1][2]:{ "errors": [], "data": [ { "type": "light", "id": "191f7732-280b-46c8-b1d2-58fcbb717abe", "id_v1": "/lights/61", "owner": { "rid": "ab36d3a0-ab36-43eb-9ba8-3b2871d79880", "rtype": "device" }, "metadata": { "name": "Hue gradient string light 1", "archetype": "string_light" }, "on": { "on": true }, "dimming": { "brightness": 100.0, "min_dim_level": 5.0 }, "dimming_delta": {}, "color_temperature": { "mirek": null, "mirek_valid": false, "mirek_schema": { "mirek_minimum": 153, "mirek_maximum": 500 } }, "color_temperature_delta": {}, "color": { "xy": { "x": 0.1545, "y": 0.0968 }, "gamut": { "red": { "x": 0.6915, "y": 0.3083 }, "green": { "x": 0.17, "y": 0.7 }, "blue": { "x": 0.1532, "y": 0.0475 } }, "gamut_type": "C" }, "dynamics": { "status": "none", "status_values": ["none", "dynamic_palette"], "speed": 0.0, "speed_valid": false }, "alert": { "action_values": ["breathe"] }, "signaling": {}, "mode": "normal", "gradient": { "points": [ { "color": { "xy": { "x": 0.1545, "y": 0.0968 } } }, { "color": { "xy": { "x": 0.1545, "y": 0.0968 } } }, { "color": { "xy": { "x": 0.1545, "y": 0.0968 } } }, { "color": { "xy": { "x": 0.1545, "y": 0.0968 } } }, { "color": { "xy": { "x": 0.1545, "y": 0.0968 } } } ], "mode": "interpolated_palette", "points_capable": 5, "mode_values": [ "interpolated_palette", "interpolated_palette_mirrored", "random_pixelated" ], "pixel_count": 250 }, "effects": { "status_values": ["no_effect", "candle", "fire", "sparkle"], "status": "no_effect", "effect_values": ["no_effect", "candle", "fire", "sparkle"] }, "timed_effects": { "status_values": ["no_effect", "sunrise"], "status": "no_effect", "effect_values": ["no_effect", "sunrise"] }, "powerup": { "preset": "safety", "configured": true, "on": { "mode": "previous" }, "dimming": { "mode": "previous" }, "color_temperature": { "mode": "previous" }, "color": { "mode": "previous" } } } ] }Sources: full real-world v2 light response example [1]; OpenHue CLIP v2 light resource docs (capability blocks like
powerup, etc.) [2].🏁 Script executed:
Length of output: 424
@softhack007, excellent question! Based on my research:Current Status
WLED currently uses Hue Bridge API v1 (format:
GET /api/{apikey}/lights/{lightid}), so the 512-byte recommendation I made earlier is appropriate for the current implementation.API v2 Buffer Requirements
Yes, API v2 would require a significantly larger buffer.
Key Differences in v2:
Response wrapper structure: v2 wraps all responses in
{"errors": [], "data": [...]}Longer identifiers: UUIDs instead of numeric IDs
"id": "1""id": "191f7732-280b-46c8-b1d2-58fcbb717abe"Many additional capability blocks:
gradient(with up to 5 color points for gradient lights)effects(status_values, effect_values arrays)timed_effects(sunrise, etc.)dynamics(speed, status)powerup(with nested on/dimming/color state preservation)signalingcolorwith full gamut definitionsSize Comparison:
Recommendation for v2:
If WLED migrates to API v2 in the future, the JSON buffer should be:
Or more conservatively:
However, this would consume 1.5-2KB of stack in the async_tcp context (which only has 8KB total), making heap fragmentation and stack overflow risks even more severe.
Alternative approach for v2: Use
DynamicJsonDocumentwith heap allocation and proper error checking, though this reintroduces heap pressure concerns we discussed earlier.For now, since WLED uses v1, the 512-byte buffer remains the right choice.
🧠 Learnings used
softhack007 commentedon Jan 28, 2026
My quick-shot summary;
hueClient = new AsyncClient();only happens once. If there is a memory leak, it must be inside AsyncClient(), but user reports (200KB of heap still available shortly before the crash) do not support this.sendHuePoll()oronHueData(), especially if these are trying to modify segment instances "while drawing".==> As a first measure, the json buffer should be reduced maybe to
StaticJsonDocument<512> root.Depending on context, taking 1024 bytes from the stack may already be too much. When the stack is "smashed" this way, other varibales may bet overwritten which likely causes crashes.
WLED/wled00/hue.cpp
Line 95 in 857e73a
==> we should also review the error handling code in hue.cpp. As an example, the code below might lead to random behaviour if the resulting substring is shorter than 4 bytes:
WLED/wled00/hue.cpp
Lines 90 to 93 in 857e73a
Edit (thanks coderabbitAI) ==>
WLED/wled00/hue.cpp
Lines 133 to 135 in 857e73a
add
if (str == nullptr) {hueError = HUE_ERROR_JSON_PARSING; return;}after the call to strstr();softhack007 commentedon Jan 28, 2026
@coderabbitai anything you like to add to #2495 (comment) ?
coderabbitai commentedon Jan 28, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 5021
@softhack007, excellent summary! I agree with your analysis and have some additional observations:Additional Error Handling Issues
1. Critical nullptr dereference at Line 133:
If the response contains "state" but no subsequent
{,deserializeJson()receives a nullptr. This should be:2. Heap fragmentation from String operations in
sendHuePoll():Every poll cycle allocates and concatenates multiple Strings:
With fast polling (every few seconds), this creates/destroys heap blocks repeatedly, causing fragmentation. Over hours/days, this reduces effective available heap even if total free heap looks okay (the "200KB available but still crashes" phenomenon).
3. Race condition explaining faster polling = more crashes:
The smoking gun is here (Line 13):
colorUpdated()modifies segment data structures. If this happens during the rendering loop's segment iteration, it can cause:Faster polling = more frequent
colorUpdated()calls = higher probability of collision with rendering loop.4. No connection timeout mechanism:
If a TCP connection hangs (neither succeeds nor fails),
hueClientstays allocated indefinitely with no cleanup path.Recommendations
Immediate fixes:
Medium-term fixes:
reserve()or use char bufferYour stack smashing theory is highly plausible - if the 1024-byte StaticJsonDocument overruns the 8KB async_tcp stack, it could corrupt the
hueReceivedflag or other local variables, leading to undefined behavior that manifests as crashes.The combination of:
...explains why the crash rate correlates with polling frequency and why 200KB "free" heap isn't protective.
🧠 Learnings used