This is my first Multicast project and I cannot find a solution -
My environment is an Arduino Uno and Ethernet Shield 2 (WIZ 5500), using the Ethernet3 library.
I need to listen for the presence of UDP Multicast packets being broadcast on IP address 224.0.2.60 and ports 50001 through 50012. I need to differentiate between streams present across the port range, to take action on each unique port when active. For example: Picture a row of 12 LEDs, where each LED represents a port (LED 1 for port 50001, LED 2 for port 50002, etc.). I need to light each of the LEDs while Multicast packets are present on the associated port.
I have successfully detected Multicast traffic on a single port - but I am not sure how to go about listening on multiple ports at once.
Below is the sketch that works great for detecting traffic on a single port -
Of course any help is greatly appreciated!
#include <SPI.h>
#include <Ethernet3.h>
#include <EthernetUdp3.h>
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x6A, 0x51 }; // MAC address of this Ethernet Shield.
EthernetUDP Udp;
IPAddress ip(192, 168, 100, 19); // static IP address that Arduino uses to connect to LAN.
IPAddress multicastip(224, 0, 2, 60); // the Multicast IP to listen on.
unsigned int multicastport = 50002; // the Multicast Port to listen on.
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet.
void setup() {
Ethernet.begin(mac, ip);
Udp.beginMulticast(multicastip, multicastport);
Serial.begin(9600);
Serial.print ("Starting to Listen for UDP Multicast Traffic on IP: ");
Serial.print (multicastip);
Serial.print (" Port: ");
Serial.print (multicastport);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
}
Udp.endPacket();
delay(10);
}