-->
Page 1 of 6

UDP Multicast Server example (now working OK)

PostPosted: Mon Apr 13, 2015 8:03 am
by gerardwr
Now that the bug in the UDP library that blocked bidirectional UDP communication (ref.viewtopic.php?f=29&t=2451) is solved I created a basic example sketch for bidirectional Multicast UDP communication.

Multicast UDP will enable communication with multiple ESP's on the network using 1 single Multicast IP address. This would facilitate discovering ESP's on your network, or other solutions where multiple ESP's should react on a packet from single client.

The sketch seems to work OK with the application "Packet Sender" on Mac OSX as counterpart (available for OSX, Windows, Linux, etc. at packetsender.com):
- The sketch reacts on the selected Multicast IP address and port. Packets sent to the ESP are recognized.
- The sketch sends a confirmation UDP packet back to the sender, and this packet is received in Packetsender.

I did not try loading the same sketch on multiple ESP's, yet.

IGGR informed me that applications like mnc en multicast should also work. Have not tried these.

NOTE : I started with using netcat/nc on Mac OSX but apparently this does not support Multicast. The Multicast packets were received by the ESP OK, but the confirmation message sent back did not arrive.

Below you will find:
- Screen dump, left = Serial Monitor ESP, right is Packetsender on Mac as UDP client
- the sketch

Schermafbeelding 2015-04-13 om 18.40.27.png


UdpMulticast2.ino.zip

Re: UDP Multicast ClientServer example (now working OK)

PostPosted: Tue Apr 14, 2015 4:39 am
by gerardwr
Of course you can extend the confirmation message. As an example, using these lines the ESP responds with the Chipid and the IP.
Code: Select all    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write("ESP-");
    Udp.print(system_get_chip_id(),HEX);
    Udp.print(":");
    Udp.print(WiFi.localIP());
    Udp.endPacket();


Schermafbeelding 2015-04-14 om 11.32.24.png


If you have an interesting use of this Multicast feature, let us know !

Re: UDP Multicast ClientServer example (now working OK)

PostPosted: Thu Apr 16, 2015 6:22 am
by gerardwr
Just to confirm that the following Python code can be either an UDP Multicast Client or Server on my Mac OSX 10.10.2:
http://svn.python.org/projects/stackless/trunk/Demo/sockets/mcast.py

Re: UDP Multicast Server example (now working OK)

PostPosted: Sat Apr 18, 2015 12:50 pm
by Gslomin
I've tried your sketch as well as several others related to UDP multicast on the 8266. Was there anything special that you had to do? I can't seem to get it to send or receive a multicast. Using a small C program I wrote as a client/server it works fine until the 8266 is introduced.