Skip to content

Instantly share code, notes, and snippets.

@anecdata
Created March 20, 2022 03:37
Show Gist options
  • Save anecdata/b3d43870942684570d90e3fc9833292b to your computer and use it in GitHub Desktop.
Save anecdata/b3d43870942684570d90e3fc9833292b to your computer and use it in GitHub Desktop.
UDP Server ESP32SPI read-only (very rudimentary)
import time
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
from secrets import secrets
PORT = 5000
spi = board.SPI()
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
socket.set_interface(esp)
esp.connect_AP(secrets["ssid"], secrets["password"])
print("Connected:", "RSSI =", esp.rssi)
s = socket.socket(type=socket.SOCK_DGRAM)
esp.start_server(PORT, s.socknum, conn_mode=1) # ip=
while True:
numbytes_avail = esp.socket_available(s.socknum)
if numbytes_avail:
print(numbytes_avail)
bytes_read = esp.socket_read(s.socknum, numbytes_avail)
print(bytes_read)
@anecdata
Copy link
Author

Arduino functions WiFiUDP.remoteIP() and WiFiUDP.remotePort() are accessed by NINA firmware function getRemoteData() (command code 0x3A), which is unimplemented in the ESP32SPI library as of v4.0.2.

@anecdata
Copy link
Author

anecdata commented Sep 6, 2022

NINA firmware function getRemoteData() is now exposed in the ESP32SPI library as of v4.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment