Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By gerardwr
#14358 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
You do not have the required permissions to view the files attached to this post.
Last edited by gerardwr on Thu Apr 16, 2015 12:51 pm, edited 1 time in total.
User avatar
By gerardwr
#14444 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 !
You do not have the required permissions to view the files attached to this post.
User avatar
By Gslomin
#14921 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.