Greatly improved the wifi connection, ntp polling, and irc connection by adding retries and delays for syncing ntp which was causing tls errors when out of sync
This commit is contained in:
parent
9a5379eea2
commit
5df11770d6
20
src/main.ino
20
src/main.ino
@ -396,14 +396,20 @@ bool connectToIRC() {
|
||||
|
||||
void connectToWiFi() {
|
||||
WiFi.begin(ssid.c_str(), password.c_str());
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
int attempts = 0;
|
||||
while (WiFi.status() != WL_CONNECTED && attempts < 10) { // Try to connect for up to 10 seconds
|
||||
delay(500);
|
||||
displayCenteredText("CONNECTING TO " + ssid);
|
||||
attempts++;
|
||||
}
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
displayCenteredText("CONNECTED TO " + ssid);
|
||||
delay(1000);
|
||||
updateTimeFromNTP();
|
||||
} else {
|
||||
displayCenteredText("WIFI CONNECTION FAILED");
|
||||
Serial.println("Failed to connect to WiFi.");
|
||||
}
|
||||
}
|
||||
|
||||
void sendIRC(String command) {
|
||||
@ -798,11 +804,17 @@ uint16_t getColorFromPercentage(int rssi) {
|
||||
|
||||
void updateTimeFromNTP() {
|
||||
configTime(-5 * 3600, 0, "pool.ntp.org", "time.nist.gov");
|
||||
delay(2000); // Wait for NTP to sync
|
||||
|
||||
for (int i = 0; i < 10; ++i) { // Try up to 10 times
|
||||
delay(2000);
|
||||
struct tm timeinfo;
|
||||
if (getLocalTime(&timeinfo)) {
|
||||
Serial.println(&timeinfo, "Time synchronized: %A, %B %d %Y %H:%M:%S");
|
||||
return;
|
||||
} else {
|
||||
Serial.println("Failed to synchronize time");
|
||||
Serial.println("Failed to synchronize time, retrying...");
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("Failed to synchronize time after multiple attempts.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user