Skip to content

[16.0.0 / 16.0.1] ESP32: free heap leaks on every UDP sync notification sent → reboot every ~40 min on the sync master #5924

Open

Description

@gvillant

What happens
On WLED 16.0.0 (ESP32, QuinLED Dig-Quad V3 build, Ethernet), the free heap drops by about 1–2 kB every time a UDP sync notification is sent. The device that sends sync (a playlist "master" changing preset every 60 s) loses ~1.6 kB/min and reboots after ~40 min (heap ~40 kB). Shortly before the crash, effects fall back to solid colour (segment data allocation fails). Receivers are not affected.

16.0.1 reduces it but does not fix it (~340 B per notification). 0.15.4 on the same device and config: no leak.

Measurements (freeheap via /json/info, max of 3 reads, same device, same config)

Action (repeated 10–20×) 16.0.0 16.0.1 0.15.4
nothing ~0
preset load with "udpn":{"nn":true} ~0
direct fx change with "udpn":{"nn":true} 0
preset load / fx change with sync send −1.2 to −2 kB per change −340 B per change ~0
same, Wi-Fi disabled (Ethernet only) −1 kB per change
same, 2 segments instead of 3 same leak

No WebSocket clients connected during the tests (ws: 0). The heap is never recovered.

Setup

  • ESP32 (QuinLED Dig-Quad V3), Ethernet (type 4) + Wi-Fi both connected for most tests
  • 3 segments, 681 LEDs (WS281x), Art-Net receive enabled (no Art-Net traffic during the tests)
  • Sync: send enabled (group 1, direct change + button), ESP-NOW off; 4 receivers on the LAN
  • Boot preset = playlist of 18 presets, 60 s each

Steps to reproduce

  1. Enable "Send broadcast" (UDP sync) on an ESP32 running 16.0.0.
  2. Change the effect via /json/state every few seconds (without nn).
  3. Watch freeheap in /json/info: it goes down by ~1–2 kB per change and never recovers.

Possibly related
#5614 (periodic reboots on 16.x, fixed in 17.0.0-dev by replacing quickespnow) — here ESP-NOW is disabled, but the leak is in the broadcast send path too.

Activity

  1. softhack007 commented on Oct 21, 2026

    @softhack007
    Member

    @gvillant can you upload a backup of your device configuration (cfg.json) and presets (presets.json), both for the sync master and for one of the receiving devices? This would help us to reproduce the problem, and find a solution faster.

    Edit: no pretty-printing please - just upload the raw files that you can download from the Security & Update settings page.

  2. added
    needs investigationThe bug has not yet been reproduced by me. Analysis or more details are needed.
    on Oct 21, 2026
  3. softhack007 commented on Oct 21, 2026

    @softhack007
    Member

    Watch freeheap in /json/info: it goes down by ~1–2 kB per change and never recovers.

    @gvillant Just a side-question: Did you use an AI for this report?

    I'm wondering, because a human user would normally watch the Info panel in the webUI - I've never seen a user who prefers to regularly poll a json endpoint directly 📟

  4. gvillant commented on Oct 22, 2026

    @gvillant
    Author

    Thanks for looking into this!

    Config files: wled-5924-configs.zip :

    • master_16.0.0_*: the sync master (QuinLED Dig-Quad V3, 16.0.0) as it was while leaking: playlist of 18 presets (60 s each) as boot preset, UDP sync send enabled, Ethernet + Wi-Fi both connected
    • receiver_16.0.0_*: one of the 4 receivers (16.0.0, sync receive only, no leak observed on it)

    For the record, the master has since been downgraded to 0.15.4 as a workaround: no leak there with the same config (and Wi-Fi disabled, Ethernet only).

    About AI: yes. I did the troubleshooting together with an AI assistant (Claude). It wrote small scripts that polled /json/info and drove /json/state to isolate the cause step by step: idle, preset changes with and without nn, 2 vs 3 segments, Wi-Fi on/off, then 16.0.1 and 0.15.4. It also drafted the report, which I reviewed. That's why the numbers come from the JSON API rather than the Info page. The first symptom was a real one, though: my master pod rebooted every ~40 min during a test show, with a short solid colour just before each crash.

    Happy to run any additional test or a debug build on the spare board if that helps.

  5. DedeHai commented on Oct 22, 2026

    @DedeHai
    Collaborator

    on my C3, wifi only, this issue does not exist. Maybe its related to ethernet.

  6. added
    AIPartly generated by an AI. Make sure that the contributor fully understands the code!
    on Oct 22, 2026
  7. softhack007 commented on Oct 22, 2026

    @softhack007
    Member

    Another possible explanation - at least as a theory - is heap fragmentation. When quickly changing between effects, some effects will have effect data (heap allocation), some will not. Transitions and cross-fade adds to that. It means repeated alloc/free cycles, leading to fragmentation that looks like a memory leak. Also measuring via json API can produce a twisted result, because the json messages themselves need heap storage.

  8. softhack007 commented on Oct 22, 2026

    @softhack007
    Member

    The topic reminds me of a "leak hunt" that we performed a few years ago in wled-mm, leading to additional safeguards around wifiUDP message parsing. Not sure it was the real root cause, but it did stabilise heap use compared to the 0.14.4 baseline from upstream wled.

    Just some ideas for reference.

  9. gvillant commented on Oct 22, 2026

    @gvillant
    Author

    @DedeHai you were right, it's Ethernet. New tests on the sync master, now on 16.0.1, same device and same config:

    Sync master (16.0.1) Free heap per preset change (sync sent)
    Ethernet + Wi-Fi connected −665 B (20 changes: 62424 → 49116)
    Wi-Fi only (Ethernet type set to None, rebooted) ≈ 0 (20 changes: 122644 → 122844)

    Protocol: 20 preset loads, 10 s apart, UDP sync send enabled, free heap = max of 3 reads of /json/info before and after. No WebSocket client connected.

    With the real playlist (one preset change per minute, Ethernet + Wi-Fi), the drop is about 1.5 kB per change (102.6 kB → 83.2 kB in 12.5 min). Between changes the heap stays flat. The device reboots after roughly an hour.

    Second finding: Ethernet + a Wi-Fi network that can't be found. To run Ethernet only, I had set the Wi-Fi SSID to a network that doesn't exist. With Ethernet active, free heap then went down continuously, ~3.5–4 kB per minute. This happened even with the playlist stopped (no sync sent) and no WebSocket client, and the device rebooted in about 20 min. Once the real SSID was back, the continuous drop stopped and only the per-change drop above remained. Maybe the same leak, triggered by the Wi-Fi reconnect attempts?

    About fragmentation (@softhack007): I don't think it explains this.

    • It's the total freeheap that goes down until the reboot, not only the largest free block.
    • The same effect changes sent with "udpn":{"nn":true} (no sync) and measured the same way give 0. So neither the effect allocations nor the JSON reads cause the drop.
    • The receivers play exactly the same effect changes and don't lose heap. One of them is on Ethernet too (receive only).
    • Wi-Fi only, same effects and same measurement method: no drop at all.

    So it seems to happen only when a device sends UDP sync over Ethernet (ESP32, QuinLED Dig-Quad V3, Ethernet type "QuinLED-ESP32").

    Current workaround: the master runs Wi-Fi only. That's fine for now, but the final install will be spread over several tens of metres with an audience, so we'll need Ethernet everywhere. Happy to test a debug build or a fix on this board.

  10. gvillant commented on Oct 22, 2026

    @gvillant
    Author

    Small follow-up on the Wi-Fi only result. The "≈ 0" above comes from the short 20-change test. Over a longer run it isn't exactly zero:

    • Sync master on Wi-Fi only, real playlist (one preset change every 2 min), 1 h 50: free heap went from 122.7 kB to 113.5 kB. That's about 5 kB/h, ~170 B per change.
    • For comparison, Ethernet + Wi-Fi, one change per minute: about 1.5 kB per change, ~90 kB/h, reboot after about an hour.
    • A receiver on Ethernet, over the same 3 h: flat at ~101 kB.

    So there may still be a small leak on the send path over Wi-Fi, but Ethernet makes it roughly 10× worse.

  11. DedeHai commented on Oct 22, 2026

    @DedeHai
    Collaborator

    Note: I have let my lamp run for several hours, playlist changed FX every 10 seconds and I saw no decrease in heap on a C3.

  12. softhack007 commented on Oct 22, 2026

    @softhack007
    Member

    So it seems to happen only when a device sends UDP sync over Ethernet

    There is another known memory leak coming from the ESP-NOW library. It basicially happens when there is no Wi-Fi connection, but ESP-NOW tries to re-connect regularly - for example to send UDP sync over ESP-NOW, or to receive from an ESP-NOW remote.
    The ESP-NOW driver gets re-initailized very often in this scenario, and it leaks RAM until the boards crashes with OOM.

    The workaround is the same - connect all devices by Wi-Fi.

    WLED 16.1.0 will be built with an ESP-NOW library that has this bug fixed.

  13. softhack007 commented on Oct 22, 2026

    @softhack007
    Member

    So it seems to happen only when a device sends UDP sync over Ethernet (ESP32, QuinLED Dig-Quad V3, Ethernet type "QuinLED-ESP32").

    @coderabbitai are there any code differences between Wi-Fi and Ethernet connections in the UDP sync sending path in our 16_x branch?

    If yes, can the differences explain the memory leaks observed?
    If no, please review the ethernet code from arduino-esp32 2.0.17, and look for possible memory leaks that could be related to the scenario described by the user.

  14. coderabbitai commented on Oct 22, 2026

    @coderabbitai
  15. coderabbitai commented on Oct 22, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/bin/bash
    set -euo pipefail
    mkdir -p /tmp/wled5924-review
    for spec in \
     'wled/WLED/16_x/wled00/udp.cpp' \
     'wled/WLED/16_x/wled00/src/dependencies/network/Network.cpp' \
     'wled/WLED/16_x/wled00/network.cpp' \
     'wled/WLED/16_x/platformio.ini' \
     'espressif/arduino-esp32/2.0.17/libraries/WiFi/src/WiFiUdp.cpp' \
     'espressif/arduino-esp32/2.0.17/libraries/Ethernet/src/ETH.cpp'; do
     out="/tmp/wled5924-review/$(basename "$spec")"
     curl -fsSL "https://raw.githubusercontent.com/$spec" -o "$out"
     echo "=== $spec ==="
     if [[ "$out" == *.cpp ]]; then ast-grep outline "$out" --items all; else rg -n -C3 'platform *=|platform_packages|2\.0\.|2024\.' "$out"; fi
    done

    Length of output: 17458


    🏁 Script executed:

    #!/bin/bash
    set -euo pipefail
    echo '=== WLED sender ==='
    nl -ba /tmp/wled5924-review/udp.cpp | sed -n '1,208p;468,565p'
    echo '=== interface selection ==='
    nl -ba /tmp/wled5924-review/Network.cpp | sed -n '1,95p'
    echo '=== Ethernet initialization ==='
    nl -ba /tmp/wled5924-review/network.cpp | sed -n '186,290p'
    echo '=== UDP allocations and disposal ==='
    nl -ba /tmp/wled5924-review/WiFiUdp.cpp | sed -n '29,281p'
    echo '=== Ethernet initialization and accessors ==='
    nl -ba /tmp/wled5924-review/ETH.cpp | sed -n '225,408p;465,492p'
    for f in components/lwip/port/esp32/netif/ethernetif.c components/esp_eth/src/esp_eth_netif_glue.c components/esp_eth/src/esp_eth_mac_esp.c components/hal/emac_hal.c; do
     out="/tmp/wled5924-review/$(basename "$f")"
     curl -fsSL "https://raw.githubusercontent.com/espressif/esp-idf/v4.4.7/$f" -o "$out"
     ast-grep outline "$out" --items all --match 'output|transmit|rx_task|input'
    done
    echo '=== IDF transmit / receive allocation ownership ==='
    rg -n -A65 -B5 'static err_t ethernet_low_level_output|static err_t low_level_output|static esp_err_t emac_esp32_transmit|uint32_t emac_hal_transmit_frame|static void emac_esp32_rx_task|static esp_err_t eth_input_to_netif' /tmp/wled5924-review/{ethernetif.c,esp_eth_mac_esp.c,emac_hal.c,esp_eth_netif_glue.c}

    Length of output: 63581


    @softhack007 The 16_x branch uses the same UDP sync sender for Wi-Fi and Ethernet. The interface-specific differences do not show an allocation leak. I also inspected Arduino-ESP32 2.0.17 and the ESP-IDF 4.4.7 Ethernet transmit path. I found initialization cleanup defects, but no confirmed per-send leak that explains the report.

    1. Differences in WLED

    Both interfaces use notify(), Line 199–202:

    IPAddress broadcastIp = ~uint32_t(Network.subnetMask()) | uint32_t(Network.gatewayIP());
    notifierUdp.beginPacket(broadcastIp, udpPort);
    notifierUdp.write(udpOut, WLEDPACKETSIZE);
    notifierUdp.endPacket();

    The relevant differences are:

    • Address selection: NetworkClass::subnetMask() and NetworkClass::gatewayIP() prefer Ethernet when Ethernet has a nonzero IP address. Otherwise, they use Wi-Fi.
    • Output driver: lwIP routes the packet to an interface. These calls do not explicitly bind the packet to Ethernet. With both interfaces connected, a packet capture should confirm the output interface.
    • Self-packet filtering: NetworkClass::localIP() also prefers Ethernet. This affects which incoming packets WLED identifies as its own broadcasts.

    WLED constructs the notification in a stack buffer. It sends the same WLEDPACKETSIZE on either interface. That size depends on the maximum supported segment count, not the active segment count.

    None of these differences directly explains a persistent allocation loss per preset change. However, interface selection can change whether broadcast traffic returns to the sender.

    2. Arduino-ESP32 2.0.17 Ethernet review

    Component Finding
    WiFiUDP::beginPacket() Reuses the socket and a 1460-byte transmit buffer. It does not allocate another buffer for each notification.
    WiFiUDP::endPacket() Calls sendto(). It has no interface-specific allocation logic.
    ESP-IDF Ethernet output Allocates a temporary contiguous pbuf when the input is chained. It frees that temporary pbuf after transmission, including on a transmit error.
    ESP32 Ethernet HAL Copies the packet into existing DMA buffers. It does not allocate heap memory per transmission.

    The retained 1460-byte UDP transmit buffer is close to one reported loss measurement. Its size alone is not evidence of the leak: the code reuses that buffer.

    There are missing cleanup paths in ETHClass::begin(). For example, if MAC creation fails after esp_netif_new(), the function returns without destroying the netif. Later failure paths also leave resources allocated.

    Repeated failed initialization could therefore lose heap. But WLED’s initEthernet() prevents reinitialization after successful setup. These defects do not fit a loss on every preset change with an established Ethernet connection.

    3. Receive-buffer retention remains a useful test target

    The current 16_x branch still rejects self-originated notifications before consuming the packet at Line 522:

    if (!isSupp && notifierUdp.remoteIP() == localIP) return;

    In stock 2.0.17, WiFiUDP::parsePacket() returns zero while rx_buffer exists. If a returned broadcast reaches this check, WLED retains the packet and stops draining that socket until something reads, flushes, or closes it.

    This can retain one Arduino receive buffer and fill the underlying receive queue. It does not establish an unlimited leak: the queue has a finite capacity. It could explain an initial heap decrease, but not necessarily the continued decrease until reboot.

    A diagnostic build should discard that rejected packet with notifierUdp.flush() before returning. The test should also record whether this rejection occurs.

    4. Recommended next checks

    1. Confirm the framework build. 16_x/platformio.ini, Line 298–304 selects Tasmota Arduino Core 2.0.18 / ESP-IDF 4.4.8 by default. Stock 2.0.17 / ESP-IDF 4.4.7 is an optional configuration. The upstream review above is not proof about the exact installed binary.
    2. Compare broadcast with unicast. Keep the payload, effects, and send interval unchanged. This helps isolate broadcast reception and queue retention.
    3. Log send results and connection events over serial. WLED currently ignores the return values from the three UDP send calls.
    4. Trace outstanding allocations across several notifications. Heap tracing in the exact framework build can identify allocations that remain after traffic settles.
    5. Keep the missing-SSID test separate. That heap loss occurs without sync transmission. It can have a different cause.

    Bottom line: I did not find an Ethernet transmit allocation leak that matches the measurements. The strongest concrete WLED finding is the unread-packet rejection path. Test that path first, but do not treat it as the confirmed cause of the continuing heap loss.

    You are interacting with an AI system.

  16. softhack007 commented on Oct 22, 2026

    @softhack007
    Member

    @coderabbitai do the user's configuration files (#5924 (comment)) show that ESP-NOW is not active so the root case from #5614 can be excluded?

  17. coderabbitai commented on Oct 22, 2026

    @coderabbitai
    Contributor
    🧩 Analysis chain

    🏁 Script executed:

    #!/bin/bash
    set -euo pipefail
    gh api repos/wled/WLED/issues/comments/6329735631 --jq .body
    gh issue view 5614 --repo wled/WLED --json title,body --jq '{title,body}'
    curl -fsSL https://github.com/user-attachments/files/33794237/wled-5924-configs.zip -o /tmp/wled5924-config-check.zip
    python - <<'PY'
    import zipfile,json
    with zipfile.ZipFile('/tmp/wled5924-config-check.zip') as z:
        for name in z.namelist():
            if not name.endswith('.json') or 'preset' in name.lower():
                continue
            data=json.loads(z.read(name))
            print(name)
            for path in [('nw','espnow'),('if','sync','espnow')]:
                value=data
                for key in path:
                    value=value.get(key) if isinstance(value,dict) else None
                print('.'.join(path),repr(value))
    PY
    for file in cfg.cpp network.cpp udp.cpp; do
     curl -fsSL "https://raw.githubusercontent.com/wled/WLED/16_x/wled00/$file" -o "/tmp/wled5924-check-$file"
     ast-grep outline "/tmp/wled5924-check-$file" --items all --match 'deserializeConfig|handleConnection|initConnection|notify' || true
     rg -n -C5 'enableESPNow|useESPNowSync|quickEspNow\.(begin|stop|send)' "/tmp/wled5924-check-$file"
    done

    Length of output: 5793


    🏁 Script executed:

    #!/bin/bash
    set -euo pipefail
    for file in wled.cpp udp.cpp; do
     curl -fsSL "https://raw.githubusercontent.com/wled/WLED/16_x/wled00/$file" -o "/tmp/wled5924-gate-$file"
     ast-grep outline "/tmp/wled5924-gate-$file" --items all --match 'loop|setup|notify|handle'
     rg -n -C7 'enableESPNow|useESPNowSync|quickEspNow\.(begin|stop|send)' "/tmp/wled5924-gate-$file" || true
    done

    Length of output: 5919


    @softhack007 Yes. Both uploaded configuration files disable ESP-NOW. I rechecked the raw files from the configuration attachment.

    File nw.espnow if.sync.espnow
    master_16.0.0_cfg.json false false
    receiver_16.0.0_cfg.json false false

    In 16_x, these settings map to:

    • enableESPNow = false: WLED skips quickEspNow.begin(). This disables ESP-NOW initialization, including support for ESP-NOW remotes.
    • useESPNowSync = false: WLED disables sync transmission over ESP-NOW. The send path also requires enableESPNow to be true.

    Therefore, the repeated ESP-NOW initialization leak associated with #5614 can be excluded for operation with these settings. This conclusion assumes that the device used the uploaded settings during the failing tests. A configuration backup cannot establish whether settings changed during later tests.

    The settings do not exclude a separate leak in Wi-Fi, Ethernet, or UDP handling.

    You are interacting with an AI system.

  18. softhack007 commented on Oct 23, 2026

    @softhack007
  19. coderabbitai commented on Oct 23, 2026

    @coderabbitai
  20. softhack007 commented on Oct 23, 2026

    @softhack007
  21. coderabbitai commented on Oct 23, 2026

    @coderabbitai
  22. coderabbitai commented on Oct 23, 2026

    @coderabbitai
  23. coderabbitai commented on Oct 23, 2026

    @coderabbitai
  24. softhack007 commented on Oct 23, 2026

    @softhack007
    Member

    The WiFiUDP problem discussion (master blocks itself from receiving any UDP sync messages) is moved into #5929

  25. gvillant commented on Oct 27, 2026

    @gvillant
    Author

    I won't have access to the hardware before ~20 November, so here is everything we have, to help reproduce it on your side.

    @softhack007 @Aircoookie about #5932 / #5929: on my setup the sync master very likely receives its own broadcasts, which may be why I see it and you don't. It had Ethernet and Wi-Fi connected at the same time, on the same subnet, with the same static IP: the static IP from the Wi-Fi settings is applied to both ETH.config() and WiFi.config(). So each sync broadcast sent on one interface can come back on the other one, with remoteIP() == localIP, and hit the early return at every send.

    Free heap over 17 h (master = red, one receiver = grey, ~1 sample/min):

    Image
    Phase Firmware Master network What happens to the master's free heap
    A 0.15.4 Ethernet only, Wi-Fi SSID set to a network that doesn't exist flat (~114 kB) over the 4.5 h logged, preset change every 60 s
    B 16.0.1 same as A −3.5 to −4 kB/min continuously, OOM reboot after ~21 min; keeps dropping with the playlist stopped
    C 16.0.1 Ethernet + Wi-Fi, same IP drops only at preset changes; flat for 47 min while the playlist was paused (Art-Net stream from a PC, no sync sent)
    D 16.0.1 Wi-Fi only ~5 kB/h; same 20-change test as in C: no loss

    The receiver runs the same 16.0.1 build with Ethernet + Wi-Fi on the same IP, and stays flat the whole time.

    Raw data (time, phase, master free heap / uptime / preset, receiver free heap / uptime):

    heap-log-2026-10-21_22.csv

    Correction to my first report. The "Wi-Fi disabled (Ethernet only)" rows in the issue description were not really Wi-Fi off. I had set the SSID to a network that doesn't exist, which is the phase B situation above. All per-change tests so far, on the same board:

    Firmware Master network Free heap per change (20 changes)
    16.0.0 Ethernet + Wi-Fi, same IP −1202 B and −1348 B (two runs, 5 s apart)
    16.0.0 Ethernet + SSID not found −997 B
    16.0.1 Ethernet + SSID not found −544 B, −342 B, −342 B (5 s apart)
    0.15.4 Ethernet + SSID not found −56 B, +6 B
    16.0.1 Ethernet + Wi-Fi, same IP −665 B (10 s apart)
    16.0.1 Wi-Fi only (Ethernet type None) +10 B

    The 16.0.1 "SSID not found" runs lasted ~100 s each. −6.8 kB in 100 s is exactly the continuous ~4 kB/min loss of phase B. So the "−340 B per notification on 16.0.1" in my first post is most likely that time-based loss, not a per-send cost. What I never tested is Ethernet with no SSID configured at all. That's the clean "Ethernet only" case, and it's first on my list when I get the board back.

    Exact firmware. QuinLED builds, not the stock esp32_eth env:

    Setup. 5 × QuinLED Dig-Quad V3 (ESP32, Ethernet type "QuinLED-ESP32"):

    • network: one /24 subnet, static IPs, a consumer Wi-Fi router plus an unmanaged 8-port D-Link switch;
    • the master: playlist of 18 presets (60 s each, 0.7 s transition), UDP sync send on (port 21324, group 1), ESP-NOW off, 4 segments, 681 LEDs;
    • receivers: one on Ethernet + Wi-Fi, three on Wi-Fi only, sync receive only (segment options and bounds off);
    • the cfg/presets files are in the zip posted above.

    Steps to reproduce with any ESP32 + Ethernet board

    1. Flash 16.0.1 and connect both Ethernet and Wi-Fi to the same LAN, with a static IP in the Wi-Fi settings so both interfaces get the same address.
    2. Enable "Send broadcast" (UDP sync), ESP-NOW off. Save a few presets with different effects.
    3. Change preset every 10 s (or run a playlist) and watch free heap in Info. Expected: about −0.7 to −1.5 kB per change.
    4. Control: set Ethernet type to "None" and reboot. The loss should go away.
    5. Separate case: Ethernet on and the Wi-Fi SSID set to a network that doesn't exist. Expected: continuous loss of ~4 kB/min with no sync sent at all.

    Test script, the one used for the per-change numbers above. It reads /json/info (max of 3 reads) before and after N preset changes, with a control mode that sends the same changes with "udpn":{"nn":true}.

    heap_sync_test.py
    """Measure WLED free heap loss per preset change (with UDP sync sent).
    
    Usage: python heap_sync_test.py <device-ip> [changes] [interval_s] [preset ids...]
    Example: python heap_sync_test.py 192.168.1.21 20 10 3 4 5 6 7 8 9 10 11 12
    
    The device must have "Send broadcast" (UDP sync) enabled and the listed presets saved.
    Free heap is read from /json/info as the max of 3 reads (the JSON request itself uses heap).
    A first preset is loaded with "udpn":{"nn":true} (no sync sent) so the baseline is settled.
    Run it again with SEND_SYNC = False as a control: same preset changes, no sync sent.
    """
    import json, sys, time, urllib.request
    
    SEND_SYNC = True
    
    ip = sys.argv[1]
    changes = int(sys.argv[2]) if len(sys.argv) > 2 else 20
    interval = float(sys.argv[3]) if len(sys.argv) > 3 else 10
    presets = [int(x) for x in sys.argv[4:]] or [1, 2, 3, 4, 5]
    
    def post(obj):
        req = urllib.request.Request(f"http://{ip}/json/state", data=json.dumps(obj).encode(),
                                     headers={"Content-Type": "application/json"})
        urllib.request.urlopen(req, timeout=5).read()
    
    def info():
        return json.loads(urllib.request.urlopen(f"http://{ip}/json/info", timeout=5).read())
    
    def heap():
        values = []
        for _ in range(3):
            values.append(info()["freeheap"]); time.sleep(0.3)
        return max(values)
    
    post({"ps": presets[0], "udpn": {"nn": True}}); time.sleep(15)
    i = info()
    print(f"{i['ver']} | uptime {i['uptime']} s | wifi bssid {i['wifi'].get('bssid') or '-'} | ws clients {i.get('ws')}")
    h0 = heap()
    for k in range(changes):
        cmd = {"ps": presets[k % len(presets)]}
        if not SEND_SYNC: cmd["udpn"] = {"nn": True}
        post(cmd); time.sleep(interval)
    h1 = heap()
    print(f"sync {'sent' if SEND_SYNC else 'NOT sent'}: {h0} -> {h1} = {h1 - h0:+d} B, {(h1 - h0) / changes:+.0f} B per change")

    When I get the board back, I'll first test Ethernet with no SSID configured, then flash the #5932 CI build (esp32_eth) and rerun phases B, C and D.

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

    AIPartly generated by an AI. Make sure that the contributor fully understands the code!bugneeds investigationThe bug has not yet been reproduced by me. Analysis or more details are needed.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址