我用 esp32 协处理器举起了羽毛。esp 通过 spi 连接,我用这个库“adafruit_esp32spi.adafruit_esp32spi_socket”创建了一个套接字。通常我会收到至少 200 个包裹,但在某些时候,它会停止工作。使用 socket.recv(1500) 我读出了缓冲区,但它总是空的。你们有没有类似的问题?你怎么修的。我喜欢circuitpython,但它看起来很糟糕,偷走了它的乐趣。
如果重要:我在 art-net 协议中接收 25fps 来控制 LED 矩阵
我缩短了代码,但问题仍然存在......
TIMEOUT = 5 # time out socket
HOST = "192.168.4.1" # listing for this host
PORT = 1030 # listing on this port from the host
### imports ###
import time
import board
from digitalio import DigitalInOut
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import udp_decoder
import neopixel
# Get wifi details and more from a secrets.py file
# adafruit standard
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
### wired pins ###
# to esp32
spi = board.SPI()
esp32_cs = DigitalInOut(board.D13)
esp32_ready = DigitalInOut(board.D11)
esp32_reset = DigitalInOut(board.D12)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
connected = 0
while not connected:
try:
# connect to wifi AP (RPI)
esp.connect(secrets)
print(connected)
connected = 1
except:
print("Tryng to connect again")
print("My IP address is", esp.pretty_ip(esp.ip_address))
# test for connectivity to server
print("Server ping:", esp.ping(HOST), "ms")
# create the socket
socket.set_interface(esp)
socketaddr = socket.getaddrinfo(HOST, PORT)[0][4]
s = socket.socket(type=socket.SOCK_DGRAM)
s.settimeout(TIMEOUT)
s.connect(socketaddr, conntype=esp.UDP_MODE)
ii = 0
while 1:
print("looping")#see if still alive
# amount = s.available() # also not vorking
amount = s.recv(1500)
if amount:
# here would be my code
print(ii)
ii += 1
time.sleep(0.0025) #estimated time for neopixel control of my matrix