diff --git a/Firmware/RTK_Surveyor/NtripClient.ino b/Firmware/RTK_Surveyor/NtripClient.ino index d25499f07..6a674bdd0 100644 --- a/Firmware/RTK_Surveyor/NtripClient.ino +++ b/Firmware/RTK_Surveyor/NtripClient.ino @@ -169,10 +169,9 @@ bool ntripClientConnectLimitReached() ntripClientStop(false); // Allocate new wifiClient // Retry the connection a few times - bool limitReached = false; - if (ntripClientConnectionAttempts++ >= MAX_NTRIP_CLIENT_CONNECTION_ATTEMPTS) - limitReached = true; + bool limitReached = (ntripClientConnectionAttempts >= MAX_NTRIP_CLIENT_CONNECTION_ATTEMPTS); + ntripClientConnectionAttempts++; ntripClientConnectionAttemptsTotal++; if (limitReached == false) @@ -434,6 +433,12 @@ void ntripClientUpdate() else { // Wait for ethernet to connect + static unsigned long lastDebug = millis(); + if (millis() > (lastDebug + 5000)) + { + lastDebug = millis(); + log_d("NTRIP Client: Ethernet not connected. Waiting to retry."); + } } } else diff --git a/Firmware/RTK_Surveyor/NtripServer.ino b/Firmware/RTK_Surveyor/NtripServer.ino index f929b4c60..094a75621 100644 --- a/Firmware/RTK_Surveyor/NtripServer.ino +++ b/Firmware/RTK_Surveyor/NtripServer.ino @@ -130,16 +130,24 @@ bool ntripServerConnectLimitReached() ntripServerStop(false); // Allocate new wifiClient // Retry the connection a few times - bool limitReached = false; - if (ntripServerConnectionAttempts++ >= MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS) - limitReached = true; + bool limitReached = (ntripServerConnectionAttempts >= MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS); + ntripServerConnectionAttempts++; ntripServerConnectionAttemptsTotal++; if (limitReached == false) { - ntripServerConnectionAttemptTimeout = - ntripServerConnectionAttempts * 5 * 60 * 1000L; // Wait 5, 10, 15, etc minutes between attempts + if (ntripServerConnectionAttempts == 1) + ntripServerConnectionAttemptTimeout = 15 * 1000L; // Wait 15s + else if (ntripServerConnectionAttempts == 2) + ntripServerConnectionAttemptTimeout = 30 * 1000L; // Wait 30s + else if (ntripServerConnectionAttempts == 3) + ntripServerConnectionAttemptTimeout = 1 * 60 * 1000L; // Wait 1 minute + else if (ntripServerConnectionAttempts == 4) + ntripServerConnectionAttemptTimeout = 2 * 60 * 1000L; // Wait 2 minutes + else + ntripServerConnectionAttemptTimeout = + (ntripServerConnectionAttempts - 4) * 5 * 60 * 1000L; // Wait 5, 10, 15, etc minutes between attempts reportHeapNow(); } @@ -419,8 +427,18 @@ void ntripServerUpdate() { if (online.ethernetStatus == ETH_CONNECTED) ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_CONNECTED); - else + else if (online.ethernetStatus == ETH_CAN_NOT_BEGIN) // Ethernet hardware failure or not available ntripServerSetState(NTRIP_SERVER_OFF); + else + { + // Wait for ethernet to connect + static unsigned long lastDebug = millis(); + if (millis() > (lastDebug + 5000)) + { + lastDebug = millis(); + log_d("NTRIP Server: Ethernet not connected. Waiting to retry."); + } + } } else { @@ -456,18 +474,20 @@ void ntripServerUpdate() // Attempt a connection to the NTRIP caster if (!ntripServerConnectCaster()) { - if (ntripServerConnectionAttemptTimeout / 1000 < 120) - systemPrintf("NTRIP Server failed to connect to caster. Trying again in %d seconds.\r\n", - ntripServerConnectionAttemptTimeout / 1000); - else - systemPrintf("NTRIP Server failed to connect to caster. Trying again in %d minutes.\r\n", - ntripServerConnectionAttemptTimeout / 1000 / 60); - // Assume service not available - if (ntripServerConnectLimitReached()) + if (ntripServerConnectLimitReached()) // Update ntripServerConnectionAttemptTimeout { systemPrintln("NTRIP Server failed to connect! Do you have your caster address and port correct?"); } + else + { + if (ntripServerConnectionAttemptTimeout / 1000 < 120) + systemPrintf("NTRIP Server failed to connect to caster. Trying again in %d seconds.\r\n", + ntripServerConnectionAttemptTimeout / 1000); + else + systemPrintf("NTRIP Server failed to connect to caster. Trying again in %d minutes.\r\n", + ntripServerConnectionAttemptTimeout / 1000 / 60); + } } else { diff --git a/Firmware/RTK_Surveyor/menuEthernet.ino b/Firmware/RTK_Surveyor/menuEthernet.ino index ed9ae3af6..208f5f09a 100644 --- a/Firmware/RTK_Surveyor/menuEthernet.ino +++ b/Firmware/RTK_Surveyor/menuEthernet.ino @@ -14,7 +14,7 @@ bool ethernetIsNeeded() ) return true; - // Does Base mode NTRIP Server need Ethernet? + // Does Rover mode NTRIP Client need Ethernet? if (HAS_ETHERNET && settings.enableNtripClient == true && (systemState >= STATE_ROVER_NOT_STARTED && systemState <= STATE_ROVER_RTK_FIX) //&& !settings.ntripClientUseWiFiNotEthernet //For future expansion @@ -56,7 +56,7 @@ void beginEthernet() Ethernet.begin(ethernetMACAddress, settings.ethernetIP, settings.ethernetDNS, settings.ethernetGateway, settings.ethernetSubnet); - if (Ethernet.hardwareStatus() == EthernetNoHardware) + if (Ethernet.hardwareStatus() == EthernetNoHardware) // Check that a W5n00 has been detected { log_d("Ethernet hardware not found"); online.ethernetStatus = ETH_CAN_NOT_BEGIN; @@ -64,10 +64,12 @@ void beginEthernet() } online.ethernetStatus = ETH_STARTED_CHECK_CABLE; + lastEthernetCheck = millis(); // Wait a full second before checking the cable + break; case (ETH_STARTED_CHECK_CABLE): - if (millis() - lastEthernetCheck > 1000) // Don't check for cable but once a second + if (millis() - lastEthernetCheck > 1000) // Check for cable every second { lastEthernetCheck = millis(); @@ -94,17 +96,16 @@ void beginEthernet() break; case (ETH_STARTED_START_DHCP): - Ethernet.begin(ethernetMACAddress); - - if (Ethernet.hardwareStatus() == EthernetNoHardware) + if (millis() - lastEthernetCheck > 1000) // Try DHCP every second { - log_d("Ethernet hardware not found"); - online.ethernetStatus = ETH_CAN_NOT_BEGIN; - return; - } + lastEthernetCheck = millis(); - log_d("Ethernet started with DHCP"); - online.ethernetStatus = ETH_CONNECTED; + if (Ethernet.begin(ethernetMACAddress, 20000)) // Restart Ethernet with DHCP. Use 20s timeout + { + log_d("Ethernet started with DHCP"); + online.ethernetStatus = ETH_CONNECTED; + } + } break; case (ETH_CONNECTED):