7 #ifdef USE_BINARY_SENSOR 10 #if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) 13 #ifdef USE_SOCKET_IMPL_LWIP_TCP 35 #ifdef USE_BINARY_SENSOR 45 void setup()
override;
47 void update()
override;
48 void dump_config()
override;
53 this->sensors_.push_back(st);
56 this->add_provider(hostname);
57 this->remote_sensors_[hostname][remote_id] =
sensor;
60 #ifdef USE_BINARY_SENSOR 63 this->binary_sensors_.push_back(st);
67 this->add_provider(hostname);
68 this->remote_binary_sensors_[hostname][remote_id] =
sensor;
71 void add_address(
const char *addr) { this->addresses_.emplace_back(addr); }
72 void set_port(uint16_t port) { this->port_ = port; }
76 if (this->providers_.count(hostname) == 0) {
81 provider.
name = hostname;
82 this->providers_[hostname] = provider;
84 this->remote_sensors_[hostname] = std::map<std::string, sensor::Sensor *>();
86 #ifdef USE_BINARY_SENSOR 87 this->remote_binary_sensors_[hostname] = std::map<std::string, binary_sensor::BinarySensor *>();
97 this->providers_[
name].encryption_key = std::move(key);
101 void send_data_(
bool all);
102 void process_(uint8_t *buf,
size_t len);
104 void add_data_(uint8_t key,
const char *
id,
float data);
105 void add_data_(uint8_t key,
const char *
id, uint32_t data);
106 void increment_code_();
107 void add_binary_data_(uint8_t key,
const char *
id,
bool data);
111 uint16_t port_{18511};
112 uint32_t ping_key_{};
113 uint32_t rolling_code_[2]{};
114 bool rolling_code_enable_{};
115 bool ping_pong_enable_{};
116 uint32_t ping_pong_recyle_time_{};
117 uint32_t last_key_time_{};
118 bool resend_ping_key_{};
122 bool should_listen_{};
125 #if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) 126 std::unique_ptr<socket::Socket> broadcast_socket_ =
nullptr;
127 std::unique_ptr<socket::Socket> listen_socket_ =
nullptr;
128 std::vector<struct sockaddr> sockaddrs_{};
130 #ifdef USE_SOCKET_IMPL_LWIP_TCP 131 std::vector<IPAddress> ipaddrs_{};
132 WiFiUDP udp_client_{};
134 std::vector<uint8_t> encryption_key_{};
135 std::vector<std::string> addresses_{};
138 std::vector<Sensor> sensors_{};
139 std::map<std::string, std::map<std::string, sensor::Sensor *>> remote_sensors_{};
141 #ifdef USE_BINARY_SENSOR 142 std::vector<BinarySensor> binary_sensors_{};
143 std::map<std::string, std::map<std::string, binary_sensor::BinarySensor *>> remote_binary_sensors_{};
146 std::map<std::string, Provider> providers_{};
147 std::vector<uint8_t> ping_header_{};
148 std::vector<uint8_t> header_{};
149 std::vector<uint8_t> data_{};
150 std::map<const char *, uint32_t> ping_keys_{};
151 void add_key_(
const char *
name, uint32_t key);
152 void send_ping_pong_request_();
153 void send_packet_(
void *data,
size_t len);
154 void process_ping_request_(
const char *name, uint8_t *ptr,
size_t len);
void add_remote_sensor(const char *hostname, const char *remote_id, sensor::Sensor *sensor)
void add_sensor(const char *id, sensor::Sensor *sensor)
void set_rolling_code_enable(bool enable)
std::vector< uint8_t > encryption_key
binary_sensor::BinarySensor * sensor
void add_provider(const char *hostname)
const float AFTER_WIFI
For components that should be initialized after WiFi is connected.
void set_encryption_key(std::vector< uint8_t > key)
T id(T value)
Helper function to make id(var) known from lambdas work in custom components.
This class simplifies creating components that periodically check a state.
void add_remote_binary_sensor(const char *hostname, const char *remote_id, binary_sensor::BinarySensor *sensor)
void add_binary_sensor(const char *id, binary_sensor::BinarySensor *sensor)
void set_provider_encryption(const char *name, std::vector< uint8_t > key)
void add_address(const char *addr)
void set_ping_pong_enable(bool enable)
float get_setup_priority() const override
ESPPreferenceObject pref_
Implementation of SPI Controller mode.
Base class for all binary_sensor-type classes.
void set_ping_pong_recycle_time(uint32_t recycle_time)
Base-class for all sensors.
esphome::sensor::Sensor * sensor
void set_port(uint16_t port)