From e92ecef46fc8dc492b79c5874b703d1d75dc3526 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Fri, 11 Apr 2025 08:35:58 +0200 Subject: [PATCH] moved from broadcasting to unicasting --- EspIdf/EspIdfParticipant.cpp | 32 +++++++++++++------------------- Participants/ParticipantUDP.cpp | 1 + 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/EspIdf/EspIdfParticipant.cpp b/EspIdf/EspIdfParticipant.cpp index 099ae5c..f479a18 100644 --- a/EspIdf/EspIdfParticipant.cpp +++ b/EspIdf/EspIdfParticipant.cpp @@ -60,22 +60,22 @@ std::cout << "Set up UDP\n"; void ParticipantUDP::GetBroadcastAddress() { // SOMEHOW, THIS FUNCTION RESULTS IN MEMORY CORRUPION... - // esp_netif_ip_info_t ip_info; - // esp_netif_t* esp_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"); + esp_netif_ip_info_t ip_info; + esp_netif_t* esp_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"); - // // Get IP information (IP address, netmask, gateway) - // if (esp_netif_get_ip_info(esp_netif, &ip_info) != ESP_OK) { - // std::cout << "Failed to get IP info\n"; - // return; - // } + // Get IP information (IP address, netmask, gateway) + if (esp_netif_get_ip_info(esp_netif, &ip_info) != ESP_OK) { + std::cout << "Failed to get IP info\n"; + return; + } - // ip_addr_t broadcast_addr = {}; - // broadcast_addr.u_addr.ip4.addr = - // (ip_info.ip.addr & ip_info.netmask.addr) | ~ip_info.netmask.addr; + ip_addr_t broadcast_addr = {}; + broadcast_addr.u_addr.ip4.addr = + (ip_info.ip.addr & ip_info.netmask.addr) | ~ip_info.netmask.addr; - // snprintf(this->broadcastIpAddress, INET_ADDRSTRLEN, IPSTR, - // IP2STR(&broadcast_addr.u_addr.ip4)); - // std::cout << "Broadcast address: " << this->broadcastIpAddress << "\n"; + snprintf(this->broadcastIpAddress, INET_ADDRSTRLEN, IPSTR, + IP2STR(&broadcast_addr.u_addr.ip4)); + std::cout << "Broadcast address: " << this->broadcastIpAddress << "\n"; } void ParticipantUDP::Receive() { @@ -152,12 +152,6 @@ bool ParticipantUDP::Publish(IMessage* msg) { sizeof(dest_addr)); if (err != 0) std::cout << "Publish error\n"; - // udp.beginPacket(this->broadcastIpAddress, this->remotePort); - // udp.write((unsigned char*)buffer, bufferSize); - // udp.endPacket(); - - // std::cout << "Publish to " << this->broadcastIpAddress << ":" - // << this->remotePort << "\n"; #endif return true; }; diff --git a/Participants/ParticipantUDP.cpp b/Participants/ParticipantUDP.cpp index d2f22aa..a406449 100644 --- a/Participants/ParticipantUDP.cpp +++ b/Participants/ParticipantUDP.cpp @@ -28,6 +28,7 @@ namespace RoboidControl { ParticipantUDP::ParticipantUDP(int port) { this->ipAddress = "0.0.0.0"; this->port = port; + this->remoteSite = nullptr; if (this->port == 0) this->isIsolated = true; }