Skip to content
Open
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
21 changes: 16 additions & 5 deletions E131.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,30 @@ void E131::initUnicast() {
}
}

/*
* Converts a DMX 'universe' to the corresponding e131 multicast address.
*
* e131 mandates a fixed multicase base-IP of 239.255.0.0, to which
* the (two-byte, 1-63.999) universe value is added.
* (effectively defining the last two positions of the IP)
*/
IPAddress E131::multicastIPFor(uint16_t universe) {
return IPAddress(239, 255,
((universe >> 8) & 0xff),
((universe >> 0) & 0xff)
);
}

void E131::initMulticast(uint16_t universe, uint8_t n) {
delay(100);
IPAddress address = IPAddress(239, 255, ((universe >> 8) & 0xff),
((universe >> 0) & 0xff));
IPAddress address = multicastIPFor(universe);
#ifdef INT_ESP8266
ip_addr_t ifaddr;
ip_addr_t multicast_addr;

ifaddr.addr = static_cast<uint32_t>(WiFi.localIP());
for (uint8_t i = 1; i < n; i++) {
multicast_addr.addr = static_cast<uint32_t>(IPAddress(239, 255,
(((universe + i) >> 8) & 0xff), (((universe + i) >> 0)
& 0xff)));
multicast_addr.addr = static_cast<uint32_t>(MulticastIPFor(universe + i));
igmp_joingroup(&ifaddr, &multicast_addr);
}

Expand Down
3 changes: 3 additions & 0 deletions E131.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class E131 {

E131();

/* Maps a DMX universe to the correct multicast IP */
static IPAddress multicastIPFor(uint16_t universe);

/* Generic UDP listener, no physical or IP configuration */
void begin(e131_listen_t type, uint16_t universe = 1, uint8_t n = 1);

Expand Down