Skip to content

Commit 1a4663f

Browse files
authored
Add virtual beginMulticast(...) stub to UDP class (#8969)
* - Same UDP API of ESP32 core * - PR review
1 parent f2da54d commit 1a4663f

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

cores/esp8266/Udp.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class UDP: public Stream {
4343
public:
4444
virtual ~UDP() {};
4545
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
46+
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
4647
virtual void stop() =0; // Finish with the UDP socket
4748

4849
// Sending UDP packets

doc/esp8266wifi/udp-class.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ Multicast UDP
2626

2727
.. code:: cpp
2828
29-
uint8_t beginMulticast (IPAddress interfaceAddr, IPAddress multicast, uint16_t port)
29+
uint8_t beginMulticast (IPAddress multicast, uint16_t port)
3030
virtual int beginPacketMulticast (IPAddress multicastAddress, uint16_t port, IPAddress interfaceAddress, int ttl=1)
3131
IPAddress destinationIP ()
3232
uint16_t localPort ()
3333
34-
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.
34+
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.
3535

3636
For code samples please refer to separate section with `examples <udp-examples.rst>`__ dedicated specifically to the UDP Class.

libraries/ESP8266WiFi/src/WiFiUdp.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ uint8_t WiFiUDP::begin(uint16_t port)
8484
return (_ctx->listen(IPAddress(), port)) ? 1 : 0;
8585
}
8686

87+
uint8_t WiFiUDP::beginMulticast(IPAddress multicast, uint16_t port)
88+
{
89+
return beginMulticast(IP_ADDR_ANY, multicast, port);
90+
}
91+
8792
uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port)
8893
{
8994
if (_ctx) {

libraries/ESP8266WiFi/src/WiFiUdp.h

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class WiFiUDP : public UDP, public SList<WiFiUDP> {
4747
// Finish with the UDP connection
4848
void stop() override;
4949
// join a multicast group and listen on the given port
50+
virtual uint8_t beginMulticast(IPAddress interfaceAddr, uint16_t port);
51+
// join a multicast group and listen on the given port, using a specific interface address
5052
uint8_t beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port);
5153

5254
// Sending UDP packets

0 commit comments

Comments
 (0)