how can I recieve udp multicast packets in ESP8266? I have this piece of code:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "my_wifi_ssid";
const char* password = "my_wifi_password";
WiFiUDP Udp;
unsigned int multicastPort = 5683; // local port to listen on
IPAddress multicastIP(224,0,1,187);
void setup(){
Serial.begin(115200);
Serial.println();
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("connected");
Udp.beginMulticast(WiFi.localIP(), multicastIP, multicastPort);
Serial.printf("Now listening at IP %s and %s, UDP port %d\n", WiFi.localIP().toString().c_str(), multicastIP.toString().c_str(), multicastPort);
}
void loop(){
int packetSize = Udp.parsePacket();
if (packetSize){
Serial.println("RECEIVED!");
}
}
I wrote it according to this documentation and this addition to that about adding multicast.
It just set server listening on port 5683.
It prints something like:
Now listening at IP 192.168.1.6 and 224.0.1.187, UDP port 5683
But if I send UDP packet to 224.0.1.187:5683 (eg. via Packet sender app), it doesn't print message "RECEIVED!" (which should, look in loop function). Why ESP8266 is not receiving anything? Strange is, that when I send packet to 192.168.1.6:5683 (its local IP), it prints that message ("RECEIVED!").
Why it works only for local message but not for multicast??
Thanks for every help! :)
PS: this advice didn't help me...
1 Answer 1
I think you need to call
Udp.begin(multicastPort);
right before calling
Udp.beginMulticast(WiFi.localIP(), multicastIP, multicastPort);
At least that's what did the trick for me.