adafruit / adafruit/Adafruit_CircuitPython_ESP32SPI
UDP server limited to receiving <=1472 byte packets
- Dominant language
- Python
- Stars
- 102
- Forks
- 71
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 1
Description
`Adafruit CircuitPython 10.0.3 on 2025-10-17; Adafruit PyPortal with samd51j20` with ESP32SPI latest v9.0.4
Helping with a ESP32SPI UDP server issue on [Discord](https://discord.com/channels/327254708534116352/537365702651150357/1431145354648227973), ran into a limit on the size of packets that can be received, at a max of 1472. It should allow much higher, something approaching 65535. This may be due to underlying code sharing some functions between TCP and UDP.
CircuitPython server code...
```py
import time
import os
import board
import digitalio
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socketpool as socketpool
from adafruit_esp32spi import adafruit_esp32spi
PORT = 5000
spi = board.SPI()
# edit pins to match board
esp32_cs = digitalio.DigitalInOut(board.ESP_CS)
esp32_reset = digitalio.DigitalInOut(board.ESP_RESET)
esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY)
radio = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, debug=0)
pool = adafruit_connection_manager.get_radio_socketpool(radio)
print(f'Connecting to wifi... ', end='')
radio.connect(os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD"))
print(f'{radio.ipv4_address}')
print("Create UDP Server Socket")
s = pool.socket(type=pool.SOCK_DGRAM)
radio.start_server(PORT, s._socknum, conn_mode=1) # UDP_MODE = const(1)
while True:
numbytes_avail = radio.socket_available(s._socknum)
if numbytes_avail:
print(f'{time.monotonic():.03f} {numbytes_avail}', end=" ")
bytes_read = radio.socket_read(s._socknum, numbytes_avail)
print(f'{bytes_read[:10]}...{bytes_read[(numbytes_avail - 10):]}')
```
CPython client code...
```py
#!/usr/bin/env python3
import time
import socket
import random
# edit host and port to match server
HOST = "192.168.6.39"
PORT = 5000
PKTSIZE = 1472
INTERVAL = 1
choices = iter(b'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')
while True:
outbuf = bytearray()
element = next(choices, 255)
for _ in range(PKTSIZE):
outbuf.append(element)
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
size = s.sendto(outbuf, (HOST, PORT))
print(f'{time.monotonic():.03f} sent {size} bytes of {chr(element)} to {HOST}:{PORT}')
time.sleep(INTERVAL)
```
The behavior if the sent size is >1472 is that the server seems to loop through `socket_available` and `socket_read` without reading any more bytes (control-C exits).
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the issue with the supplied CircuitPython server and CPython UDP client, varying the packet size above 1472 bytes. Then trace the ESP32SPI implementations of socket_available and socket_read and their UDP server path. Done means the server receives the complete UDP datagram rather than looping without reading the remaining bytes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100