espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.61k stars 7.41k forks source link

AsyncUDP ipv6 Multicast not working #9970

Open friedrichengel opened 4 months ago

friedrichengel commented 4 months ago

Board

ESP-32-Wrover-E

Device Description

Own Hardware, uses Etehrnet (Rj45)

Hardware Configuration

nothing i would think that it has something to do with multicast Ethernet. Ehernet + Webserver in general is working fine.

Version

v3.0.1

IDE Name

VSCode with Platformio

Operating System

Windows 11

Flash frequency

40 Mhz

PSRAM enabled

yes

Upload speed

922190

Description

Settingup an UDP Listener to use IPv6 Multicast dont seem to work.

if you setup your listener with:

IPAddress udp_ip_v6;
udp_ip_v6.fromString("ff02::1"); //"ff02::1" listen_multicast_v6 = udp.listenMulticast(udp_ip_v6, udp_port, 0, TCPIP_ADAPTER_IF_ETH);

It seems to setup this listener and it seems fine. Return Value says it is ok.

If you then wants to send something to this multicast Adress it returns an error. I have tried different ways to send:

1) udp_ip_2.fromString("ff02::1"); udp_send_rv = udp.writeTo((uint8_t*)(temp_casambi_command.c_str()),temp_casambi_command.length(), udp_ip_2, udp_port, TCPIP_ADAPTER_IF_ETH);

2) udp_send_rv = udp.print(temp_casambi_command.c_str());

3) udp_message.write((uint8_t*)(temp_casambi_command.c_str()), temp_casambi_command.length());

But it always returned an error code in most cases it is: ERR_VAL = -6, or ERR_RTE = -4,

If i do it on an non multicast way like listen_v4 = udp.listen(udp_port); listen_v6 = udp.listenIPv6();

and sending it to an known working ip it seems to be fine and i can receive the Packet.

If i send commands directed in ipv4 it also works and if i send it in broadcast in ipv4 it works too.

Sketch

See Description

Debug Message

See Description

Other Steps to Reproduce

I have tried it with different adresses and also changing between TCPIP_ADAPTER_IF_ETH and TCPIP_ADAPTER_IF_MAX or letting it empty. In Multicast it seems not to send something.

I have checked existing issues, online documentation and the Troubleshooting Guide

me-no-dev commented 4 months ago
friedrichengel commented 4 months ago

Yes i have printed all these informations like IP-Adress and return values from listenMulticast and writeTo.

listen_multicast_v6 is true, yes i have checked this. I also added some more debug output to listenMulticast but it does not throw any error.

if changed also the return values from writeTo so i can extract the error codes from inside the async udp library. ERR_VAL = -6, or ERR_RTE = -4,

I have set "-DCORE_DEBUG_LEVEL=5" for my build flags but it does not give me many informations. Is there another way to enable debug output?

I sadly dont have an minimalized example. I could try to change the multicast example from the framework to use ipv6 instead of ipv4.

Strange is that normal ipv6 with directed adresses are working fine.

I would also suppose that i could send to the multicast address directy without joining the multicast group. Because send and receive should be seperated. But i can also not sent to an multicast adress only with listening to udp and enable listenv6.

me-no-dev commented 4 months ago

I have set "-DCORE_DEBUG_LEVEL=5" for my build flags but it does not give me many informations.

You also need to add Serial.setDebugOutput(true); after Serial.begin();

Please devise a minimal example that we can use to exactly reproduce the issue. From code perspective, everything in our lib looks fine. After all it's not much being done, but joining the multicast group and listening.

friedrichengel commented 4 months ago

Ok, i have added a simple sketch basically with all part i think are needed. I hope i didnt forget anything.

https://github.com/friedrichengel/esp32_multicast_sample

I hope it is ok that i put it in an extra repo for easier access. Quick and Dirty.

Debug Output:

--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1288
load:0x40078000,len:13856
load:0x40080400,len:4
ho 8 tail 4 room 4
load:0x40080404,len:3048
entry 0x40080590
[     2][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x400da0f0
[    14][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x400da0c0
[    27][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x400da090
[    41][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x400da060
[    54][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x400da0f0
[    67][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x400da0c0
[    81][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x400da090
[    94][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x400da060
[   108][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x400da0f0
[   121][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x400da0c0
[   135][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x400da090
[   148][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x400da060
��␙ɕ�Օ���5��J�␂���J␂�␂z␂�␂�␂���␂j��␂"յ�����ѥѥ���2�չ��jRT␅       �␓S�%HY.\5�KW�E���}���͡�␂r��␚�ɕ�"յ�����ѥѥ���2�չ��jR�␅           R��S�E��Uk�͒jB���␚�չ␚钲��␅���
␅%J␂������␂B�5R�[   627][I][esp32-hal-psram.c:90] psramInit(): PSRAM enabled
[  1973][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 3 successfully set to type UART_RX (2) with bus 0x3ffbdb6c
[  1984][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 1 successfully set to type UART_TX (3) with bus 0x3ffbdb6c
=========== Before Setup Start ===========
Chip Info:
------------------------------------------
  Model             : ESP32
  Package           : D0WD-Q5
  Revision          : 1.44
  Cores             : 2
  CPU Frequency     : 240 MHz
  XTAL Frequency    : 40 MHz
  Embedded Flash    : No
  Embedded PSRAM    : No
  2.4GHz WiFi       : Yes
  Classic BT        : Yes
  BT Low Energy     : Yes
  IEEE 802.15.4     : No
------------------------------------------
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   373508 B ( 364.8 KB)
  Free Bytes        :   329248 B ( 321.5 KB)
  Allocated Bytes   :    35480 B (  34.6 KB)
  Minimum Free Bytes:   323948 B ( 316.4 KB)
  Largest Free Block:   110580 B ( 108.0 KB)
------------------------------------------
SPIRAM Memory Info:
------------------------------------------
  Total Size        :  4194304 B (4096.0 KB)
  Free Bytes        :  4161192 B (4063.7 KB)
  Allocated Bytes   :    30916 B (  30.2 KB)
  Minimum Free Bytes:  4161192 B (4063.7 KB)
  Largest Free Block:  4128756 B (4032.0 KB)
  Bus Mode          : QSPI
------------------------------------------
Flash Info:
------------------------------------------
  Chip Size         : 16777216 B (16 MB)
  Block Size        :    65536 B (  64.0 KB)
  Sector Size       :     4096 B (   4.0 KB)
  Page Size         :      256 B (   0.2 KB)
  Bus Speed         : 40 MHz
  Bus Mode          : DIO
------------------------------------------
Partitions Info:
------------------------------------------
            otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
               app0 : addr: 0x00010000, size:  6400.0 KB, type:  APP, subtype: OTA_0
               app1 : addr: 0x00650000, size:  6400.0 KB, type:  APP, subtype: OTA_1
             eeprom : addr: 0x00C90000, size:     4.0 KB, type: DATA, subtype: 0x99
                nvs : addr: 0x00C91000, size:  1472.0 KB, type: DATA, subtype: NVS
             spiffs : addr: 0x00E01000, size:  2044.0 KB, type: DATA, subtype: SPIFFS
------------------------------------------
Software Info:
------------------------------------------
  Compile Date/Time : Jul  1 2024 10:22:47
  ESP-IDF Version   : v5.1.4-358-gbd2b9390ef-dirty
  Arduino Version   : 3.0.2
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : OLIMEX ESP32-PoE-ISO
  Arduino Variant   : esp32-poe-iso
  Core Debug Level  : 5
  Arduino Runs Core : 1
  Arduino Events on : 1
  CDC On Boot       : 0
============ Before Setup End ============
[  2536][V][esp32-hal-uart.c:408] uartBegin(): UART0 baud(115200) Mode(800001c) rxPin(3) txPin(1)
[  2545][V][esp32-hal-uart.c:497] uartBegin(): UART0 not installed. Starting installation
[  2556][V][esp32-hal-uart.c:544] uartBegin(): UART0 initialization done.
Debug Console ready
ETH enable v6
[  2571][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type ETHERNET_RMII (49) successfully set to 0x400d6980
[  2585][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type ETHERNET_CLK (50) successfully set to 0x400d6980
[  2597][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type ETHERNET_MCD (51) successfully set to 0x400d6980
[  2609][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type ETHERNET_MDIO (52) successfully set to 0x400d6980
[  2621][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type ETHERNET_PWR (53) successfully set to 0x400d6980
eth_mac->write_phy_reg(eth_mac, phy_addr, 0x1f, 0x8180);
[  5469][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 0 successfully set to type ETHERNET_CLK (50) with bus 0x3ffc16d0
[  5469][V][ETH.cpp:104] _onEthEvent(): eth0 Started
[  5485][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 1 - ETH_START
[  5486][V][ETH.cpp:95] _onEthEvent(): eth0 Connected
ETH Started
[  5485][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 23 successfully set to type ETHERNET_MCD (51) with bus 0x3ffc16d[  5498][V][NetworkEvents.cpp:119] ch[ k55rEv[V][Ne NetkInk Evant.cp - E] _CONpECTED
: eth0 Got New IP: 192.168.1.10 MASK: 255.255.255.0 GW: 192.168.1.1
0
[  5523][V][ETH.cpp:80] onEthConnected(): Enabled IPv6 Link Local on eth0
ETH Connected
[  5529][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 5 - ETH_GOT_IP
ETH MAC: 8C:4B:14:AA:0A:0B
IPv4: 192.168.1.10
FULL_DUPLEX, 100Mbps
Use this URL to connect: http://192.168.1.10/
[  5548][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 18 successfully set to type ETHERNET_MDIO (52) with bus 0x3ffc16d0
[  5560][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 21 successfully set to type ETHERNET_RMII (49) with bus 0x3ffc16d0
[  5571][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 19 successfully set to type ETHERNET_RMII (49) with bus 0x3ffc16d0
[  5582][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 22 successfully set to type ETHERNET_RMII (49) with bus 0x3ffc16d0
[  5593][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 25 successfully set to type ETHERNET_RMII (49) with bus 0x3ffc16d0
[  5605][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 26 successfully set to type ETHERNET_RMII (49) with bus 0x3ffc16d0
[  5616][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 27 successfully set to type ETHERNET_RMII (49) with bus 0x3ffc16d0
[  5627][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 12 successfully set to type ETHERNET_PWR (53) with bus 0x3ffc16d0
[  6633][V][NetworkInterface.cpp:111] _onIpEvent(): IF eth0 Got IPv6: Interface: 3, IP Index: 0, Type: LINK_LOCAL, Zone: 2 (en1), Address: fe80:0000:0000:0000:8e4b:14ff:feaa:0a0b
[  6650][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 7 - ETH_GOT_IP6
ETH IPv6 local: fe80::8e4b:14ff:feaa:a0b
[  7633][V][NetworkInterface.cpp:111] _onIpEvent(): IF eth0 Got IPv6: Interface: 3, IP Index: 1, Type: GLOBAL, Zone: 0 (), Address: 2001:1111:2222:3333:8e4b:14ff:feaa:0a0b
[  7649][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 7 - ETH_GOT_IP6
ETH IPv6 local: fe80::8e4b:14ff:feaa:a0b
ETH IPv6 global: 2001:1111:2222:3333:8e4b:14ff:feaa:a0b
UDP-Listen: MC[1] v4:[0] v6:[0]
UDP Listening on IPv4+v6: 192.168.1.10 Port: 10009
=========== After Setup Start ============
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   373508 B ( 364.8 KB)
  Free Bytes        :   279228 B ( 272.7 KB)
  Allocated Bytes   :    83500 B (  81.5 KB)
  Minimum Free Bytes:   279028 B ( 272.5 KB)
  Largest Free Block:   110580 B ( 108.0 KB)
------------------------------------------
SPIRAM Memory Info:
------------------------------------------
  Total Size        :  4194304 B (4096.0 KB)
  Free Bytes        :  4161192 B (4063.7 KB)
  Allocated Bytes   :    30916 B (  30.2 KB)
  Minimum Free Bytes:  4161192 B (4063.7 KB)
  Largest Free Block:  4128756 B (4032.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------
     0 : ETHERNET_CLK
     1 : UART_TX[0]
     3 : UART_RX[0]
    12 : ETHERNET_PWR
    18 : ETHERNET_MDIO
    19 : ETHERNET_RMII
    21 : ETHERNET_RMII
    22 : ETHERNET_RMII
    23 : ETHERNET_MCD
    25 : ETHERNET_RMII
    26 : ETHERNET_RMII
    27 : ETHERNET_RMII
============ After Setup End =============
UDP_SEND [0] to (ff02::1) test
UDP_SEND [0] to (ff02::1) test
UDP_SEND [0] to (ff02::1) test
UDP_SEND [0] to (ff02::1) test