Skip to content

Fix ntrip server on ethernet #499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Firmware/RTK_Surveyor/NtripClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
48 changes: 34 additions & 14 deletions Firmware/RTK_Surveyor/NtripServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
25 changes: 13 additions & 12 deletions Firmware/RTK_Surveyor/menuEthernet.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,18 +56,20 @@ 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;
return;
}

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();

Expand All @@ -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):
Expand Down