ESP8266 UDP multicast doesn't receive packets 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. 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:

#include &lt;ESP8266WiFi.h&gt;
#include &lt;WiFiUdp.h&gt;

#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 &gt; 0){
            incomingPacket[len] = 0;
            Serial.printf("%s\n", incomingPacket);
        }
    }
}


When sending a packet with a simple 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.

EDIT:
Since the time I asked this question I completely ruled out an error of the sender on the linux machine by using a verified, 100% working sender. The ESP8266 still doesn't receive any multicast datagramms.
I recently had the same problem.

The unequivocal answer is that there is a power optimization (internal by Espressif) to save power, I guess, and it really creates havoc in the UDP Multicast receiving. Why? I have no idea. Same problem with the ESP32 and ESP8266.

Solution:



#include "user_interface.h"


and after:

WiFi.mode(WIFI_STA);
// the below instructions and now u will receive.
wifi_set_sleep_type(NONE_SLEEP_T); //LIGHT_SLEEP_T and MODE_SLEEP_T