fix scan timeouts

This commit is contained in:
Summer
2025-11-23 14:00:15 -08:00
parent 34f89ffb33
commit 6c6d184e55
8 changed files with 55 additions and 24 deletions

View File

@@ -74,8 +74,8 @@ std::function<CommandResult()> CommandManager::createCommand(const CommandType t
case CommandType::RESTART_DEVICE:
return restartDeviceCommand;
case CommandType::SCAN_NETWORKS:
return [this]
{ return scanNetworksCommand(this->registry); };
return [this, json]
{ return scanNetworksCommand(this->registry, json); };
case CommandType::START_STREAMING:
return startStreamingCommand;
case CommandType::GET_WIFI_STATUS:

View File

@@ -1,7 +1,7 @@
#include "scan_commands.hpp"
#include "sdkconfig.h"
CommandResult scanNetworksCommand(std::shared_ptr<DependencyRegistry> registry)
CommandResult scanNetworksCommand(std::shared_ptr<DependencyRegistry> registry, const nlohmann::json &json)
{
#if !CONFIG_GENERAL_ENABLE_WIRELESS
return CommandResult::getErrorResult("Not supported by current firmware");
@@ -12,7 +12,14 @@ CommandResult scanNetworksCommand(std::shared_ptr<DependencyRegistry> registry)
return CommandResult::getErrorResult("Not supported by current firmware");
}
auto networks = wifiManager->ScanNetworks();
// Extract timeout from JSON if provided, default to 15000ms (15 seconds)
int timeout_ms = 15000;
if (json.contains("timeout_ms") && json["timeout_ms"].is_number_integer())
{
timeout_ms = json["timeout_ms"].get<int>();
}
auto networks = wifiManager->ScanNetworks(timeout_ms);
nlohmann::json result;
std::vector<nlohmann::json> networksJson;

View File

@@ -8,6 +8,6 @@
#include <string>
#include <nlohmann-json.hpp>
CommandResult scanNetworksCommand(std::shared_ptr<DependencyRegistry> registry);
CommandResult scanNetworksCommand(std::shared_ptr<DependencyRegistry> registry, const nlohmann::json &json);
#endif