One example of a server I found uses bind() but that doesn't exist in the MP CircuitPython 8.0.0 rc2. Probably because the ESP32 is driven by SPI and not loaded with CP
I can get a UDP server working on a Pimoroni Interstate 75 W (Rpi Pico) and can almost get 25fps. I send the video frames from a python script on my desktop machine which does all the frame resizing and LED brightness compensation.
I can also get an FTP server working on the MP but it is slow due to FTP handshake (about 10fps).
I can get a UDP client working - an example I found which gets time from pool.ntp.org. But this sends a UDP packet to pool.ntp.org and receives a packet back.
The code I'm trying to use is below. It connects to my wifi network ok and reports an IP address 192.168.1.202. Ping to that address gets a response from the MP.
I have read all the code in the adafruit_esp32spi library folder trying to find out what is going on.
I must be missing something OR a UDP server is impossible on the MP. Whch is it?
Can anyone help? Has anyone gotten a UDP server to work on the MP?
Thanks for reading.
Regards
Brian
Code: Select all
# Adafruit CircuitPython 8.0.0-rc.2 on 2023-02-02; Adafruit Matrix Portal M4 with samd51j19
import time
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import os
PORT = 8000
CREATE_AP=False # True= create a new AP (192.168.4.1) otherwise get Ip by dhcp
PORTAL_SSID="Portal" # only needed if CREATE_AP is True
PORTAL_PASS=None # open AP
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)
if CREATE_AP:
# create AP creates a server with an ip address 192.168.4.1
esp.create_AP(PORTAL_SSID,PORTAL_PASS)
print(f"Now an AP: RSSI ={ esp.rssi} IP={esp.pretty_ip(esp.ip_address)} port:{PORT}")
else:
# connect_AP connects to the existing network
esp.connect_AP(os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD"))
print(f"Connected to AP: RSSI ={ esp.rssi} IP={esp.pretty_ip(esp.ip_address)} port:{PORT}")
s = socket.socket(type=socket.SOCK_DGRAM)
esp.start_server(PORT, s.socknum, conn_mode=1,ip=esp.ip_address) # conn_mode=UDP (see ESP_SPIcontrol)
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)
time.sleep(0.1)