Skip to content

Commit

Permalink
ESP/WiFi station: fix SNTP error checking
Browse files Browse the repository at this point in the history
Also increases default SNTP timeout from 5 seconds to 20 seconds
to prevent issues with unreachable IPv6 DNS servers aquired over
SLAAC.
  • Loading branch information
DavidB137 committed Nov 7, 2023
1 parent 87b2894 commit 957a0ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/espidf/spsp_wifi_station.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace SPSP::WiFi

// Timing
std::chrono::milliseconds initTimeout = std::chrono::seconds(20); //!< Timeout for connecting to AP
std::chrono::milliseconds sntpTimeout = std::chrono::seconds(5); //!< Timeout for initial time synchronization using SNTP server
std::chrono::milliseconds sntpTimeout = std::chrono::seconds(20); //!< Timeout for initial time synchronization using SNTP server
};

/**
Expand Down
12 changes: 6 additions & 6 deletions src/espidf/spsp_wifi_station.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ namespace SPSP::WiFi
sntpConfig.num_of_servers = 1;
sntpConfig.servers[0] = m_config.sntpServer.c_str();

esp_netif_sntp_init(&sntpConfig);
SPSP_ERROR_CHECK(esp_netif_sntp_init(&sntpConfig),
ConnectionError("SNTP init failed"));

// Block
if (esp_netif_sntp_sync_wait(
pdMS_TO_TICKS(m_config.sntpTimeout.count())
) != ESP_OK) {
throw ConnectionError("SNTP synchronization timeout");
}
SPSP_ERROR_CHECK(
esp_netif_sntp_sync_wait(pdMS_TO_TICKS(m_config.sntpTimeout.count())),
ConnectionError("SNTP synchronization timeout")
);
}

m_initialized = true;
Expand Down

0 comments on commit 957a0ed

Please sign in to comment.