CPY V8.0.0-rc.2 socketpool sock.recv_into() hangs

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
paulskpt
 
Posts: 30
Joined: Sat Oct 03, 2015 7:30 pm

CPY V8.0.0-rc.2 socketpool sock.recv_into() hangs

Post by paulskpt »

I am porting a script that ran OK in Python on a Raspberry Pi to receive, decode and display UDP datagram packets broadcasted in the LAN by X-Plane flight simulator to Circuitpython v8.0.0-rc.2 on an Adafruit Feather ESP32-S2 with TFT. I am using the displayio module to present texts and logos onto the TFT display. This part works fine. Even connecting to internet, receiving NTP datetime. The flight simulator is running on a desktop PC running MS Windows 11 Pro. I added rules for UDP in/out packets to certain ranges of ports in the Defender firewall. I also set port triggering in the router of my ISP. On the desktop PC I checked and saw, using the Wireshark app, that the flight simulator was broadcasting BECN and DATA UDP packets to group '239.255.1.1', port 49707.
The CircuitPython script is performing OK until the line:

Code: Select all

size = sock.recv_into(packet)
At this line the script hangs forever.

To prepare for UDP packet reception the following commands are used:
(Note that WiFi is established. CPY is showing an IP address).

Code: Select all

pool = socketpool.SocketPool(wifi.radio)
sock = pool.socket(pool.AF_INET, pool.SOCK_DGRAM)
sock.bind((MCAST_GRP, MCAST_PORT))  # MCAST_GRP = '239.255.1.1', MCAST_PORT = 49707
packet_size = 61  # the packet frame size of a BECN (beacon) UDP packet. 
packet = bytearray(packet_size)
size = sock.recv_into(packet)     # <<<=== HERE THE SCRIPT HANGS FOREVER

The script idea is similar than the example in 'UDP Sender and Receiver in CircuitPython': https://gist.github.com/todbot/877b2037 ... id=4278796

Anyone have some idea? Or do I have to create an issue on Github Adafruit Circuitpython ?

User avatar
paulskpt
 
Posts: 30
Joined: Sat Oct 03, 2015 7:30 pm

Re: CPY V8.0.0-rc.2 socketpool sock.recv_into() hangs

Post by paulskpt »

Problem solved with help of @todbot https://gist.github.com/todbot/877b2037 ... c83c6e2182.
My error was that in the line with the 'sock.bind()' command I used a MULTICAST_GROUP address ('193.255.1.1') instead of the IP-address of the CircuitPython device this script is running on. The following line instead, solved it:

Code: Select all

self.my_DataRef_sock.bind((str(wifi.radio.ipv4_address), self.MCAST_PORT)) 

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”