Skip to content

Commit fef3df3

Browse files
authored
Merge pull request #651 from LeeLeahy2/ns-bko-delay
NTRIP Server: Reset attempt count & timeout after long connection
2 parents 5ca2181 + 0fbdaf8 commit fef3df3

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ NtripServer.ino
138138
// 5 minutes. The NTRIP server stops retrying after 25 hours and 18 minutes
139139
static const int MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS = 28;
140140

141+
// NTRIP client connection delay before resetting the connect accempt counter
142+
static const int NTRIP_SERVER_CONNECTION_TIME = 5 * 60 * 1000;
143+
141144
// Define the NTRIP server states
142145
enum NTRIPServerState
143146
{
@@ -687,8 +690,7 @@ void ntripServerUpdate()
687690

688691
// We don't use a task because we use I2C hardware (and don't have a semphore).
689692
online.ntripServer = true;
690-
ntripServerConnectionAttempts = 0;
691-
ntripClientConnectionAttemptTimeout = 0;
693+
ntripServerStartTime = millis();
692694
ntripServerSetState(NTRIP_SERVER_CASTING);
693695
}
694696

@@ -746,6 +748,22 @@ void ntripServerUpdate()
746748
}
747749
else
748750
{
751+
// Handle other types of NTRIP connection failures to prevent
752+
// hammering the NTRIP caster with rapid connection attempts.
753+
// A fast reconnect is reasonable after a long NTRIP caster
754+
// connection. However increasing backoff delays should be
755+
// added when the NTRIP caster fails after a short connection
756+
// interval.
757+
if (((millis() - ntripServerStartTime) > NTRIP_SERVER_CONNECTION_TIME)
758+
&& (ntripServerConnectionAttempts || ntripServerConnectionAttemptTimeout))
759+
{
760+
// After a long connection period, reset the attempt counter
761+
ntripServerConnectionAttempts = 0;
762+
ntripServerConnectionAttemptTimeout = 0;
763+
if (settings.debugNtripServerState)
764+
systemPrintln("NTRIP Server resetting connection attempt counter and timeout");
765+
}
766+
749767
// All is well
750768
cyclePositionLEDs();
751769
}

0 commit comments

Comments
 (0)