diff --git a/components/rpc/CommunicationRouter.cpp b/components/rpc/CommunicationRouter.cpp index cbdbeea..1dab9ec 100644 --- a/components/rpc/CommunicationRouter.cpp +++ b/components/rpc/CommunicationRouter.cpp @@ -95,7 +95,9 @@ void CommunicationRouter::update_leader() { this->m_leader = max; - mDNSDiscoveryService::set_connected_boards(connected_module_ids); + if (this->m_leader == m_module_id) { + mDNSDiscoveryService::set_connected_boards(connected_module_ids); + } this->m_last_leader_updated = std::chrono::system_clock::now(); } diff --git a/components/rpc/WifiManager.cpp b/components/rpc/WifiManager.cpp index e87c841..c4f3efb 100644 --- a/components/rpc/WifiManager.cpp +++ b/components/rpc/WifiManager.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" @@ -188,6 +189,7 @@ void WifiManager::wifi_event_handler(void *event_handler_arg, esp_event_base_t e } else if (WIFI_EVENT_STA_CONNECTED == event_id) { printf("Connected to wifi in station mode\n"); that->update_state(wifi_state::connected); + mDNSDiscoveryService::setup(); } else if (WIFI_EVENT_STA_DISCONNECTED == event_id) { printf("Station mode shutdown\n"); xSemaphoreTake(that->m_mutex, portMAX_DELAY); @@ -204,5 +206,8 @@ void WifiManager::wifi_event_handler(void *event_handler_arg, esp_event_base_t e printf("User connected to AP\n"); } else if (WIFI_EVENT_AP_STADISCONNECTED == event_id) { printf("User disconnected from AP\n"); + } else if (WIFI_EVENT_AP_START == event_id) { + mDNSDiscoveryService::setup(); + printf("AP started\n"); } } diff --git a/components/rpc/include/mDNSDiscoveryService.h b/components/rpc/include/mDNSDiscoveryService.h index 9f63e97..5695e80 100644 --- a/components/rpc/include/mDNSDiscoveryService.h +++ b/components/rpc/include/mDNSDiscoveryService.h @@ -13,7 +13,7 @@ public: ~mDNSDiscoveryService() = delete; static void setup(); - static void set_connected_boards(std::vector& boards); + static void set_connected_boards(const std::vector& boards); }; #endif //DISCOVERYSERVICE_H diff --git a/components/rpc/mDNSDiscoveryService.cpp b/components/rpc/mDNSDiscoveryService.cpp index 325bff2..c4247d2 100644 --- a/components/rpc/mDNSDiscoveryService.cpp +++ b/components/rpc/mDNSDiscoveryService.cpp @@ -32,7 +32,7 @@ void mDNSDiscoveryService::setup() { mdns_service_txt_set("_robotcontrol", "_tcp", service_txt_data, 3); } -void mDNSDiscoveryService::set_connected_boards(std::vector& boards) { +void mDNSDiscoveryService::set_connected_boards(const std::vector& boards) { std::stringstream ss; for (int i = 0; i < boards.size(); i++) { diff --git a/main/main.cpp b/main/main.cpp index 445ba8a..89ad2c6 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -16,6 +16,5 @@ extern "C" [[noreturn]] void app_main(void) { ESP_LOGI("MEM", "Free PSRAM: %d", heap_caps_get_free_size(MALLOC_CAP_SPIRAM)); ConfigManager::init_config(); - mDNSDiscoveryService::setup(); LoopManager::control_loop(); }