Last active
June 1, 2024 16:58
-
-
Save anecdata/61dfb2e5f4649a1a42885f8e9314800a to your computer and use it in GitHub Desktop.
ESP32SPI UDP Server test code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adafruit CircuitPython 9.1.0-beta.2 on 2024-05-15; FeatherS3 with ESP32S3 | |
# Adafruit Airlift FeatherWing w/ NINA 1.7.7 | |
# ESP32SPI v8.3.1 | |
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() | |
esp32_cs = digitalio.DigitalInOut(board.D13) | |
esp32_reset = digitalio.DigitalInOut(board.D12) | |
esp32_ready = digitalio.DigitalInOut(board.D11) | |
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}', end=" ") | |
remote_data = radio.get_remote_data(s._socknum) | |
remote_ip = radio.pretty_ip(remote_data["ip_addr"]) | |
remote_port = remote_data["port"] | |
print(f'REMOTE: {remote_ip}:{remote_port}') |
Author
anecdata
commented
Jun 1, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment