7 #ifdef USE_BINARY_SENSOR 10 #if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) 34 #ifdef USE_BINARY_SENSOR 44 void setup()
override;
46 void update()
override;
47 void dump_config()
override;
52 this->sensors_.push_back(st);
55 this->add_provider(hostname);
56 this->remote_sensors_[hostname][remote_id] =
sensor;
59 #ifdef USE_BINARY_SENSOR 62 this->binary_sensors_.push_back(st);
66 this->add_provider(hostname);
67 this->remote_binary_sensors_[hostname][remote_id] =
sensor;
70 void add_address(
const char *addr) { this->addresses_.emplace_back(addr); }
71 void set_port(uint16_t port) { this->port_ = port; }
75 if (this->providers_.count(hostname) == 0) {
80 provider.
name = hostname;
81 this->providers_[hostname] = provider;
83 this->remote_sensors_[hostname] = std::map<std::string, sensor::Sensor *>();
85 #ifdef USE_BINARY_SENSOR 86 this->remote_binary_sensors_[hostname] = std::map<std::string, binary_sensor::BinarySensor *>();
96 this->providers_[
name].encryption_key = std::move(key);
100 void send_data_(
bool all);
101 void process_(uint8_t *buf,
size_t len);
103 void add_data_(uint8_t key,
const char *
id,
float data);
104 void add_data_(uint8_t key,
const char *
id, uint32_t data);
105 void increment_code_();
106 void add_binary_data_(uint8_t key,
const char *
id,
bool data);
110 uint16_t port_{18511};
111 uint32_t ping_key_{};
112 uint32_t rolling_code_[2]{};
113 bool rolling_code_enable_{};
114 bool ping_pong_enable_{};
115 uint32_t ping_pong_recyle_time_{};
116 uint32_t last_key_time_{};
117 bool resend_ping_key_{};
121 bool should_listen_{};
124 #if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) 125 std::unique_ptr<socket::Socket> broadcast_socket_ =
nullptr;
126 std::unique_ptr<socket::Socket> listen_socket_ =
nullptr;
127 std::vector<struct sockaddr> sockaddrs_{};
129 std::vector<IPAddress> ipaddrs_{};
130 WiFiUDP udp_client_{};
132 std::vector<uint8_t> encryption_key_{};
133 std::vector<std::string> addresses_{};
136 std::vector<Sensor> sensors_{};
137 std::map<std::string, std::map<std::string, sensor::Sensor *>> remote_sensors_{};
139 #ifdef USE_BINARY_SENSOR 140 std::vector<BinarySensor> binary_sensors_{};
141 std::map<std::string, std::map<std::string, binary_sensor::BinarySensor *>> remote_binary_sensors_{};
144 std::map<std::string, Provider> providers_{};
145 std::vector<uint8_t> ping_header_{};
146 std::vector<uint8_t> header_{};
147 std::vector<uint8_t> data_{};
148 std::map<const char *, uint32_t> ping_keys_{};
149 void add_key_(
const char *
name, uint32_t key);
150 void send_ping_pong_request_();
151 void send_packet_(
void *data,
size_t len);
152 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)