Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add virtual beginMulticast(...) stub to UDP class #8969

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/esp8266/Udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class UDP: public Stream {
public:
virtual ~UDP() {};
virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
virtual void stop() =0; // Finish with the UDP socket

// Sending UDP packets
Expand Down
4 changes: 2 additions & 2 deletions doc/esp8266wifi/udp-class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Multicast UDP

.. code:: cpp

uint8_t beginMulticast (IPAddress interfaceAddr, IPAddress multicast, uint16_t port)
uint8_t beginMulticast (IPAddress multicast, uint16_t port)
virtual int beginPacketMulticast (IPAddress multicastAddress, uint16_t port, IPAddress interfaceAddress, int ttl=1)
IPAddress destinationIP ()
uint16_t localPort ()

The ``WiFiUDP`` class supports sending and receiving multicast packets on STA interface. When sending a multicast packet, replace ``udp.beginPacket(addr, port)`` with ``udp.beginPacketMulticast(addr, port, WiFi.localIP())``. When listening to multicast packets, replace ``udp.begin(port)`` with ``udp.beginMulticast(WiFi.localIP(), multicast_ip_addr, port)``. You can use ``udp.destinationIP()`` to tell whether the packet received was sent to the multicast or unicast address.
The ``WiFiUDP`` class supports sending and receiving multicast packets on STA interface. When sending a multicast packet, replace ``udp.beginPacket(addr, port)`` with ``udp.beginPacketMulticast(addr, port, WiFi.localIP())``. When listening to multicast packets, replace ``udp.begin(port)`` with ``udp.beginMulticast(multicast_ip_addr, port)``. You can use ``udp.destinationIP()`` to tell whether the packet received was sent to the multicast or unicast address.

For code samples please refer to separate section with `examples <udp-examples.rst>`__ dedicated specifically to the UDP Class.
5 changes: 5 additions & 0 deletions libraries/ESP8266WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ uint8_t WiFiUDP::begin(uint16_t port)
return (_ctx->listen(IPAddress(), port)) ? 1 : 0;
}

uint8_t WiFiUDP::beginMulticast(IPAddress multicast, uint16_t port)
{
return beginMulticast(IP_ADDR_ANY, multicast, port);
}

uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port)
{
if (_ctx) {
Expand Down
2 changes: 2 additions & 0 deletions libraries/ESP8266WiFi/src/WiFiUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class WiFiUDP : public UDP, public SList<WiFiUDP> {
// Finish with the UDP connection
void stop() override;
// join a multicast group and listen on the given port
virtual uint8_t beginMulticast(IPAddress interfaceAddr, uint16_t port);
// join a multicast group and listen on the given port, using a specific interface address
uint8_t beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port);

// Sending UDP packets
Expand Down