2#if defined(USE_NETWORK) && !defined(USE_ZEPHYR)
9static const uint8_t PREFIX[6] = {255, 255, 255, 255, 255, 255};
21 LOG_BUTTON(
"",
"Wake-on-LAN Button",
this);
22 ESP_LOGCONFIG(TAG,
" Target MAC address: %02X:%02X:%02X:%02X:%02X:%02X", this->
macaddr_[0], this->
macaddr_[1],
28 ESP_LOGW(TAG,
"Socket not available");
32 ESP_LOGW(TAG,
"Network not connected");
35 ESP_LOGI(TAG,
"Sending Wake-on-LAN Packet");
40 ESP_LOGW(TAG,
"Invalid broadcast address");
44 memcpy(
buffer, PREFIX,
sizeof(PREFIX));
45 for (
size_t i = 0; i != 16; i++) {
50 ESP_LOGW(TAG,
"sendto() error %d", errno);
62 auto err = this->
broadcast_socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable,
sizeof(
int));
67 err = this->
broadcast_socket_->setsockopt(SOL_SOCKET, SO_BROADCAST, &enable,
sizeof(
int));
void mark_failed()
Mark this component as failed.
void status_set_warning()
ESPHOME_ALWAYS_INLINE bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
std::unique_ptr< UDPSendSocket > socket_udp_send(int domain, int protocol)
Create a send-only UDP socket (socket_udp_send), a UDP socket with receive support (socket_udp),...
socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const char *ip_address, uint16_t port)
Set a sockaddr to the specified address and port for the IP version used by socket_ip().
ESPHOME_LOG_TAG(TAG, "wake_on_lan.button")