-->
Page 1 of 2

ESP8266 UDP multicast doesn't receive packets

PostPosted: Thu Jul 13, 2017 2:22 pm
by elheck
I am currently working on an ESP8266 with the Arduino IDE. I try to implement an ESP8266 in STA mode as multicast receiver. I was writing my code with the help of this documentation [ https://arduino-esp8266.readthedocs.io/ ... class.html]. Especially the following part:

> The WiFiUDP class supports sending and receiving multicast packets on STA interface. When sending a multicast packet, replace udp.beginPacket(addr, port) with udp.beginPacketMulticast(addr, port, WiFi.localIP()). When listening to multicast packets, replace udp.begin(port) with udp.beginMulticast(WiFi.localIP(), multicast_ip_addr, port). You can use udp.destinationIP() to tell whether the packet received was sent to the multicast or unicast address.


Sending to the multicast group with `udp.beginPacketMulticast(addr, port, WiFi.localIP())` and `udp.write(message, messageLength)`works flawlessly.

The receiving part of my code is as follows:



Code: Select all   #include <ESP8266WiFi.h>
    #include <WiFiUdp.h>
   
    #define BUFFER_LENGTH 256
   
    const char* ssid = "xxxxxx";
    const char* password = "xxxxxx";
   
    WiFiUDP Udp;
    IPAddress multicastAddress(226,1,1,1);
    unsigned int multicastPort = 4096;
   
    char incomingPacket[BUFFER_LENGTH];
   
    void setup(){
       WiFi.mode(WIFI_STA); //station
       WiFi.setOutputPower(0);
       while (WiFi.status() != WL_CONNECTED)
       {
           WiFi.begin(ssid, password);
           delay(500);
        }
        Udp.beginMulticast(WiFi.localIP(), multicastAddress, multicastPort);
    }
   
    void loop(){
       int packetLength = Udp.parsePacket();
       if(packetLength){
          int len = Udp.read(incomingPacket, BUFFER_LENGTH);
            if (len > 0){
              incomingPacket[len] = 0;
                Serial.printf("%s\n", incomingPacket);
            }
       }
    }


When sending a packet with a simple [ http://ntrg.cs.tcd.ie/undergrad/4ba2/mu ... ample.html] multicast sender (with matching IP and port), my multicast receiver on my linux laptop receives the packet, but the ESP8266 doesn't.

Maybe some of you have experienced a similar behavior and are able to give me some hints, where I might be wrong.

Re: ESP8266 UDP multicast doesn't receive packets

PostPosted: Thu Jul 20, 2017 7:13 pm
by hazyj
Any luck solving your issue? I am currently having exact same problem: esp8266 client is not receiving the multicast packages sent from my esp8266 server via udp.beginPacketMulticast(addr, port, WiFi.localIP()).

My code is simply a way for all clients to find the IP address of the server and to do so dynamically.

Also, I don't understand this statement from documentation:

"You can use Udp.destinationIP() to tell whether the packet received was sent to the multicast or unicast address." Is this a typo? Should it be "sent from the multicast or unicast address" instead?

Thanks,
John

Re: ESP8266 UDP multicast doesn't receive packets

PostPosted: Sat Mar 03, 2018 8:13 am
by mrlightsman
Did you ever get an answer to this? I am having the exact same problem and can’t figure it out. Thanks.

Re: ESP8266 UDP multicast doesn't receive packets

PostPosted: Sat Jan 25, 2020 7:59 pm
by gibo77
I am also having the same problem on UDP multicast receiving. I could not receive packet!
My program is basic and has no other content. Just bare bones.

I tried the solution on the link below, but still did not work.

Code: Select allhttps://arduino.stackexchange.com/questions/39957/esp8266-udp-multicast-doesnt-receive-packets/58268


Can somebody help us please. As per documentation of Arduino ESP8266 that multicast works.