2#if defined(USE_NETWORK) && !defined(USE_ZEPHYR)
9static const char *
const TAG =
"wake_on_lan.button";
10static const uint8_t PREFIX[6] = {255, 255, 255, 255, 255, 255};
22 LOG_BUTTON(
"",
"Wake-on-LAN Button",
this);
23 ESP_LOGCONFIG(TAG,
" Target MAC address: %02X:%02X:%02X:%02X:%02X:%02X", this->
macaddr_[0], this->
macaddr_[1],
29 ESP_LOGW(TAG,
"Network not connected");
32 ESP_LOGI(TAG,
"Sending Wake-on-LAN Packet");
33#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
38 ESP_LOGW(TAG,
"Invalid broadcast address");
42 memcpy(
buffer, PREFIX,
sizeof(PREFIX));
43 for (
size_t i = 0; i != 16; i++) {
48 ESP_LOGW(TAG,
"sendto() error %d", errno);
51 IPAddress broadcast = IPAddress(255, 255, 255, 255);
54 if (this->
udp_client_.beginPacketMulticast(broadcast, 9, ip, 128) != 0) {
56 for (
size_t i = 0; i < 16; i++) {
61 ESP_LOGW(TAG,
"WOL broadcast failed");
66 ESP_LOGW(TAG,
"No ip4 addresses to broadcast to");
71#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
79 auto err = this->
broadcast_socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable,
sizeof(
int));
84 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, ...)
network::IPAddresses get_ip_addresses()
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().
std::unique_ptr< Socket > socket(int domain, int type, int protocol)
Create a socket of the given domain, type and protocol.