I would like to know if the library EthernetENC will ever be able to receive UDP broadcasted packages sent to 255.255.255.255?
I ask this because all other libraries can, like the EtherCard and the WiFi one, however I’m trying to use the ENC28J60 together with the ESP32, and everything works until the moment I send broadcasted UDP an the ESP32 fails to receive it! It’s so sad…
Can this be easily solved?
I had to do an entire copy of the original library and change these lines of code in the file Enc28J60Network.cpp:
from this:
writeReg(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN);
writeRegPair(EPMM0, 0x303f);
writeRegPair(EPMCSL, 0xf7f9);
to this:
writeReg(ERXFCON, ERXFCON_UCEN | ERXFCON_CRCEN | ERXFCON_BCEN);
// Pattern matching disabled – not needed for broadcast
// writeRegPair(EPMM0, 0x303f);
// writeRegPair(EPMCSL, 0xf7f9);
It turns out it is needed to use ERXFCON_BCEN instead of ERXFCON_PMEN, explained here:
PMEN: Pattern Match Filter Enable bit
BCEN: Broadcast Filter Enable bit
From the ENC28J60 Data Sheet
Just needed to make sure I used the copy instead the original library like this:
#include "../Changed_EthernetENC/src/EthernetENC.h"
// #include <EthernetUdp.h> // DON'T INCLUDE THIS ONE BECAUSE ARDUINO COMPILER CAN PICH THE WRONG ONE
#include "../Changed_EthernetENC/src/EthernetUdp.h" // Forces the correct usage of EthernetUdp.h
After doing these changes and use the copy it started to accept UDP packages sent to the broadcast address 255.255.255.255! I just don’t understand why the library doesn't allow this by default, or at least with some type of configuration…