Skip to content

Arduino RP2040 connect wifi UDP - Multicast group not working #139

@manpowre

Description

@manpowre

CircuitPython version

Adafruit 7.0 latest, and master branch (yeah I compiled master).

esp32 wifi chip:
Firmware vers. bytearray(b'1.4.8\x00')

Code/REPL

import time
import board
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import neopixel
from rainbowio import colorwheel
import gc
from secrets import secrets

UDP_IN_ADDR="224.1.1.1"
UDP_IN_PORT = 5500

UDP_TIMEOUT = 20

esp32_cs = DigitalInOut(board.CS1)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)

esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
socket.set_interface(esp)

s_in = socket.socket(type=socket.SOCK_DGRAM)
s_in.settimeout(UDP_TIMEOUT)


if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
    print("ESP32 found and in idle mode")
print("Firmware vers.", esp.firmware_version)
print("MAC addr:", [hex(i) for i in esp.MAC_address])
print("Connecting to AP...")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets["ssid"], secrets["password"])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)
        continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
#esp.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)
time.sleep(1)
IP_ADDR = esp.pretty_ip(esp.ip_address)
print("ip:", esp.ip_address)
print("My IP address is", esp.pretty_ip(esp.ip_address))
print("udp in addr: ", UDP_IN_ADDR, UDP_IN_PORT)



socketaddr_udp_in = socket.getaddrinfo(UDP_IN_ADDR, UDP_IN_PORT)[0][4] 
s_in.connect(socketaddr_udp_in, conntype=esp.UDP_MODE) 
print("connected local UDP")

while True:
    data = s_in.recv(1205)
    if len(data)>=1:
        data=data.decode('utf-8')
        print(len(data), data)


Python on Ubuntu:
# Untitled - By: svein - fre. okt. 15 2021

import socket
import time

def run(group, port):
    MULTICAST_TTL = 40
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, MULTICAST_TTL)
    sock.sendto(b'from multicast_send.py: ' +
                f'group: {group}, port: {port}'.encode(), (group, port))
if __name__ == '__main__':
    while True:
        #run('224.1.1.1', 5500)
        run('192.168.2.147', 5500)
        time.sleep(1)

Behavior

ESP32 found and in idle mode
Firmware vers. bytearray(b'1.4.8\x00')
MAC addr: ['0xd0', '0xb1', '0x78', '0xa8', '0xcc', '0x84']
Connecting to AP...
Connected to zone RSSI: -47
ip: bytearray(b'\xc0\xa8\x02\x93')
My IP address is 192.168.2.147
udp in addr: 224.1.1.1 5500
connected local UDP
-->>> NO PACKETS recieved

ESP32 found and in idle mode
Firmware vers. bytearray(b'1.4.8\x00')
MAC addr: ['0xd0', '0xb1', '0x78', '0xa8', '0xcc', '0x84']
Connecting to AP...
Connected to zone RSSI: -47
ip: bytearray(b'\xc0\xa8\x02\x93')
My IP address is 192.168.2.147
udp in addr: 192.168.2.147 5500
connected local UDP
56 from multicast_send.py: group: 192.168.2.147, port: 5500
56 from multicast_send.py: group: 192.168.2.147, port: 5500
56 from multicast_send.py: group: 192.168.2.147, port: 5500
56 from multicast_send.py: group: 192.168.2.147, port: 5500

Description

So Ive been testing the wifi part of the circuitpython on the Arduino rp2040 connect.
The circuitpython esp32 wifi integration doesnt allow to set a static IP (Im gonna make a separate bug report on this), and I want to be able to communicate with the rp2040 chip through wifi and send datapackets, but since I dont know the IP adress, I figured I could send a multicast IP instead. On my ubuntu, I do recieve these packages on same multicast IP and port. so the router is out of the question.(As I made a multicast data logger from my rp2040 chip to get debug data from it).

The UDP reciever works with the IP adress of the wifi chip eg. 192.168.2.147:5500, but NOT the multicast adress 224.1.1.1:5500.

I hope you guys can fix this.. and the dhcp=True/False issue aswell.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions