> 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 <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.