Great @mdma should have guessed it is you. I found the following function:
wiced_result_t wiced_multicast_join(
wiced_interface_t interface, const wiced_ip_address_t* address);
(There is also the corresponding leave function, which will ignore for the discussion).
This will subscribe to a multicast address on the IGMP level. It seems that all UDP sockets will then receive multicast packets sent to their respective ports.
What I did is to add a
int socket_join_multicast(const sockaddr_t *addr);
function to socket_hal. This is then used in
int udp_join_multicast(IPAddress ip);
in spark_wiring_udp. So far so trivial. I am unsure if that is the right location (it is, I think) and if it should be a static function of the UDP class or a free function.
Here is a simple test program which you can put on as many Photons as you like and they will all start flashing the blue LED. The more Photons, the faster they will flash :-).
#include "application.h"
static UDP g_udp;
static int g_last = 0;
void setup()
{
pinMode(7, OUTPUT);
Serial.begin(115200);
g_udp.begin(10000);
IPAddress address(224, 1, 2, 3);
int result = udp_join_multicast(address);
Serial.println(result);
}
void loop()
{
if (g_udp.parsePacket() > 0)
{
// Read first char of data received
unsigned char v = g_udp.read();
Serial.print("Received packet ");
Serial.println(v);
g_udp.flush();
digitalWrite(7, true);
delay(30);
digitalWrite(7, false);
}
int now = millis();
if (now - g_last < 1000)
return;
g_last = now;
Serial.println("Sending packet");
unsigned char v = 42;
IPAddress ipAddress(224, 1, 2, 3);
g_udp.beginPacket(ipAddress, 10000);
g_udp.write(&v, 1);
g_udp.endPacket();
}
We should of course add the leave function as well. What do you think?