Commit Graph

22957 Commits

Author SHA1 Message Date
J. Nick Koston
3306fb2d21 Merge remote-tracking branch 'upstream/libretiny-lwip-tune' into integration 2026-02-21 17:50:04 -06:00
J. Nick Koston
ca82c7c7c6 [socket] Show (min) indicator when platform minimums are applied
Helps users understand why socket counts may be higher than what
their components registered.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 17:49:45 -06:00
J. Nick Koston
096694cd6b Merge remote-tracking branch 'upstream/libretiny-lwip-tune' into integration 2026-02-21 17:48:51 -06:00
J. Nick Koston
fadf7a2ba3 [socket] Lower minimum socket counts (TCP=8, UDP=6)
Previous minimums (10/8) were overly conservative. Most configs
register their actual needs via consume_sockets(), so the minimums
only need to cover unregistered components with modest headroom.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 17:48:35 -06:00
J. Nick Koston
2ece30ed76 Merge remote-tracking branch 'upstream/libretiny-lwip-tune' into integration 2026-02-21 17:47:20 -06:00
J. Nick Koston
e3154e48bd [libretiny] Log socket component details during lwIP configuration
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 17:47:06 -06:00
J. Nick Koston
2727f9c74f Merge remote-tracking branch 'upstream/libretiny-lwip-tune' into integration 2026-02-21 17:45:31 -06:00
J. Nick Koston
341b22c7e4 [socket] Include component details in platform lwIP log messages
get_socket_counts() now returns component detail strings alongside
counts so platforms can include them in their log messages. ESP32
INFO log now shows which components consume each socket type.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 17:45:13 -06:00
J. Nick Koston
1518875cd2 Merge remote-tracking branch 'origin/libretiny-lwip-tune' into integration 2026-02-21 17:41:18 -06:00
J. Nick Koston
0c184ce791 [esp32] Include TCP_LISTEN in CONFIG_LWIP_MAX_SOCKETS count
CONFIG_LWIP_MAX_SOCKETS is a single VFS socket pool shared by all
socket types. Listening sockets consume file descriptors too, so
they must be included in the total.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 17:40:47 -06:00
J. Nick Koston
f87a0b24a9 Merge remote-tracking branch 'origin/libretiny-lwip-tune' into integration 2026-02-21 17:34:47 -06:00
J. Nick Koston
e74506b957 Merge branch 'scheduler_de_template' into integration 2026-02-21 17:34:37 -06:00
J. Nick Koston
9b1480840f Merge remote-tracking branch 'upstream/dev' into scheduler_de_template
# Conflicts:
#	esphome/core/scheduler.h
2026-02-21 17:31:57 -06:00
J. Nick Koston
462ac29563 [scheduler] Use relaxed memory ordering for atomic reads under lock (#14140) 2026-02-21 17:29:41 -06:00
J. Nick Koston
8aa77c306f [socket] Fix docstring and comment accuracy
- Update MIN_TCP_SOCKETS comment: api(3) + web_server(5) = 8 typical
- Add TCP_LISTEN to consume_sockets docstring

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 17:19:20 -06:00
J. Nick Koston
7a1448ed19 Update esphome/components/socket/__init__.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-21 17:18:21 -06:00
J. Nick Koston
bfde66f7f4 [socket] Update comments for new TCP_LISTEN registration model
- 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>
2026-02-21 17:10:29 -06:00
J. Nick Koston
c90ab6f72f [socket] Remove legacy aliases, fix NETCONN count, add comments
- 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>
2026-02-21 17:07:46 -06:00
J. Nick Koston
d630166280 [socket] Track TCP listening sockets separately via SocketType.TCP_LISTEN
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>
2026-02-21 17:00:40 -06:00
J. Nick Koston
5b5bc28ba3 [libretiny] Enable MEM_LIBC_MALLOC + MEMP_MEM_MALLOC on all platforms
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>
2026-02-21 16:37:56 -06:00
J. Nick Koston
30d694e62e [libretiny] Enable MEMP_MEM_MALLOC=1 on BK72XX for dynamic MEMP pools
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>
2026-02-21 16:19:18 -06:00
J. Nick Koston
770e3092a5 [libretiny] Fix MEMP_NUM_NETCONN double-counting listening sockets
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>
2026-02-21 15:54:42 -06:00
J. Nick Koston
e463dc331e [libretiny] Use system heap for BK72XX lwIP (MEM_LIBC_MALLOC=1)
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>
2026-02-21 15:37:03 -06:00
J. Nick Koston
6adbb34fbb [libretiny] Show BK72XX reduced/default plan values for MEM_SIZE
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>
2026-02-21 15:05:18 -06:00
J. Nick Koston
18c89a1cce [libretiny] Set BK72XX PBUF_POOL_SIZE to 10 to match default plan
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>
2026-02-21 14:58:11 -06:00
J. Nick Koston
2b00a809c8 [libretiny] Fix BK72XX lwIP sanity check for reduced-plan boards
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>
2026-02-21 14:42:30 -06:00
J. Nick Koston
6f198adb0c [scheduler] Reduce lock acquisitions in process_defer_queue_ (#14107) 2026-02-21 14:29:50 -06:00
J. Nick Koston
5d44a556a4 [socket] Increase MIN_UDP_SOCKETS from 6 to 8
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>
2026-02-21 14:15:52 -06:00
J. Nick Koston
f55387b323 [wifi] Guard lwIP-internal socket registration to LibreTiny only
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>
2026-02-21 14:11:19 -06:00
J. Nick Koston
e521522b38 [haier] Fix uninitialized HonSettings causing API connection failures (#14188) 2026-02-21 13:54:43 -06:00
J. Nick Koston
5a07908dfa [api] Fix build error when lambda returns StringRef in homeassistant.event data (#14187) 2026-02-21 13:54:20 -06:00
J. Nick Koston
9571a979eb [ci] Suggest StringRef instead of std::string_view (#14183) 2026-02-21 13:53:45 -06:00
J. Nick Koston
38984b61c9 [wifi] Track lwIP-internal DHCP+DNS UDP PCBs via socket consumer API
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>
2026-02-21 13:33:50 -06:00
J. Nick Koston
4114620aee [libretiny] Fix RTL87xx BD_RAM overflow — use per-SDK lwIP defaults
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>
2026-02-21 13:23:42 -06:00
tomaszduda23
48ba007c22 [nrf52] print line number after crash in logs (#14165) 2026-02-21 14:16:20 -05:00
J. Nick Koston
482721d1ce [libretiny] Tune oversized lwIP defaults for ESPHome
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
2026-02-21 11:50:29 -06:00
Clyde Stubbs
6ff17fbf7c [epaper_spi] Fix color mapping for weact (#14134) 2026-02-22 04:17:54 +11:00
J. Nick Koston
416b97311b [mqtt] Remove broken ESP8266 ssl_fingerprints option (#14182) 2026-02-21 11:12:35 -06:00
J. Nick Koston
7fb09da7cf [dsmr] Add deprecated std::string overload for set_decryption_key (#14180) 2026-02-21 11:08:13 -06:00
Sxt Fov
6ecb01dedc [cc1101] actions to change general and tuner settings (#14141)
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
2026-02-21 08:45:15 -05:00
Clyde Stubbs
518f08b909 [mipi_dsi] Disallow swap_xy (#14124) 2026-02-21 19:51:13 +11:00
J. Nick Koston
9adb2dd3f1 Merge remote-tracking branch 'upstream/dev' into integration 2026-02-20 23:45:45 -06:00
Rodrigo Martín
2eac106f11 [mqtt] add missing precision in HA autodiscovery (#14010) 2026-02-20 23:20:27 -05:00
J. Nick Koston
681bdf16aa Merge remote-tracking branch 'upstream/dev' into integration 2026-02-20 21:40:33 -06:00
J. Nick Koston
f77da803c9 [api] Write protobuf encode output to pre-sized buffer directly (#14018) 2026-02-20 21:39:18 -06:00
J. Nick Koston
f8f98bf428 [logger] Reduce UART driver heap waste on ESP32 (#14168) 2026-02-21 03:16:49 +00:00
J. Nick Koston
abe37c9841 [uptime] Use scheduler millis_64() for rollover-safe uptime tracking (#14170) 2026-02-21 03:08:49 +00:00
J. Nick Koston
8589f80d8f [api,ota,captive_portal] Fix fd leaks and clean up socket_ip_loop_monitored setup paths (#14167) 2026-02-20 20:59:49 -06:00
J. Nick Koston
f3b1ae6ba5 Merge branch 'setup_heap_stats' into integration 2026-02-20 20:51:54 -06:00
J. Nick Koston
487d311dbc tweak 2026-02-20 20:51:36 -06:00