- OTA: note that active transfer uses a TCP PCB from general pool
- MIN_TCP_SOCKETS: update base count to api(3) after TCP_LISTEN split
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove SOCKET_TCP/SOCKET_UDP aliases, use SocketType.UDP everywhere
- Fix MEMP_NUM_NETCONN to include listening_tcp (listeners need netconns)
- Add comment on listening_tcp minimum (not all components register yet)
- Add comment on MAX_LISTENING_SOCKETS_TCP (BK-specific, RTL/LN use
MEMP_NUM_TCP_PCB_LISTEN directly)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Components now register their listening sockets explicitly instead of
relying on a hardcoded count. web_server_base registers the shared
HTTP listener (used by both web_server and captive_portal). The
libretiny lwIP config derives MEMP_NUM_TCP_PCB_LISTEN dynamically
from these registrations.
Also fixes captive_portal to correctly register its DNS socket as UDP
instead of TCP.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move MEM_LIBC_MALLOC=1 and MEMP_MEM_MALLOC=1 from BK72XX-only to all
LibreTiny platforms. All three SDKs (BK/RTL/LN) wire malloc to
FreeRTOS pvPortMalloc (thread-safe), and WiFi receive paths run in
task context.
Tested on RTL87xx (BW15): 84,184 B → 103,744 B free heap (~19.6KB
freed). OTA and web server confirmed working.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Allocate all MEMP pools (TCP PCBs, UDP PCBs, netconns, TCP segments,
pbufs, etc.) from the heap on demand instead of pre-allocated static
arrays. Saves ~20KB RAM on BK7231N (87,312 B free vs 67,144 B before).
Safe because the BK WiFi driver's receive path runs in task context
(core_thread pops from g_wifi_core.io_queue), not ISR context.
ESP32 and ESP8266 both ship with MEMP_MEM_MALLOC=1.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Listening sockets are already included in the TCP socket count from
component registrations (e.g. api registers 1 listening + 3 clients).
Remove the extra listening_tcp from MEMP_NUM_NETCONN to avoid
over-provisioning.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the dedicated lwIP heap (MEM_SIZE=16/32KB) with system malloc
on BK72XX, matching what LN882H and ESP8266 already do. The BK SDK's
malloc wraps FreeRTOS pvPortMalloc which is thread-safe.
This eliminates the dedicated pool bottleneck that caused OTA slowness
when MEM_SIZE was reduced to 5KB, and frees ~5.9KB heap on BK7231N
(61,264 B → 67,144 B).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BK SDK has two plans: reduced (16KB) and default (32KB). Show both
in the docstring table for accuracy.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PBUF_POOL_SIZE=4 was the minimum to pass lwIP's sanity check but caused
pbuf exhaustion during concurrent connections (API + web_server + OTA),
resulting in dropped log messages.
Set to 10 to match the BK SDK default plan and ESP8266. RTL/LN already
default to 20 and need no override.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BK SDK boards with CFG_LWIP_MEM_POLICY=LWIP_REDUCE_THE_PLAN (e.g. CB3S/
BK7231N) set PBUF_POOL_SIZE=3, which is too small for TCP_WND=4*MSS:
3*(1580-54)=4578 < 5840. Set PBUF_POOL_SIZE=4 on BK72XX so the lwIP
compile-time sanity check passes: 4*1526=6104 > 5840.
RTL(20) and LN(20) already have large enough PBUF pools.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Now that DHCP+DNS are tracked as wifi.lwip_internal UDP consumers,
the old minimum of 6 only left 4 free PCBs. Bumping to 8 restores
the same effective headroom as before (6 free after DHCP+DNS).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DHCP/DNS raw UDP PCBs only need tracking on LibreTiny where we directly
set MEMP_NUM_UDP_PCB. On ESP32, CONFIG_LWIP_MAX_SOCKETS controls the
POSIX socket layer — DHCP/DNS use raw udp_new() bypassing it entirely.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Register the 2 UDP PCBs that lwIP allocates internally for DHCP and DNS
as a wifi.lwip_internal socket consumer, eliminating the magic +2 in
libretiny's MEMP_NUM_UDP_PCB calculation. Also corrects SDK default
values in the comparison table after line-by-line verification against
all three SDK source files.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The original table treated BK/RTL/LN SDK defaults as identical, but
they differ significantly:
- BK72XX: MEM_SIZE=32KB, TCP_SND_BUF=10×MSS — wildly oversized
- RTL87XX: MEM_SIZE=5KB, TCP_SND_BUF=5×MSS — already conservative
- LN882H: MEM_LIBC_MALLOC=1, TCP_SND_BUF=7×MSS — uses system heap
Setting MEM_SIZE=16KB on RTL87XX was an 11KB *increase* from its 5KB
SDK default, causing BD_RAM overflow on the mqtt test.
Fix: only set MEM_SIZE on BK72XX (where the 32KB→12KB reduction is
needed). RTL87XX keeps its SDK 5KB default, LN882H doesn't use it.
The comparison table is updated with accurate per-SDK columns.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Beken/RTL SDKs ship lwIP defaults tuned for a general-purpose WiFi
SoC: TCP_SND_BUF=10*MSS (14.6KB), MEM_SIZE=32KB, 12 TCP + 22 UDP
sockets. These waste significant RAM on memory-constrained chips.
ESPAsyncWebServer allocates malloc(tcp_sndbuf()) per response chunk,
and at 14.6KB this causes OOM on BK7231N.
This tunes lwIP to match ESP32/ESP8266 ranges:
- TCP_SND_BUF/TCP_WND: 4*MSS (was 10*MSS)
- MEM_SIZE: 12KB BK72XX / 16KB RTL,LN (was 32KB)
- Socket counts: dynamic from component registrations
- All derived pool sizes adjusted accordingly
Also splits socket consumer tracking into TCP/UDP, adds
get_socket_counts() API, and updates ESP32 to use it.
Closes https://github.com/esphome/esphome/issues/14095
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>