Skip to content

Commit 683803a

Browse files
author
Lee Leahy
committed
NTRIP Client: Reset attempt count & timeout after long connection
1 parent 3e3d20d commit 683803a

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Firmware/RTK_Surveyor/NtripClient.ino

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ static const int SERVER_BUFFER_SIZE = CREDENTIALS_BUFFER_SIZE + 3;
145145

146146
static const int NTRIPCLIENT_MS_BETWEEN_GGA = 5000; // 5s between transmission of GGA messages, if enabled
147147

148+
// NTRIP client connection delay before resetting the connect accempt counter
149+
static const int NTRIP_CLIENT_CONNECTION_TIME = 5 * 60 * 1000;
150+
148151
// Define the NTRIP client states
149152
enum NTRIPClientState
150153
{
@@ -683,8 +686,6 @@ void ntripClientUpdate()
683686
// We don't use a task because we use I2C hardware (and don't have a semphore).
684687
online.ntripClient = true;
685688
ntripClientStartTime = millis();
686-
ntripClientConnectionAttempts = 0;
687-
ntripClientConnectionAttemptTimeout = 0;
688689
ntripClientSetState(NTRIP_CLIENT_CONNECTED);
689690
}
690691
else if (strstr(response, "401") != nullptr)
@@ -741,6 +742,22 @@ void ntripClientUpdate()
741742
}
742743
else
743744
{
745+
// Handle other types of NTRIP connection failures to prevent
746+
// hammering the NTRIP caster with rapid connection attempts.
747+
// A fast reconnect is reasonable after a long NTRIP caster
748+
// connection. However increasing backoff delays should be
749+
// added when the NTRIP caster fails after a short connection
750+
// interval.
751+
if (((millis() - ntripClientStartTime) > NTRIP_CLIENT_CONNECTION_TIME)
752+
&& (ntripClientConnectionAttempts || ntripClientConnectionAttemptTimeout))
753+
{
754+
// After a long connection period, reset the attempt counter
755+
ntripClientConnectionAttempts = 0;
756+
ntripClientConnectionAttemptTimeout = 0;
757+
if (settings.debugNtripClientState)
758+
systemPrintln("NTRIP Client resetting connection attempt counter and timeout");
759+
}
760+
744761
// Check for timeout receiving NTRIP data
745762
if (ntripClientReceiveDataAvailable() == 0)
746763
{

0 commit comments

Comments
 (0)