Skip to content

Commit

Permalink
Handle new IPAddress structure (elupus#41)
Browse files Browse the repository at this point in the history
Correct handling of new Ip_address structure with changes in
esphome/esphome#5252

Since IPAddress is no longer sortable, we keep it as a vector instead.
It's somewhat slower, but it will be a short list.

Fixes elupus#40
  • Loading branch information
elupus authored Oct 18, 2023
1 parent 3f0ebbd commit 1fe413f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions components/nibegw/NibeGwComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ void NibeGwComponent::callback_msg_received(const byte* const data, int len)
ESP_LOGD(TAG, "UDP Packet with %d bytes to send", len);
for (auto target = udp_targets_.begin(); target != udp_targets_.end(); target++)
{
if (!udp_read_.writeTo(data, len, (uint32_t)std::get<0>(*target), std::get<1>(*target))) {
ip_addr_t address = (ip_addr_t)std::get<0>(*target);
if (!udp_read_.writeTo(data, len, &address, std::get<1>(*target))) {
ESP_LOGW(TAG, "UDP Packet send failed to %s:%d",
std::get<0>(*target).str().c_str(),
std::get<1>(*target));
Expand All @@ -56,8 +57,8 @@ void NibeGwComponent::token_request_cache(AsyncUDPPacket& udp, byte address, byt
return;
}

network::IPAddress ip = (uint32_t)udp.remoteIP();
if (udp_source_ip_.size() && udp_source_ip_.count(ip) == 0) {
network::IPAddress ip = udp.remoteIP();
if (udp_source_ip_.size() && std::count(udp_source_ip_.begin(), udp_source_ip_.end(), ip) == 0) {
ESP_LOGW(TAG, "UDP Packet wrong ip ignored %s", ip.str().c_str());
return;
}
Expand Down
4 changes: 2 additions & 2 deletions components/nibegw/NibeGwComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class NibeGwComponent: public esphome::Component, public esphome::uart::UARTDevi
const int requests_queue_max = 3;
int udp_read_port_ = 9999;
int udp_write_port_ = 10000;
std::set<network::IPAddress> udp_source_ip_;
std::vector<network::IPAddress> udp_source_ip_;
bool is_connected_ = false;

std::vector<target_type> udp_targets_;
Expand Down Expand Up @@ -67,7 +67,7 @@ class NibeGwComponent: public esphome::Component, public esphome::uart::UARTDevi
}

void add_source_ip(const network::IPAddress& ip){
udp_source_ip_.insert(ip);
udp_source_ip_.push_back(ip);
};

void set_const_request(int address, int token, request_data_type request)
Expand Down

0 comments on commit 1fe413f

Please sign in to comment.