I can confirm that the ESPHome Wake-on-LAN Button component in fact indeed is working fine: the only problem seems to be a bug in the logging output, generating incorrect error logs.
To test it I first added the current Wake-on-LAN Button component to an ESP8266 (Wemos D1 Mini v4), and although there always was an error logged in the ESPHome output the WoL function did indeed work fine.
So then I had a brief look at the Wake-on-LAN component code on Github (specifically the wake_on_lan.cpp code), and, although I am not completely sure about the complete functioning of this code, it looks like it is a bug in the logging function.
This is a snippet of the current code where the magic packet is sent and where the error log is generated:
if (begin_status) {
this->udp_client_.write(PREFIX, 6);
for (size_t i = 0; i < 16; i++) {
this->udp_client_.write(macaddr_, 6);
}
end_status = this->udp_client_.endPacket();
}
if (!begin_status || end_status) {
ESP_LOGE(TAG, "Sending Wake-on-LAN Packet Failed!");
}
The line if (!begin_status || end_status)
means:
IF ( NOT begin_status OR end_status ) THEN ERROR
But I think this should be:
IF ( NOT begin_status OR NOT end_status ) THEN ERROR
It should only generate an error log when either the begin_status
or the end_status
is false (not true), and like it is now it will generate an error log when either the begin_status
is false or the end_status
is true?
So I think the code probably should be:
if (begin_status) {
this->udp_client_.write(PREFIX, 6);
for (size_t i = 0; i < 16; i++) {
this->udp_client_.write(macaddr_, 6);
}
end_status = this->udp_client_.endPacket();
}
if (!begin_status || !end_status) {
ESP_LOGE(TAG, "Sending Wake-on-LAN Packet Failed!");
}
For clarity: the difference here is the added exclamation mark (meaning NOT) before end_status
.
I did test this in a local component, and indeed the WoL function is still working fine like that but the error is not generated anymore.
Can someone with a better understanding of this code please confirm this to be correct?