Skip to content

Commit 203af56

Browse files
committed
Enable multicast groups
1 parent 9f3c329 commit 203af56

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

libraries/WiFi/src/WiFiUdp.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ uint8_t arduino::WiFiUDP::begin(uint16_t port) {
3939
return 1;
4040
}
4141

42+
uint8_t arduino::WiFiUDP::beginMulticast(IPAddress ip, uint16_t port) {
43+
// success = 1, fail = 0
44+
if(begin(port) != 1){
45+
return 0;
46+
}
47+
48+
nsapi_addr_t multicastGroup = {NSAPI_IPv4, {ip[0], ip[1], ip[2], ip[3]}};
49+
50+
if (_socket.join_multicast_group(SocketAddress(multicastGroup)) != NSAPI_ERROR_OK) {
51+
printf("Error joining the multicast group\n");
52+
return 0;
53+
}
54+
55+
return 1;
56+
}
57+
4258
void arduino::WiFiUDP::stop() {
4359
_socket.close();
4460
}

libraries/WiFi/src/WiFiUdp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class WiFiUDP : public UDP {
4747
WiFiUDP(); // Constructor
4848
~WiFiUDP();
4949
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
50-
// virtual uint8_t beginMulticast(IPAddress, uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use
50+
virtual uint8_t beginMulticast(IPAddress, uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use
5151
virtual void stop(); // Finish with the UDP socket
5252

5353
// Sending UDP packets

0 commit comments

Comments
 (0)