Skip to content

Commit d15767d

Browse files
committed
- Same UDP API of ESP32 core
1 parent f2da54d commit d15767d

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

cores/esp8266/Udp.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,18 @@ 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+
IPAddress local = WiFi.localIP();
90+
return _beginMulticast(local, multicast, port);
91+
}
92+
8793
uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port)
94+
{
95+
return _beginMulticast(interfaceAddr, multicast, port);
96+
}
97+
98+
uint8_t WiFiUDP::_beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port)
8899
{
89100
if (_ctx) {
90101
_ctx->unref();

libraries/ESP8266WiFi/src/WiFiUdp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class UdpContext;
3232
class WiFiUDP : public UDP, public SList<WiFiUDP> {
3333
private:
3434
UdpContext* _ctx;
35+
uint8_t _beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port);
3536

3637
public:
3738
WiFiUDP(); // Constructor
@@ -47,7 +48,8 @@ class WiFiUDP : public UDP, public SList<WiFiUDP> {
4748
// Finish with the UDP connection
4849
void stop() override;
4950
// join a multicast group and listen on the given port
50-
uint8_t beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port);
51+
virtual uint8_t beginMulticast(IPAddress interfaceAddr, uint16_t port);
52+
uint8_t beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port) __attribute__((deprecated));
5153

5254
// Sending UDP packets
5355

0 commit comments

Comments
 (0)